简体   繁体   English

在运行时删除kubernetes pod

[英]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. 我们正在使用kubernetes部署我们的微服务,在生产模式下,我们将无法直接访问kubernetes,因此,有什么方法可以执行操作,例如使用rest api调用删除pod或通过http请求执行任何操作。

We need to delete a pod or its replica set to restart the pod forcefully. 我们需要删除Pod或其副本集以强制重新启动Pod。

Like we access a remote kubernetes and delete a particular pod at runtime 就像我们访问远程kubernetes并在运行时删除特定的pod

Yes by setting up RBAC. 是的,通过设置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" 一个服务帐户,它将识别您的Pod“服务”
  3. RoleBinding which grants your Service Account (2) the Role (1) to delete Pods in the Namespace RoleBinding授予您的服务帐户(2)角色(1)删除命名空间中的Pod

Then with given Serivce Account token you can either use kubectl or actual REST call to k8s apiserver to delete. 然后,使用给定的Serivce Account令牌,您可以使用kubectl或对k8s apiserver的实际REST调用来删除。

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. 如果您没有获得访问生产的kubectl命令或API的权利,则应在容器上实现活动性探针。

https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-probes/ 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) 您可以将活动性检查与可以手动创建的系统条件结合起来(数据库中的字段“ restart_request”设置为1,文件存在或类似的东西)

This way, you can restart your containers manually and k8s will restart them for you if they cease to operate properly. 这样,您可以手动重新启动容器,如果k8s停止正常运行,它们将为您重新启动它们。

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

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