简体   繁体   English

在 kubernetes(副本、部署和 pod 删除)中向下/向上扩展/重新启动应用程序的正确方法?

[英]Correct way to scale/restart an application down/up in kubernetes (replicaset, deployments and pod deletion)?

I usually restart my applications by:我通常通过以下方式重新启动我的应用程序:

kubectl scale deployment my-app --replicas=0

Followed by:其次是:

kubectl scale deployment my-app --replicas=1

which works fine.效果很好。 I also have another running application but when I look at its replicaset I see:我还有另一个正在运行的应用程序,但是当我查看它的副本集时,我看到:

$ kubectl get rs
NAME                                        DESIRED   CURRENT   READY     AGE
another-app                                 2         2         2         2d

So to restart that correctly I would of course need to:因此,要正确重新启动,我当然需要:

kubectl scale deployment another-app --replicas=0
kubectl scale deployment another-app --replicas=2

But is there a better way to do this so I don't have to manually look at the repliasets before scaling/restarting my application (that might have replicas > 1 )?但是有没有更好的方法来做到这一点,所以我不必在缩放/重新启动我的应用程序(可能有replicas > 1 )之前手动查看副本集?

You can restart pods by using level您可以使用 level 重新启动 pod

kubectl delete pods -l name=myLabel

You can rolling restart of all pods for a deployments, so that you don't take the service down您可以滚动重启部署的所有 pod,这样您就不会关闭服务

kubectl patch deployment your_deployment_name -p \
  "{\"spec\":{\"template\":{\"metadata\":{\"annotations\":{\"date\":\"`date +'%s'`\"}}}}}"

And After kubernetes version 1.15 you can而kubernetes 1.15版之后就可以

kubectl rollout restart deployment your_deployment_name

To make changes in your current deployment you can use kubectl rollout pause deployment/YOUR_DEPLOYMENT . 要更改当前部署,您可以使用kubectl rollout pause deployment/YOUR_DEPLOYMENT This way the deployment will be marked as paused and won't be reconciled by the controller.这样,部署将被标记为暂停,并且不会被 controller 协调。 After it's paused you can make necessary changes to your configuration and then resume it by using kubectl rollout resume deployment/YOUR_DEPLOYMENT .暂停后,您可以对配置进行必要的更改,然后使用kubectl rollout resume deployment/YOUR_DEPLOYMENT恢复它。 This way it will create a new replicaset with updated configuration.这样,它将创建一个具有更新配置的新replicaset

Pod with new configuration will be started and when it's in running status, pod with old configuration will be terminated.新配置的 Pod 将被启动,当它处于running状态时,旧配置的 Pod 将被终止。

Using this method you will be able to rollout the deployment to previous version by using:使用此方法,您将能够使用以下方法将部署部署到以前的版本:

kubectl rollout history deployment/YOUR_DEPLOYMENT

to check history of the rollouts and then execute following command to rollback:检查推出的历史记录,然后执行以下命令进行回滚:

kubectl rollout undo deployment/YOUR_DEPLOYMENT --to-revision=REVISION_NO

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

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