Job和Service
Job及CronJob:
---
apiVersion: batch/v1
kind: Job
metadata:
name: job-demo
spec:
template:
metadata:
name: job-demo
spec:
restartPolicy: Never
containers:
- name: counter
image: busybox
command:
- "/bin/sh"
- "-c"
- "for i in 9 8 7 6 5 4 3 2 1 ; do echo $i; done"
$ kubectl apply -f job-demo.yaml
$ kubectl get job
$ vim cronjob-demo.yaml
---
apiVersion: batch/v1beta1
kind: CronJob
metadata:
name: cronjob-demo
spec:
successfulJobsHistoryLimit: 10
failedJobsHistoryLimit: 10
schedule: "*/1 * * * *"
jobTemplate:
spec:
template:
metadata:
name: cronjob-demo
spec:
restartPolicy: Never
containers:
- name: counter
image: busybox
command:
- "/bin/sh"
- "-c"
- "for i in 9 8 7 6 5 4 3 2 1 0 -1 ; do echo $i; done"
spec.successfulJobsHistoryLimit和.spec.failedJobsHistoryLimit,表示历史限制,是可选的字段。它们指定了可以保留多少完成和失败的Job,默认没有限制,所有成功和失败的Job都会被保留。然而,当运行一个Cron Job时,Job可以很快就堆积很多,所以一般推荐设置这两个字段的值。如果设置限制的值为 0,那么相关类型的Job完成后将不会被保留
$ vim deploy-demo.yaml
---
apiVersion: apps/v1beta1
kind: Deployment
metadata:
name: nginx-deploy
labels:
app: nginx-demo
spec:
replicas: 3
revisionHistoryLimit: 15
minReadySeconds: 5
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 1
maxUnavailable: 1
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.9.7
ports:
- containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
name: myservice
spec:
selector:
app: nginx
type: NodePort
ports:
- name: mynginx-http
protocol: TCP
port: 80
targetPort: 80
nodePort: 30001