Kubernetes作业每分钟删除一个Pod

编程入门 行业动态 更新时间:2024-10-26 12:35:24
本文介绍了Kubernetes作业每分钟删除一个Pod的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想创建一个Job,以便每隔一分钟或创建后的任何时间杀死以下Pod.

I'd like to create a Job to kill the following pod every single minute or any time when is created.

我的测试平台是:

apiVersion: v1 kind: Pod metadata: name: myapp-pod labels: app: myapp spec: containers: - name: myapp-container image: busybox command: ['sh', '-c', 'echo Hello && sleep 3600']

有可能这样做吗?

推荐答案

是的,您可以在集群中删除带有kubectl的Pod. 首先,您需要创建一组RBAC(基于角色的访问控制)对象. 这是示例.

Yes, you can delete the pods with kubectl within the cluster. First, you need to create a set of RBAC(Role-based access control) object. Here is the sample.

apiVersion: v1 kind: ServiceAccount metadata: name: test # this is service account for binding the pod --- apiVersion: rbac.authorization.k8s.io/v1 kind: Role metadata: name: test # This defines a role and what API it can access rules: - apiGroups: [""] resources: ["pods"] verbs: ["delete", "get", "list"] --- apiVersion: rbac.authorization.k8s.io/v1 kind: RoleBinding metadata: name: test # This will bind the role and service account subjects: - kind: ServiceAccount name: test roleRef: kind: Role name: test apiGroup: rbac.authorization.k8s.io

这些对象将定义适当的RABC规则,以便创建的Pod可以与Kubernetes的相应API进行交互. 然后,您可以使用这样的Cronjob类型定义Job.

These objects will define a proper RABC rule so that the pod created can interact with Kubernetes's corresponding API. Then, you can define your Job with a Cronjob type like this.

apiVersion: batch/v1beta1 kind: CronJob metadata: name: kill-pod spec: schedule: "*/1 * * * *" jobTemplate: spec: template: spec: serviceAccountName: test containers: - name: kill-pod image: bitnami/kubectl:latest command: - kubectl args: - delete - pod - sth restartPolicy: OnFailure

更多推荐

Kubernetes作业每分钟删除一个Pod

本文发布于:2023-06-07 15:26:33,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/568599.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:作业   每分钟   Kubernetes   Pod

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!