简体   繁体   English

Kubernetes kubectl 补丁 pod 与删除/创建 pod

[英]Kubernetes kubectl patch pod vs delete/create pod

I have a Pod - I want to update to latest version of container image, if it fails then want to revert it back to earlier version of container image.我有一个 Pod - 我想更新到最新版本的容器映像,如果它失败了,那么想将它恢复到早期版本的容器映像。

Which approach of below will be good to update to latest or earlier container image.下面哪种方法可以很好地更新到最新或更早的容器映像。 1> using kubectl patch is good option? 1> 使用 kubectl 补丁是不错的选择? 2> deleting the pod and again creating the pod is good option? 2> 删除 pod 并再次创建 pod 是个好选择吗?

what are benefits/disadvantages of both approach.两种方法的优缺点是什么。

kubectl patch pod test-pod -p '{"spec":{"containers":[{"name":"test","image":"1.0"}]}}'

kubectl delete pod test-pod and kubectl apply -f testpod.yaml

based on the scenario put up by you, you can choose to look for doing canary deployments by using the rolling update strategy, if the new deployment's containers fail to serve the load then the old ones will not be destroyed and load will continuously be served by pre-existing containers.根据您提出的场景,您可以选择使用滚动更新策略寻找金丝雀部署,如果新部署的容器无法服务负载,则旧的容器不会被销毁,负载将继续由预先存在的容器。

The other way can be to keep deployment history, you can define the number of manifests you want to be saved by kubernetes and then you can manually rollback to your desired version另一种方法是保留部署历史记录,您可以通过 kubernetes 定义要保存的清单数量,然后您可以手动回滚到您想要的版本

And if you are not aware about what version carries which image then you can go for patch command, as portrayed by you in the question如果您不知道哪个版本带有哪个图像,那么您可以使用 go 进行补丁命令,正如您在问题中所描述的那样

From the docs here one of the use cases of deployment这里的文档中,部署的用例之一

Rollback to an earlier Deployment revision if the current state of the Deployment is not stable.如果 Deployment 的当前 state 不稳定,则回滚到较早的 Deployment 修订版。 Each rollback updates the revision of the Deployment.每次回滚都会更新 Deployment 的修订版。

So use deployment to perform rolling update and rollback when necessary所以在必要的时候使用deployment来执行滚动更新回滚

kubectl set image deployment.v1.apps/nginx-deployment nginx=nginx:1.161 --record=true

Check rollout history检查推出历史

kubectl rollout history deployment.v1.apps/nginx-deployment

Rollback to a previous version回滚到以前的版本

kubectl rollout undo deployment.v1.apps/nginx-deployment

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM