标签:meta his com rest run cluster 3.5 running code
a.创建deployment pod
kubectl run mynginx --image=docker.io/nginx:1.13 --replicas=4 --record
准备svc文件
apiVersion: v1 kind: Service metadata: name: nginxsvc spec: type: NodePort ports: - port: 80 nodePort: 30080 selector: run: mynginx #修改为需要关联pod的lable参数,‘kubectl describe deploy/mynginx‘查看
创建nginx-svc
kubectl create -f nginx-svc.yaml
[root@master01 ~]# kubectl get all -o wide NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE deploy/mynginx 4 4 4 4 14m NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE SELECTOR svc/kubernetes 10.254.0.1 <none> 443/TCP 1d <none> svc/nginxsvc 10.254.198.39 <nodes> 80:30080/TCP 9m run=mynginx NAME DESIRED CURRENT READY AGE CONTAINER(S) IMAGE(S) SELECTOR rs/mynginx-1186046214 4 4 4 14m mynginx docker.io/nginx:1.13 pod-template-hash=1186046214,run=mynginx NAME READY STATUS RESTARTS AGE IP NODE po/mynginx-1186046214-0q0cg 1/1 Running 0 4m 172.16.43.4 192.168.29.203 po/mynginx-1186046214-7g99g 1/1 Running 0 4m 172.16.22.3 192.168.29.202 po/mynginx-1186046214-bzjn2 1/1 Running 0 4m 172.16.43.3 192.168.29.203 po/mynginx-1186046214-g9dd1 1/1 Running 0 4m 172.16.22.4 192.168.29.202
b.升级mynginx,nginx:1.13 > nginx:1.15
kubectl set image deploy/mynginx mynginx=docker.io/nginx:1.15 #升级
[root@master01 ~]# kubectl get all -o wide NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE deploy/mynginx 4 4 4 4 35m NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE SELECTOR svc/kubernetes 10.254.0.1 <none> 443/TCP 1d <none> svc/nginxsvc 10.254.198.39 <nodes> 80:30080/TCP 30m run=mynginx NAME DESIRED CURRENT READY AGE CONTAINER(S) IMAGE(S) SELECTOR rs/mynginx-1186046214 0 0 0 35m mynginx docker.io/nginx:1.13 pod-template-hash=1186046214,run=mynginx rs/mynginx-1335861512 4 4 4 2m mynginx docker.io/nginx:1.15 pod-template-hash=1335861512,run=mynginx NAME READY STATUS RESTARTS AGE IP NODE po/mynginx-1335861512-7h3hc 1/1 Running 0 2m 172.16.43.5 192.168.29.203 po/mynginx-1335861512-cp080 1/1 Running 0 2m 172.16.22.2 192.168.29.202 po/mynginx-1335861512-k6kkb 1/1 Running 0 2m 172.16.43.4 192.168.29.203 po/mynginx-1335861512-xg6cr 1/1 Running 0 2m 172.16.43.3 192.168.29.203
c.回滚升级
kubectl rollout history deploy/mynginx #查看操作历史
[root@master01 ~]# kubectl rollout history deploy/mynginx deployments "mynginx" REVISION CHANGE-CAUSE 1 kubectl run mynginx --image=docker.io/nginx:1.13 --replicas=4 --record 2 kubectl set image deploy/mynginx mynginx=docker.io/nginx:1.15
kubectl rollout undo deploy/mynginx --to-revision=1 #回滚
[root@master01 ~]# kubectl rollout undo deploy/mynginx --to-revision=1 deployment "mynginx" rolled back [root@master01 ~]# kubectl get all -o wide NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE deploy/mynginx 4 4 4 4 39m NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE SELECTOR svc/kubernetes 10.254.0.1 <none> 443/TCP 1d <none> svc/nginxsvc 10.254.198.39 <nodes> 80:30080/TCP 35m run=mynginx NAME DESIRED CURRENT READY AGE CONTAINER(S) IMAGE(S) SELECTOR rs/mynginx-1186046214 4 4 4 39m mynginx docker.io/nginx:1.13 pod-template-hash=1186046214,run=mynginx rs/mynginx-1335861512 0 0 0 6m mynginx docker.io/nginx:1.15 pod-template-hash=1335861512,run=mynginx NAME READY STATUS RESTARTS AGE IP NODE po/mynginx-1186046214-4z1f5 1/1 Running 0 51s 172.16.43.3 192.168.29.203 po/mynginx-1186046214-f1qzz 1/1 Running 0 52s 172.16.22.4 192.168.29.202 po/mynginx-1186046214-ks19b 1/1 Running 0 52s 172.16.22.3 192.168.29.202 po/mynginx-1186046214-xqxj6 1/1 Running 0 50s 172.16.43.6 192.168.29.203
[root@master01 ~]# kubectl rollout history deploy/mynginx deployments "mynginx" REVISION CHANGE-CAUSE 2 kubectl set image deploy/mynginx mynginx=docker.io/nginx:1.15 3 kubectl run mynginx --image=docker.io/nginx:1.13 --replicas=4 --record
标签:meta his com rest run cluster 3.5 running code
原文地址:https://www.cnblogs.com/omgasw/p/10567376.html