简体   繁体   English

kubectl 删除 pod 与设置环境

[英]kubectl delete pod vs set env

I can see that both kubectl delete pod and kubectl set env will restart.我可以看到kubectl delete podkubectl set env都会重新启动。 I would like to know the best practice to be followed, is there any advantage of using set env我想知道要遵循的最佳实践,使用set env有什么好处吗

Other than these two options, is there any other better option to restart a pod?除了这两个选项之外,还有其他更好的选项来重新启动 pod 吗?

Although your question is not really clear, I believe that you are now using deployment or other types of replica set to spawn the pods.尽管您的问题不是很清楚,但我相信您现在正在使用部署或其他类型的副本集来生成 pod。

So, neither kubectl delete pod nor kubectl set env are the correct one to restart all the replicas in the Kubernetes.因此, kubectl delete podkubectl set env都不是重启 Kubernetes 中所有副本的正确方法。 The proper way to restart all the pod under a replica set is kubectl rollout restart <type-of-replica-set>/<name> .重启副本集下所有 pod 的正确方法是kubectl rollout restart <type-of-replica-set>/<name>

But kubectl delete pod and kubectl set env still work by seeing the conclusion only.但是kubectl delete podkubectl set env仍然可以通过只看到结论来工作。 Here are the reasons.以下是原因。

kubectl delete pod will reduce the number of desired pods for your replica set. kubectl delete pod将减少副本集所需的 pod 数量。 The replica set controller will reconcile and spawn a new pod in order to fulfill your desired number defined.副本集 controller 将协调并生成一个新 pod,以满足您定义的所需数量。

kubectl set env is used for updating the environment variable in the specification. kubectl set env用于更新规范中的环境变量。 So, once you run the command, the whole version in the replica set is bumped.因此,一旦您运行该命令,副本集中的整个版本就会被碰撞。 The controller will reconcile and try to spawn a new set of pods for you. controller 将协调并尝试为您生成一组新的 pod。

Eventually, both of the commands can lead you to the restart of the pods.最终,这两个命令都可以引导您重新启动 pod。 But the commands are not designed for restart.但是这些命令不是为重新启动而设计的。

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

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