标签:yun 创建 文件 kubectl nta get pod version delete
job例子:
apiVersion: batch/v1 #job的apiVersion kind: Job #资源类型为job metadata: labels: name: busybox name: busybox spec: template: metadata: name: busybox spec: containers: - name: busybox image: myhub.mingyuanyun.com/library/busybox command: - sleep - "30" restartPolicy: Never #什么情况下重启容器,job一般只能设置为Never和OnFailure,一般设置为Never
restartPolicy: Never #如果使用参数Never,容器启动后未成功就会一直创建新的容器
restartPolicy: OnFailure #如果使用参数OnFailure,容器启动后未成功不会在创建新的容器,他会一直重启
kubectl apply -f myjob.yaml
kubectl get job
kubectl get pod --show-all
kubectl logs busybox
kubectl delete -f myjob.yaml
并行job的创建:
apiVersion: batch/v1 kind: Job metadata: labels: name: busybox name: busybox spec:
completions: 6 #直到总共有6个pod成功执行 如果不指定默认值为1
parallelism: 2 #一次启动2个pod来执行job 如果不指定默认值为1 template: metadata: name: busybox spec: containers: - name: busybox image: myhub.mingyuanyun.com/library/busybox command: - sleep - "30" restartPolicy: Never
定时job:
apiVersion: batch/v2alpha1 #当前CronJob的apiVersion kind: CronJob #当前类型CronJob metadata: name: test spec: schedule: "*/1 * * * *" #运行时间,格式与linux一致 jobTemplate: #job模板 spec: template: spec: containners: - name: test image: nginx command: ["echo", "this is test"] restartPolicy: OnFailure
需要在kube-aoiservier配置文件中添加
kubectl api-version #查看当前所有api-version 是否支持 batch/v2alpha1
kubectl get cronjob
标签:yun 创建 文件 kubectl nta get pod version delete
原文地址:https://www.cnblogs.com/kuku0223/p/9203015.html