minikube的使用手册 一起学习k8s

学习k8s
1.minikube的使用练习
启动minikube  start     
检查节点信息 kubectl get  nodes 查看集群信息 kubectl cluster-info 
 
Deployment是一个更高层次的API对象,它管理ReplicaSets和Pod,并提供声明式更新等功能
 

2.使用deployment创建一个pod应用

$ kubectl create deployment kubernetes-bootcamp --image=jocatalin/kubernetes-bootcamp:v1
                                          控制器名称                                  指定镜像
提示创建deployment.apps/kubernetes-bootcamp created
$ kubectl get deployments          查看deployments       
NAME                  READY   UP-TO-DATE   AVAILABLE   AGE
kubernetes-bootcamp   1/1     1            1           21s
$ kubectl get pods                     #查看pod
NAME                                   READY   STATUS    RESTARTS   AGE
kubernetes-bootcamp-7b7c64ccf7-52n67   1/1     Running   0          34s
$ kubectl get service                 #查看service 服务,这显然是集群的网络信息
NAME         TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)   AGE
kubernetes   ClusterIP   10.96.0.1    <none>        443/TCP   45m
$ kubectl exp
explain  expose   
$ kubectl expose deployment/kubernetes-bootcamp --type="NodePort" --port=8080   #给控制器指定端口
service/kubernetes-bootcamp exposed
$ kubectl get service
NAME                  TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)          AGE
kubernetes            ClusterIP   10.96.0.1        <none>        443/TCP          47m
kubernetes-bootcamp   NodePort    10.102.143.179   <none>        8080:32528/TCP   16s
$ curl http://127.0.0.1:32528     #通过本机访问
Hello Kubernetes bootcamp! | Running on: kubernetes-bootcamp-7b7c64ccf7-52n67 | v=1
Hello Kubernetes bootcamp! | Running on: kubernetes-bootcamp-7b7c64ccf7-52n67 | v=1
 
3.弹性伸缩pod
$ kubectl get  deplpyments.apps   #查看deplpyments
NAME                  READY   UP-TO-DATE   AVAILABLE   AGE
kubernetes-bootcamp   1/1     1            1           6m16s
$ kubectl scale deployment/kubernetes-bootcamp replica=5   #scale 弹性伸缩,指定pod数量
Error: required flag(s) "replicas" not set
$ kubectl scale deployment/kubernetes-bootcamp  --replicas=5
deployment.apps/kubernetes-bootcamp scaled
$ kubectl get deployments.apps           #通过deployment 管理副本数以及生命状态
NAME                  READY   UP-TO-DATE   AVAILABLE   AGE
kubernetes-bootcamp   5/5     5            5           7m46s
$ kubectl get pods                      #查看pod
NAME                                   READY   STATUS    RESTARTS   AGE
kubernetes-bootcamp-7b7c64ccf7-52n67   1/1     Running   0          8m1s
kubernetes-bootcamp-7b7c64ccf7-j7vps   1/1     Running   0          33s
kubernetes-bootcamp-7b7c64ccf7-l88jf   1/1     Running   0          33s
kubernetes-bootcamp-7b7c64ccf7-sft8h   1/1     Running   0          33s
kubernetes-bootcamp-7b7c64ccf7-vlfvb   1/1     Running   0          33s
$ kubectl get service               
NAME                  TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)          AGE
kubernetes            ClusterIP   10.96.0.1        <none>        443/TCP          51m
kubernetes-bootcamp   NodePort    10.102.143.179   <none>        8080:32528/TCP   4m39s
$ curl http://localhost:32528      #访问服务时,默认是轮训的方式
Hello Kubernetes bootcamp! | Running on: kubernetes-bootcamp-7b7c64ccf7-l88jf | v=1
Hello Kubernetes bootcamp! | Running on: kubernetes-bootcamp-7b7c64ccf7-sft8h | v=1
Hello Kubernetes bootcamp! | Running on: kubernetes-bootcamp-7b7c64ccf7-j7vps | v=1
Hello Kubernetes bootcamp! | Running on: kubernetes-bootcamp-7b7c64ccf7-vlfvb | v=1
Hello Kubernetes bootcamp! | Running on: kubernetes-bootcamp-7b7c64ccf7-j7vps | v=1
Hello Kubernetes bootcamp! | Running on: kubernetes-bootcamp-7b7c64ccf7-j7vps | v=1
 
4.升级
$ kubectl set image deployments/kubernetes-bootcamp kubernetes-bootcamp=jocatalin/kubernetes-bootcamp:v2    #给镜像升级
deployment.apps/kubernetes-bootcamp image updated
$ deployment.extensions/kubernetes-bootcamp image updated
Hello Kubernetes bootcamp! | Running on: kubernetes-bootcamp-769746fd4-pqp97 | v=2  ##此时kubernetes-bootcamp用的镜像是V2
$ kubectl get pod
NAME                                  READY   STATUS    RESTARTS   AGE
kubernetes-bootcamp-769746fd4-65lfz   1/1     Running   0          2m46s
kubernetes-bootcamp-769746fd4-pqp97   1/1     Running   0          2m52s
kubernetes-bootcamp-769746fd4-vlhg8   1/1     Running   0          2m44s
kubernetes-bootcamp-769746fd4-w9c8b   1/1     Running   0          2m52s
kubernetes-bootcamp-769746fd4-wlncc   1/1     Running   0          2m52s
Hello Kubernetes bootcamp! | Running on: kubernetes-bootcamp-769746fd4-pqp97 | v=2
Hello Kubernetes bootcamp! | Running on: kubernetes-bootcamp-769746fd4-w9c8b | v=2
Hello Kubernetes bootcamp! | Running on: kubernetes-bootcamp-769746fd4-pqp97 | v=2
Hello Kubernetes bootcamp! | Running on: kubernetes-bootcamp-769746fd4-wlncc | v=2
 
5.回滚
$ kubectl rollout undo deployments/kubernetes-bootcamp  #回滚
deployment.apps/kubernetes-bootcamp rolled back
$ kubectl get pod
NAME                                   READY   STATUS              RESTARTS   AGE
kubernetes-bootcamp-769746fd4-65lfz    1/1     Terminating         0          3m34s
kubernetes-bootcamp-769746fd4-pqp97    1/1     Running             0          3m40s
kubernetes-bootcamp-769746fd4-vlhg8    1/1     Terminating         0          3m32s
kubernetes-bootcamp-769746fd4-w9c8b    1/1     Terminating         0          3m40s
kubernetes-bootcamp-769746fd4-wlncc    1/1     Terminating         0          3m40s
kubernetes-bootcamp-7b7c64ccf7-29w6j   0/1     ContainerCreating   0          1s
kubernetes-bootcamp-7b7c64ccf7-f9nbm   0/1     ContainerCreating   0          1s
kubernetes-bootcamp-7b7c64ccf7-lqp7p   1/1     Running             0          5s
kubernetes-bootcamp-7b7c64ccf7-nqpfj   1/1     Running             0          5s
kubernetes-bootcamp-7b7c64ccf7-v2sl4   1/1     Running             0          6s
$ kubectl get deployments.apps
NAME                  READY   UP-TO-DATE   AVAILABLE   AGE
kubernetes-bootcamp   5/5     5            5           16m
$ kubectl get pod
NAME                                   READY   STATUS        RESTARTS   AGE
kubernetes-bootcamp-769746fd4-65lfz    1/1     Terminating   0          3m50s
kubernetes-bootcamp-769746fd4-pqp97    1/1     Terminating   0          3m56s
kubernetes-bootcamp-769746fd4-vlhg8    1/1     Terminating   0          3m48s
kubernetes-bootcamp-769746fd4-w9c8b    1/1     Terminating   0          3m56s
kubernetes-bootcamp-769746fd4-wlncc    1/1     Terminating   0          3m56s
kubernetes-bootcamp-7b7c64ccf7-29w6j   1/1     Running       0          17s
kubernetes-bootcamp-7b7c64ccf7-f9nbm   1/1     Running       0          17s
kubernetes-bootcamp-7b7c64ccf7-lqp7p   1/1     Running       0          21s
kubernetes-bootcamp-7b7c64ccf7-nqpfj   1/1     Running       0          21s
kubernetes-bootcamp-7b7c64ccf7-v2sl4   1/1     Running       0          22s
Hello Kubernetes bootcamp! | Running on: kubernetes-bootcamp-7b7c64ccf7-v2sl4 | v=1
Hello Kubernetes bootcamp! | Running on: kubernetes-bootcamp-7b7c64ccf7-v2sl4 | v=1
 
6.删除pod
Kubectl delete pod   加服务名称
删除pod 之前先删除deplpyments 不然是删不掉pod的
Kubectl delete deppyments  kubernetes-bootcamp

minikube的使用手册 一起学习k8s

上一篇:浅谈5款常用的大数据分析工具


下一篇:用verilog实现PWM控制呼吸灯。呼吸周期2秒:1秒逐渐变 亮,1秒逐渐变暗。系统时钟24MHz,pwm周期1ms,精度1us。