Deployment回滚(二)-视点
2023-05-01 15:05:51 腾讯云


【资料图】

回滚到之前的版本

如果我们想要回滚到之前的某个版本,我们可以使用以下命令查看Deployment的更新历史记录:

kubectl rollout history deployment/nginx-deployment

这将输出类似于以下内容的信息:

deployment.apps/nginx-deployment REVISION  CHANGE-CAUSE1         kubectl create -f nginx-deployment.yaml --record=true2         kubectl set image deployment/nginx-deployment nginx=nginx:1.17 --record=true3         kubectl set image deployment/nginx-deployment nginx=nginx:1.16 --record=true

我们可以看到Deployment共进行了3次滚动更新,我们可以回滚到任意一个版本。假设我们想要回滚到步骤3:回滚Deployment

如果新版本出现问题,您需要快速回滚Deployment。Deployment提供了回滚机制,可以使您快速回到先前的稳定版本。回滚Deployment会自动启动Rollback操作,它会撤消Deployment中的所有更改,并将其回滚到先前的版本。回滚将不断重试,直到所有Pod都达到先前的版本。

在我们的示例中,我们将回滚Deployment以将它恢复到早期版本。

检查Deployment状态:

$ kubectl rollout status deployment hello-deployment

回滚Deployment:

$ kubectl rollout undo deployment hello-deployment

检查回滚状态:

$ kubectl rollout status deployment hello-deployment

输出:

Waiting for deployment "hello-deployment" rollout to finish: 1 out of 3 new replicas have been updated...Waiting for deployment "hello-deployment" rollout to finish: 1 out of 3 new replicas have been updated...Waiting for deployment "hello-deployment" rollout to finish: 2 out of 3 new replicas have been updated...Waiting for deployment "hello-deployment" rollout to finish: 2 out of 3 new replicas have been updated...deployment "hello-deployment" successfully rolled out

您可以看到回滚Deployment后,状态已恢复到早期版本。

相关新闻: