Nem*_*one 3 cron jobs kubernetes minikube
我想创建一个作业来每分钟或创建时随时杀死以下 pod。
我的测试舱是:
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']
Run Code Online (Sandbox Code Playgroud)
可以这样做吗?
小智 6
是的,您可以使用 kubectl 删除集群内的 pod。首先,您需要创建一组RBAC(基于角色的访问控制)对象。这是示例。
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
Run Code Online (Sandbox Code Playgroud)
这些对象将定义适当的RABC规则,以便创建的Pod可以与Kubernetes相应的API进行交互。然后,您可以使用这样的 Cronjob 类型定义您的作业。
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
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2895 次 |
| 最近记录: |