kubernetes云平台管理实战:如何创建deployment更好(九)

一、文件创建带--record 

1、文件

[root@k8s-master ~]# cat nginx_deploy.yml apiVersion: extensions/v1beta1kind: Deploymentmetadata: name: nginx-deploymentspec: replicas: 3 template: metadata: labels: app: nginx spec: containers: - name: nginx image: 10.0.128.0:5000/nginx:1.13 ports: - containerPort: 80

2、启动

[root@k8s-master ~]# kubectl create -f nginx_deploy.yml --record deployment "nginx-deployment" created[root@k8s-master ~]# kubectl get all -o wideNAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGEdeploy/nginx-deployment 3 3 3 3 7sNAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE SELECTORsvc/kubernetes 10.254.0.1 <none> 443/TCP 1d <none>svc/nginx 10.254.145.15 <nodes> 80:30027/TCP 22h app=mywebNAME DESIRED CURRENT READY AGE CONTAINER(S) IMAGE(S) SELECTORrs/nginx-deployment-2950479891 3 3 3 7s nginx 10.0.128.0:5000/nginx:1.13 app=nginx,pod-template-hash=2950479891NAME READY STATUS RESTARTS AGE IP NODEpo/nginx-deployment-2950479891-3dwct 1/1 Running 0 7s 172.16.50.2 k8s-node1po/nginx-deployment-2950479891-6wvsw 1/1 Running 0 7s 172.16.19.2 k8s-node2po/nginx-deployment-2950479891-95133 1/1 Running 0 7s 172.16.50.3 k8s-node1

3、更新镜像

[root@k8s-master ~]# vim nginx_deploy.yml 版本手动修改为1.15[root@k8s-master ~]# kubectl apply -f nginx_deploy.yml deployment "nginx-deployment" configured[root@k8s-master ~]# kubectl get all -o wideNAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGEdeploy/nginx-deployment 3 3 3 3 1mNAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE SELECTORsvc/kubernetes 10.254.0.1 <none> 443/TCP 1d <none>svc/nginx 10.254.145.15 <nodes> 80:30027/TCP 22h app=mywebNAME DESIRED CURRENT READY AGE CONTAINER(S) IMAGE(S) SELECTORrs/nginx-deployment-2950479891 0 0 0 1m nginx 10.0.128.0:5000/nginx:1.13 app=nginx,pod-template-hash=2950479891rs/nginx-deployment-3113009173 3 3 3 7s nginx 10.0.128.0:5000/nginx:1.15 app=nginx,pod-template-hash=3113009173NAME READY STATUS RESTARTS AGE IP NODEpo/nginx-deployment-3113009173-4xrq4 1/1 Running 0 7s 172.16.19.3 k8s-node2po/nginx-deployment-3113009173-5crv5 1/1 Running 0 5s 172.16.19.2 k8s-node2po/nginx-deployment-3113009173-vckhg 1/1 Running 0 7s 172.16.50.2 k8s-node1

4、显示历史版本

[root@k8s-master ~]# kubectl rollout history deployment nginx-deployment deployments "nginx-deployment"REVISION CHANGE-CAUSE1 kubectl create -f nginx_deploy.yml --record2 kubectl apply -f nginx_deploy.yml

二、命令行创建不带--record 

1、启动

[root@k8s-master ~]# kubectl delete deployment nginxdeployment "nginx" deleted[root@k8s-master ~]# kubectl get all -o wideNAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE SELECTORkubernetes 10.254.0.1 <none> 443/TCP 1d <none>nginx 10.254.145.15 <nodes> 80:30027/TCP 22h app=myweb
[root@k8s-master ~]# kubectl run nginx --image=10.0.128.0:5000/nginx:1.13 --replicas=5deployment "nginx" created
[root@k8s-master ~]# kubectl get all -o wideNAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGEdeploy/nginx 5 5 5 5 7sNAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE SELECTORsvc/kubernetes 10.254.0.1 <none> 443/TCP 1d <none>svc/nginx 10.254.145.15 <nodes> 80:30027/TCP 22h app=mywebNAME DESIRED CURRENT READY AGE CONTAINER(S) IMAGE(S) SELECTORrs/nginx-835034785 5 5 5 7s nginx 10.0.128.0:5000/nginx:1.13 pod-template-hash=835034785,run=nginxNAME READY STATUS RESTARTS AGE IP NODEpo/nginx-835034785-8f4m0 1/1 Running 0 7s 172.16.50.2 k8s-node1po/nginx-835034785-8j9w2 1/1 Running 0 7s 172.16.19.3 k8s-node2po/nginx-835034785-c7nx3 1/1 Running 0 7s 172.16.19.4 k8s-node2po/nginx-835034785-p2vn0 1/1 Running 0 7s 172.16.19.2 k8s-node2po/nginx-835034785-z42qh 1/1 Running 0 7s 172.16.50.3 k8s-node1

2、更新镜像

[root@k8s-master ~]# kubectl set image deploy nginx nginx=10.0.128.0:5000/nginx:1.15deployment "nginx" image updated[root@k8s-master ~]# kubectl get all -o wideNAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGEdeploy/nginx 5 5 5 5 34sNAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE SELECTORsvc/kubernetes 10.254.0.1 <none> 443/TCP 1d <none>svc/nginx 10.254.145.15 <nodes> 80:30027/TCP 22h app=mywebNAME DESIRED CURRENT READY AGE CONTAINER(S) IMAGE(S) SELECTORrs/nginx-835034785 0 0 0 34s nginx 10.0.128.0:5000/nginx:1.13 pod-template-hash=835034785,run=nginxrs/nginx-984850083 5 5 5 10s nginx 10.0.128.0:5000/nginx:1.15 pod-template-hash=984850083,run=nginxNAME READY STATUS RESTARTS AGE IP NODEpo/nginx-984850083-4pd4w 1/1 Running 0 10s 172.16.19.2 k8s-node2po/nginx-984850083-k979d 1/1 Running 0 10s 172.16.50.4 k8s-node1po/nginx-984850083-nljkt 1/1 Running 0 4s 172.16.19.4 k8s-node2po/nginx-984850083-r3hqh 1/1 Running 0 6s 172.16.19.3 k8s-node2po/nginx-984850083-x6x47 1/1 Running 0 7s 172.16.50.5 k8s-node1

3、查看历史版本

[root@k8s-master ~]# kubectl rollout history deployment nginxdeployments "nginx"REVISION CHANGE-CAUSE1 <none>2 <none>

三、命令创建不带--record

1、启动

[root@k8s-master ~]# kubectl run nginx --image=10.0.128.0:5000/nginx:1.13 --replicas=5 --recorddeployment "nginx" created[root@k8s-master ~]# kubectl get all -o wideNAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGEdeploy/nginx 5 5 5 0 3s NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE SELECTORsvc/kubernetes 10.254.0.1 <none> 443/TCP 1d <none>svc/nginx 10.254.145.15 <nodes> 80:30027/TCP 22h app=myweb NAME DESIRED CURRENT READY AGE CONTAINER(S) IMAGE(S) SELECTORrs/nginx-835034785 5 5 0 3s nginx 10.0.128.0:5000/nginx:1.13 pod-template-hash=835034785,run=nginx NAME READY STATUS RESTARTS AGE IP NODEpo/nginx-835034785-b9mnp 0/1 ContainerCreating 0 3s <none> k8s-node2po/nginx-835034785-gp2m5 0/1 ContainerCreating 0 3s <none> k8s-node1po/nginx-835034785-hhz0b 0/1 ContainerCreating 0 3s <none> k8s-node1po/nginx-835034785-mvv4p 0/1 ContainerCreating 0 3s <none> k8s-node2po/nginx-835034785-x6mjp 0/1 ContainerCreating 0 3s <none> k8s-node1

2、升级镜像版本

[root@k8s-master ~]# kubectl set image deploy nginx nginx=10.0.128.0:5000/nginx:1.15deployment "nginx" image updated[root@k8s-master ~]# kubectl get all -o wideNAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGEdeploy/nginx 5 5 5 5 32s NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE SELECTORsvc/kubernetes 10.254.0.1 <none> 443/TCP 1d <none>svc/nginx 10.254.145.15 <nodes> 80:30027/TCP 22h app=myweb NAME DESIRED CURRENT READY AGE CONTAINER(S) IMAGE(S) SELECTORrs/nginx-835034785 0 0 0 32s nginx 10.0.128.0:5000/nginx:1.13 pod-template-hash=835034785,run=nginxrs/nginx-984850083 5 5 5 14s nginx 10.0.128.0:5000/nginx:1.15 pod-template-hash=984850083,run=nginx NAME READY STATUS RESTARTS AGE IP NODEpo/nginx-984850083-4xt4s 1/1 Running 0 5s 172.16.50.4 k8s-node1po/nginx-984850083-gk5fq 1/1 Running 0 7s 172.16.50.2 k8s-node1po/nginx-984850083-mhp7h 1/1 Running 0 13s 172.16.50.3 k8s-node1po/nginx-984850083-vs93g 1/1 Running 0 14s 172.16.19.4 k8s-node2po/nginx-984850083-z5px0 1/1 Running 0 11s 172.16.19.5 k8s-node2

3、查看历史版本

[root@k8s-master ~]# kubectl rollout history deployment nginxdeployments "nginx"REVISION CHANGE-CAUSE1 kubectl run nginx --image=10.0.128.0:5000/nginx:1.13 --replicas=5 --record2 kubectl set image deploy nginx nginx=10.0.128.0:5000/nginx:1.15

四、小结

1、创建资源方式总结

方式一:

kubectl create -f nginx_deploy.yml

方式二:

kubectl run nginx --image=10.0.128.0:5000/nginx:1.13 --replicas=5 --record

通过以上三个查看历史版本的详细程度来看方式三为最优,建议生产使用,具体命令如下

kubectl run nginx --image=10.0.128.0:5000/nginx:1.13 --replicas=5 --record

  

相关文章