简体   繁体   中英

Delete kubernetes pod at run time

We are using kubernetes for deployment of our microservices , In production mode we will not be able to access kubernetes directly , So is there any way to perform operation like delete a pod using rest api calls or perform any operation through http requests.

We need to delete a pod or its replica set to restart the pod forcefully.

Like we access a remote kubernetes and delete a particular pod at runtime

Yes by setting up RBAC.

You need following:

  1. A Role in Namespace your pods are running with "delete" permission on resources you want to delete.
  2. A Service Account which will identify your Pod "service"
  3. RoleBinding which grants your Service Account (2) the Role (1) to delete Pods in the Namespace

Then with given Serivce Account token you can either use kubectl or actual REST call to k8s apiserver to delete.

If you will not receive the right to access the kubectl command or API for the production, you should implement a liveness probe on the container.

https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-probes/

This you can do entirely in software in your microservices. The liveness check should fail, if your application is no longer "good". You can combine the liveness check with a system condition that you can create manually (a field "restart_request" in the database is set to 1, a file exists or sth like that)

This way, you can restart your containers manually and k8s will restart them for you if they cease to operate properly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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