修改镜像版本
kubectl edit deploy
image 选择升级为高版本改完之后运行这个命令看 deploy pod 的变化
[root@kubeadm-master1 ~]# kubectl get deploy
NAME READY UP-TO-DATE AVAILABLE AGE
nginx-deploy 3/3 1 3 20m
nginx-deployment 1/1 1 1 56d
tomcat-deployment 1/1 1 1 56d
[root@kubeadm-master1 ~]# kubectl get deploy
NAME READY UP-TO-DATE AVAILABLE AGE
nginx-deploy 3/3 1 3 20m
nginx-deployment 1/1 1 1 56d
tomcat-deployment 1/1 1 1 56d
[root@kubeadm-master1 ~]# kubectl get deploy
NAME READY UP-TO-DATE AVAILABLE AGE
nginx-deploy 3/3 2 3 20m
nginx-deployment 1/1 1 1 56d
tomcat-deployment 1/1 1 1 56d
[root@kubeadm-master1 ~]# kubectl get deploy
NAME READY UP-TO-DATE AVAILABLE AGE
nginx-deploy 3/3 2 3 20m
nginx-deployment 1/1 1 1 56d
tomcat-deployment 1/1 1 1 56d
[root@kubeadm-master1 ~]# kubectl get deploy
NAME READY UP-TO-DATE AVAILABLE AGE
nginx-deploy 3/3 2 3 20m
nginx-deployment 1/1 1 1 56d
tomcat-deployment 1/1 1 1 56d
[root@kubeadm-master1 ~]# kubectl get deploy
NAME READY UP-TO-DATE AVAILABLE AGE
nginx-deploy 3/3 2 3 20m
nginx-deployment 1/1 1 1 56d
tomcat-deployment 1/1 1 1 56d
[root@kubeadm-master1 ~]# kubectl get deploy
NAME READY UP-TO-DATE AVAILABLE AGE
nginx-deploy 3/3 2 3 20m
nginx-deployment 1/1 1 1 56d
tomcat-deployment 1/1 1 1 56d
[root@kubeadm-master1 ~]# kubectl get deploy
NAME READY UP-TO-DATE AVAILABLE AGE
nginx-deploy 3/3 2 3 20m
nginx-deployment 1/1 1 1 56d
tomcat-deployment 1/1 1 1 56d
[root@kubeadm-master1 ~]# kubectl get deploy
NAME READY UP-TO-DATE AVAILABLE AGE
nginx-deploy 3/3 2 3 20m
nginx-deployment 1/1 1 1 56d
tomcat-deployment 1/1 1 1 56d
[root@kubeadm-master1 ~]# kubectl get deploy --show-labels
NAME READY UP-TO-DATE AVAILABLE AGE LABELS
nginx-deploy 3/3 3 3 20m app=nginx-deploy
nginx-deployment 1/1 1 1 56d app=nginx
tomcat-deployment 1/1 1 1 56d app=tomcat查看滚动更新的状态
[root@kubeadm-master1 ~]# kubectl rollout status deploy nginx-deploy
deployment "nginx-deploy" successfully rolled out修改nginx的镜像为1.7.9[root@kubeadm-master1 ~]# kubectl set image deployment/nginx-deploy nginx=nginx:1.7.9
deployment.apps/nginx-deploy image updated
[root@kubeadm-master1 ~]# kubectl get deploy
NAME READY UP-TO-DATE AVAILABLE AGE
nginx-deploy 3/3 3 3 24m
nginx-deployment 1/1 1 1 56d
tomcat-deployment 1/1 1 1 56d
[root@kubeadm-master1 ~]# kubectl get deploy
NAME READY UP-TO-DATE AVAILABLE AGE
nginx-deploy 3/3 3 3 24m
nginx-deployment 1/1 1 1 56d
tomcat-deployment 1/1 1 1 56d
[root@kubeadm-master1 ~]# kubectl rollout status deploy nginx-deploy
deployment "nginx-deploy" successfully rolled out
[root@kubeadm-master1 ~]# kubectl describe deploy nginx-deploy
Name: nginx-deploy
Namespace: default
CreationTimestamp: Fri, 16 Feb 2024 10:25:18 +0800
Labels: app=nginx-deploy
Annotations: deployment.kubernetes.io/revision: 3
Selector: app=nginx-deploy
Replicas: 3 desired | 3 updated | 3 total | 3 available | 0 unavailable
StrategyType: RollingUpdate
MinReadySeconds: 0
RollingUpdateStrategy: 25% max unavailable, 25% max surge
Pod Template:Labels: app=nginx-deployContainers:nginx:Image: nginx:1.7.9Port: <none>Host Port: <none>Environment: <none>Mounts: <none>Volumes: <none>
Conditions:Type Status Reason---- ------ ------Available True MinimumReplicasAvailableProgressing True NewReplicaSetAvailable
OldReplicaSets: <none>
NewReplicaSet: nginx-deploy-845964f5bf (3/3 replicas created)
Events:Type Reason Age From Message---- ------ ---- ---- -------Normal ScalingReplicaSet 8m58s deployment-controller Scaled up replica set nginx-deploy-845964f5bf to 3Normal ScalingReplicaSet 5m6s deployment-controller Scaled up replica set nginx-deploy-968b78ccf to 1Normal ScalingReplicaSet 4m56s deployment-controller Scaled down replica set nginx-deploy-845964f5bf to 2Normal ScalingReplicaSet 4m56s deployment-controller Scaled up replica set nginx-deploy-968b78ccf to 2Normal ScalingReplicaSet 4m47s deployment-controller Scaled up replica set nginx-deploy-968b78ccf to 3Normal ScalingReplicaSet 4m47s deployment-controller Scaled down replica set nginx-deploy-845964f5bf to 1Normal ScalingReplicaSet 4m45s deployment-controller Scaled down replica set nginx-deploy-845964f5bf to 0Normal ScalingReplicaSet 39s (x2 over 25m) deployment-controller Scaled up replica set nginx-deploy-845964f5bf to 1Normal ScalingReplicaSet 38s deployment-controller Scaled down replica set nginx-deploy-968b78ccf to 2Normal ScalingReplicaSet 36s (x4 over 38s) deployment-controller (combined from similar events): Scaled down replica set nginx-deploy-968b78ccf to 0查看rs1 和 rs2 的更新状态,上一个变成0 ,新的变成3
[root@kubeadm-master1 ~]# kubectl get rs --show-labels
NAME DESIRED CURRENT READY AGE LABELS
nginx-deploy-845964f5bf 3 3 3 27m app=nginx-deploy,pod-template-hash=845964f5bf
nginx-deploy-968b78ccf 0 0 0 7m58s app=nginx-deploy,pod-template-hash=968b78ccf
Deployment:回滚
[root@kubeadm-master1 ~]# kubectl set image deployment/nginx-deploy nginx=nginx:1.9.1
deployment.apps/nginx-deploy image updated
[root@kubeadm-master1 ~]# kubectl rollout status deployments nginx-deploy
deployment "nginx-deploy" successfully rolled out
[root@kubeadm-master1 ~]# kubectl get pod
NAME READY STATUS RESTARTS AGE
client 1/1 Running 0 50d
my-pod 1/1 Running 0 9d
my-pod1 0/1 Completed 6 19h
net-test1 1/1 Running 138 57d
net-test2 1/1 Running 14 57d
nginx-deploy-968b78ccf-8lb9c 1/1 Running 0 16s
nginx-deploy-968b78ccf-d8mhr 1/1 Running 0 17s
nginx-deploy-968b78ccf-nqq4s 1/1 Running 0 19s
nginx-deployment-67dfd6c8f9-5s6nz 1/1 Running 1 56d
tomcat-deployment-6c44f58b47-4pz6d 1/1 Running 1 56d
[root@kubeadm-master1 ~]# kubectl describe deploy nginx-deploy
Name: nginx-deploy
Namespace: default
CreationTimestamp: Fri, 16 Feb 2024 10:25:18 +0800
Labels: app=nginx-deploy
Annotations: deployment.kubernetes.io/revision: 4
Selector: app=nginx-deploy
Replicas: 3 desired | 3 updated | 3 total | 3 available | 0 unavailable
StrategyType: RollingUpdate
MinReadySeconds: 0
RollingUpdateStrategy: 25% max unavailable, 25% max surge
Pod Template:Labels: app=nginx-deployContainers:nginx:Image: nginx:1.9.1Port: <none>Host Port: <none>Environment: <none>Mounts: <none>Volumes: <none>
Conditions:Type Status Reason---- ------ ------Available True MinimumReplicasAvailableProgressing True NewReplicaSetAvailable
OldReplicaSets: <none>
NewReplicaSet: nginx-deploy-968b78ccf (3/3 replicas created)
Events:Type Reason Age From Message---- ------ ---- ---- -------Normal ScalingReplicaSet 25m deployment-controller Scaled up replica set nginx-deploy-845964f5bf to 3Normal ScalingReplicaSet 17m (x2 over 41m) deployment-controller Scaled up replica set nginx-deploy-845964f5bf to 1Normal ScalingReplicaSet 17m deployment-controller Scaled down replica set nginx-deploy-968b78ccf to 2Normal ScalingReplicaSet 17m (x4 over 17m) deployment-controller (combined from similar events): Scaled down replica set nginx-deploy-968b78ccf to 0Normal ScalingReplicaSet 48s (x2 over 21m) deployment-controller Scaled up replica set nginx-deploy-968b78ccf to 1Normal ScalingReplicaSet 46s (x2 over 21m) deployment-controller Scaled up replica set nginx-deploy-968b78ccf to 2Normal ScalingReplicaSet 46s (x2 over 21m) deployment-controller Scaled down replica set nginx-deploy-845964f5bf to 2Normal ScalingReplicaSet 45s (x2 over 21m) deployment-controller Scaled down replica set nginx-deploy-845964f5bf to 1Normal ScalingReplicaSet 45s (x2 over 21m) deployment-controller Scaled up replica set nginx-deploy-968b78ccf to 3Normal ScalingReplicaSet 44s (x2 over 21m) deployment-controller Scaled down replica set nginx-deploy-845964f5bf to 0查看历史版本
[root@kubeadm-master1 ~]# kubectl rollout history deployment/nginx-deploy
deployment.apps/nginx-deploy
REVISION CHANGE-CAUSE
3 <none>
4 <none>如果修改时候 kubectl set image deployment/nginx-deploy nginx=nginx:1.7.9 --record
上面的none 就会记录详细的信息查看历史版本详细信息
kubectl rollout history deployment/nginx-deploy --revision=3确认回退版本之后
kubectl rollout undo deployment/nginx-deploy --to-revision=2查看回退版本的状态
kubectl get deploy
kubectl describe deploy
回退版本实际操作
[root@kubeadm-master1 ~]# kubectl describe deploy nginx-deploy
Name: nginx-deploy
Namespace: default
CreationTimestamp: Fri, 16 Feb 2024 10:25:18 +0800
Labels: app=nginx-deploy
Annotations: deployment.kubernetes.io/revision: 4
Selector: app=nginx-deploy
Replicas: 3 desired | 3 updated | 3 total | 3 available | 0 unavailable
StrategyType: RollingUpdate
MinReadySeconds: 0
RollingUpdateStrategy: 25% max unavailable, 25% max surge
Pod Template:Labels: app=nginx-deployContainers:nginx:Image: nginx:1.9.1Port: <none>Host Port: <none>Environment: <none>Mounts: <none>Volumes: <none>
Conditions:Type Status Reason---- ------ ------Available True MinimumReplicasAvailableProgressing True NewReplicaSetAvailable
OldReplicaSets: <none>
NewReplicaSet: nginx-deploy-968b78ccf (3/3 replicas created)
Events:Type Reason Age From Message---- ------ ---- ---- -------Normal ScalingReplicaSet 37m deployment-controller Scaled up replica set nginx-deploy-845964f5bf to 3Normal ScalingReplicaSet 29m (x2 over 53m) deployment-controller Scaled up replica set nginx-deploy-845964f5bf to 1Normal ScalingReplicaSet 29m deployment-controller Scaled down replica set nginx-deploy-968b78ccf to 2Normal ScalingReplicaSet 29m (x4 over 29m) deployment-controller (combined from similar events): Scaled down replica set nginx-deploy-968b78ccf to 0Normal ScalingReplicaSet 12m (x2 over 34m) deployment-controller Scaled up replica set nginx-deploy-968b78ccf to 1Normal ScalingReplicaSet 12m (x2 over 33m) deployment-controller Scaled up replica set nginx-deploy-968b78ccf to 2Normal ScalingReplicaSet 12m (x2 over 33m) deployment-controller Scaled down replica set nginx-deploy-845964f5bf to 2Normal ScalingReplicaSet 12m (x2 over 33m) deployment-controller Scaled down replica set nginx-deploy-845964f5bf to 1Normal ScalingReplicaSet 12m (x2 over 33m) deployment-controller Scaled up replica set nginx-deploy-968b78ccf to 3Normal ScalingReplicaSet 12m (x2 over 33m) deployment-controller Scaled down replica set nginx-deploy-845964f5bf to 0
[root@kubeadm-master1 ~]# kubectl rollout history deployment/nginx-deploy --revision=4
deployment.apps/nginx-deploy with revision #4
Pod Template:Labels: app=nginx-deploypod-template-hash=968b78ccfContainers:nginx:Image: nginx:1.9.1Port: <none>Host Port: <none>Environment: <none>Mounts: <none>Volumes: <none>[root@kubeadm-master1 ~]# kubectl rollout history deployment/nginx-deploy --revision=3
deployment.apps/nginx-deploy with revision #3
Pod Template:Labels: app=nginx-deploypod-template-hash=845964f5bfContainers:nginx:Image: nginx:1.7.9Port: <none>Host Port: <none>Environment: <none>Mounts: <none>Volumes: <none>[root@kubeadm-master1 ~]# kubectl rollout undo deployment/nginx-deploy --to-revision=3
deployment.apps/nginx-deploy rolled back
[root@kubeadm-master1 ~]# kubectl describe deploy nginx-deploy
Name: nginx-deploy
Namespace: default
CreationTimestamp: Fri, 16 Feb 2024 10:25:18 +0800
Labels: app=nginx-deploy
Annotations: deployment.kubernetes.io/revision: 5
Selector: app=nginx-deploy
Replicas: 3 desired | 3 updated | 3 total | 3 available | 0 unavailable
StrategyType: RollingUpdate
MinReadySeconds: 0
RollingUpdateStrategy: 25% max unavailable, 25% max surge
Pod Template:Labels: app=nginx-deployContainers:nginx:Image: nginx:1.7.9Port: <none>Host Port: <none>Environment: <none>Mounts: <none>Volumes: <none>
Conditions:Type Status Reason---- ------ ------Available True MinimumReplicasAvailableProgressing True NewReplicaSetAvailable
OldReplicaSets: <none>
NewReplicaSet: nginx-deploy-845964f5bf (3/3 replicas created)
Events:Type Reason Age From Message---- ------ ---- ---- -------Normal ScalingReplicaSet 30m (x4 over 30m) deployment-controller (combined from similar events): Scaled down replica set nginx-deploy-968b78ccf to 0Normal ScalingReplicaSet 13m (x2 over 34m) deployment-controller Scaled up replica set nginx-deploy-968b78ccf to 1Normal ScalingReplicaSet 13m (x2 over 34m) deployment-controller Scaled down replica set nginx-deploy-845964f5bf to 2Normal ScalingReplicaSet 13m (x2 over 34m) deployment-controller Scaled up replica set nginx-deploy-968b78ccf to 2Normal ScalingReplicaSet 13m (x2 over 34m) deployment-controller Scaled up replica set nginx-deploy-968b78ccf to 3Normal ScalingReplicaSet 13m (x2 over 34m) deployment-controller Scaled down replica set nginx-deploy-845964f5bf to 1Normal ScalingReplicaSet 13m (x2 over 34m) deployment-controller Scaled down replica set nginx-deploy-845964f5bf to 0Normal ScalingReplicaSet 10s (x3 over 54m) deployment-controller Scaled up replica set nginx-deploy-845964f5bf to 1Normal ScalingReplicaSet 9s (x2 over 30m) deployment-controller Scaled down replica set nginx-deploy-968b78ccf to 2Normal ScalingReplicaSet 9s deployment-controller Scaled up replica set nginx-deploy-845964f5bf to 2Normal ScalingReplicaSet 8s (x2 over 38m) deployment-controller Scaled up replica set nginx-deploy-845964f5bf to 3Normal ScalingReplicaSet 8s deployment-controller Scaled down replica set nginx-deploy-968b78ccf to 1Normal ScalingReplicaSet 6s deployment-controller Scaled down replica set nginx-deploy-968b78ccf to 0