k8s重启pod方式

本文最后更新于:2022年6月6日 下午

Rolling Restart Method

Kubernetes now allows you to execute a rolling restart of your deployment as of version 1.15. This is the quickest restart mechanism in Kubernetes, as it is a new addition. The command given above shuts down and restarts each container in your deployment one by one. Because most of the containers are still functioning, your app will be accessible.

1
kubectl rollout restart deployment nginx-deploy

Environment Variable Method

Another option is to force pods to restart and sync with your changes by setting or changing an environment variable. You can, for instance, alter the date of container deployment:

In the scenario above, set env modifies the environment variables, deployment [deployment name] selects your deployment, and DEPLOY DATE=”$(date)” modifies the deployment date and causes the pod to resume.

1
kubectl set env deployment nginx-deploy DEPLOY_DATE="$(date)"

Scale Command to Change Replicas

You can modify the number of clones of the defective pod by using the scale command. When you set this value to 0, the pod is effectively turned off:

1
kubectl scale --replicas=0 deployment nginx-deploy

To restart the pod, provide the following command with a number of replicas greater than zero:

1
kubectl scale --replicas=N deployment nginx-deploy

References


k8s重启pod方式
https://baymax55.github.io/2022/06/04/k8s/k8s重启pod方式/
作者
baymax55
发布于
2022年6月4日
许可协议