Flutter开发App的未来及其在各行业的应用潜力分析
681
2022-11-24
Docker&Kubernetes ❀ Kubernetes集群Pod控制器 - Job
文章目录
1、基本概念与控制器特点2、资源配置清单3、创建控制器
3.1 Job控制单个Pod3.2 Job控制多个并发Pod
4、删除控制器
1、基本概念与控制器特点
Job:主要用于负责批量处理(一次性处理指定数量任务)短暂的一次性(每个任务仅运行一次就结束)任务;
特点如下:
2、资源配置清单
参数查询方法:[root@master ~]# kubectl explain job
参数汇总梳理:
apiVersion: batch/v1kind: Jobmetadata: name: pc-job namespace: dev labels: controller: job spec: completions: 6 #指定job需要成功运行Pod的次数,默认值为1 parallelism: 3 #指定job在任一时刻应该并发运行pod的数量,默认值为1 activeDeadlineSeconds: 30 #指定job可运行的时间期限,超过时间未结束系统会尝试终止 backoffLimit: 6 #指定job失败后进行重试的次数,默认为6 manualSelector: true #是否可以使用selector选择器选择pod,默认为false selector: #pod选择器,指定控制那些pod matchLabels: app: count-pod matchExpressions: - key: "app" operator: In values: ["nginx-pod"] template: #模板,当副本数量不足时,会根据以下配置创建副本 metadata: labels: app: counter-pod spec: restartPolicy: Never #重启策略,支持Nerver或OnFailure containers: - name: counter image: busybox:latest command: ["/bin/sh","-c","for i in 9 8 7 6 5 4 3 2 1;do echo $i;sleep 2;done"]
重启策略:
如果指定为OnFailure,则Job会在Pod出现故障时重启容器,而不是创建Pod,failer次数不会改变;如果指定为Never,则Job会在Pod出现故障时创建新的Pod,并且故障Pod不会消失,failed次数加1;如果指定为Always,则一直重启,意味着Job任务会重复执行,因此不能设置为Always;
3、创建控制器
下面主要介绍两个使用,首先使用Job创建单个Pod以观察Pod创建的具体过程,其次创建多个Pod,使其进行并发创建,然后观察创建过程;
3.1 Job控制单个Pod
此实验建议开启三个终端,第一个终端执行调用文件命令,第二个终端监控Job控制器,第三个终端监控Pod;
#创建YAML文件[root@master ~]# cat pc-job.yaml apiVersion: batch/v1kind: Jobmetadata: name: pc-job namespace: devspec: manualSelector: true selector: matchLabels: app: counter-pod template: metadata: labels: app: counter-pod spec: restartPolicy: Never containers: - name: counter image: busybox:latest command: ["/bin/sh","-c","for i in 9 8 7 6 5 4 3 2 1;do echo $i;sleep 2;done"]
#调用YAML文件[root@master ~]# kubectl apply -f pc-job.yaml job.batch/pc-job created#监控Job控制器[root@master ~]# kubectl get job -n dev -w NAME COMPLETIONS DURATION AGEpc-job 0/1 0spc-job 0/1 0s 0spc-job 0/1 35s 35spc-job 1/1 35s 35s#监控PodNAME READY STATUS RESTARTS AGEpc-job-qtw84 0/1 Pending 0 0spc-job-qtw84 0/1 Pending 0 0spc-job-qtw84 0/1 ContainerCreating 0 0spc-job-qtw84 0/1 ContainerCreating 0 1spc-job-qtw84 1/1 Running 0 17spc-job-qtw84 0/1 Completed 0 35spc-job-qtw84 0/1 Completed 0 35spc-job-qtw84 0/1 Completed 0 35s
3.2 Job控制多个并发Pod
此实验仍然建议开启三个终端,第一个终端执行调用文件命令,第二个终端监控Job控制器,第三个终端监控Pod;
#创建YAML文件[root@master ~]# vim pc-job.yamapiVersion: batch/v1kind: Jobmetadata: name: pc-job namespace: devspec: manualSelector: true completions: 6 #指定job需要成功运行Pod的次数,默认值为1 parallelism: 3 #指定job在任一时刻应该并发运行pod的数量,默认值为1 selector: matchLabels: app: counter-pod template: metadata: labels: app: counter-pod spec: restartPolicy: Never containers: - name: counter image: busybox:latest command: ["/bin/sh","-c","for i in 9 8 7 6 5 4 3 2 1;do echo $i;sleep 2;done"]
#调用YAML文件[root@master ~]# kubectl apply -f pc-job.yaml job.batch/pc-job created#监控Job控制器[root@master ~]# kubectl get job -n dev -w NAME COMPLETIONS DURATION AGEpc-job 0/6 0spc-job 0/6 0s 0spc-job 0/6 35s 35spc-job 1/6 35s 35spc-job 1/6 36s 36spc-job 2/6 36s 36spc-job 2/6 52s 52spc-job 3/6 52s 52spc-job 3/6 71s 71spc-job 4/6 71s 71spc-job 4/6 71s 71spc-job 5/6 71s 71spc-job 5/6 87s 87spc-job 6/6 87s 87s#监控Pod[root@master ~]# kubectl get pod -n dev -wNAME READY STATUS RESTARTS AGEpc-job-jllsm 0/1 Pending 0 0spc-job-882tp 0/1 Pending 0 0spc-job-xblq4 0/1 Pending 0 0s#与配置参数符合,一次性创建3个Pod执行Job任务,共6个任务,创建2次pc-job-882tp 0/1 Pending 0 0spc-job-jllsm 0/1 Pending 0 0spc-job-xblq4 0/1 Pending 0 0spc-job-882tp 0/1 ContainerCreating 0 0spc-job-xblq4 0/1 ContainerCreating 0 0spc-job-jllsm 0/1 ContainerCreating 0 0spc-job-882tp 0/1 ContainerCreating 0 1spc-job-jllsm 0/1 ContainerCreating 0 2spc-job-xblq4 0/1 ContainerCreating 0 2spc-job-882tp 1/1 Running 0 17spc-job-jllsm 1/1 Running 0 18spc-job-xblq4 1/1 Running 0 34spc-job-882tp 0/1 Completed 0 35spc-job-8scd8 0/1 Pending 0 0spc-job-8scd8 0/1 Pending 0 0spc-job-882tp 0/1 Completed 0 35spc-job-8scd8 0/1 ContainerCreating 0 0spc-job-882tp 0/1 Completed 0 35spc-job-jllsm 0/1 Completed 0 36spc-job-n8hd9 0/1 Pending 0 0spc-job-n8hd9 0/1 Pending 0 0spc-job-n8hd9 0/1 ContainerCreating 0 0spc-job-jllsm 0/1 Completed 0 36spc-job-jllsm 0/1 Completed 0 36spc-job-8scd8 0/1 ContainerCreating 0 1spc-job-n8hd9 0/1 ContainerCreating 0 1spc-job-xblq4 0/1 Completed 0 52spc-job-zs97t 0/1 Pending 0 0spc-job-xblq4 0/1 Completed 0 52spc-job-zs97t 0/1 Pending 0 0spc-job-zs97t 0/1 ContainerCreating 0 0spc-job-xblq4 0/1 Completed 0 52spc-job-8scd8 1/1 Running 0 17spc-job-zs97t 0/1 ContainerCreating 0 1spc-job-n8hd9 1/1 Running 0 17spc-job-zs97t 1/1 Running 0 17spc-job-8scd8 0/1 Completed 0 36spc-job-8scd8 0/1 Completed 0 36spc-job-8scd8 0/1 Completed 0 36spc-job-n8hd9 0/1 Completed 0 35spc-job-n8hd9 0/1 Completed 0 35spc-job-n8hd9 0/1 Completed 0 35spc-job-zs97t 0/1 Completed 0 35spc-job-zs97t 0/1 Completed 0 35spc-job-zs97t 0/1 Completed 0 35s
4、删除控制器
[root@master ~]# kubectl delete -f pc-job.yaml job.batch "pc-job" deleted
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~