更新Deployment资源时,pod状态为Pending,使用delete命令是删不掉Pending的pod的,因为Deployment会无限创建,这时候需要用到Deployment的回滚功能
如下我更改了Deployment/Jenkins,但新创建的pod因为资源不足无法创建而处于pending状态:
$ kd get pod -n cicd
NAME READY STATUS RESTARTS AGE
jenkins-5b688ddcc7-2zlwz 1/1 Running 0 5d23h
jenkins-8588ccc5c5-v4b2x 0/1 Pending 0 28s
如果删除pod,deployment就会重新创建pod,依然是pending状态
$ kubectl delete pod jenkins-8588ccc5c5-v4b2x -n cice
pod "jenkins-8588ccc5c5-v4b2x" deleted
$ kd get pod -n cicd
NAME READY STATUS RESTARTS AGE
jenkins-5b688ddcc7-2zlwz 1/1 Running 0 5d23h
jenkins-8588ccc5c5-46qt2 0/1 Pending 0 5s
解决方法:
查看Deployment更新的历史版本,回滚到上一版本
# 查看历史版本
$ kubectl rollout history deployment jenkins -n cicd
deployment.apps/jenkins
REVISION CHANGE-CAUSE
1 <none>
2 <none>
# 回滚到上一版本
$ kubectl rollout undo deployment/jenkins -n cicd
deployment.apps/jenkins rolled back
# 回滚成功,状态为pending的pod已被删除
$ kubectl get pod -n cicd
NAME READY STATUS RESTARTS AGE
jenkins-5b688ddcc7-2zlwz 1/1 Running 0 5d23h