k8s入门(二)之Deployment、DaemonSet、Job、CronJob

news2024/11/28 0:34:25

一、Deployment使用


状态:Available部署完成,Progressing进行中,Complete已经完成,Failed失败的
失败原因:Quota不足,ReadingnessProbe失败,image pull失败,Limit Ranges范围,应用程序运行错误

1、创建nginx deploy

[root@master01 ~]# cat nginx-deploy.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
  labels:
    app: nginx
spec:
  replicas: 3
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:latest
        imagePullPolicy: IfNotPresent
        ports:
        - containerPort: 80
        
[root@master01 ~]# kubectl get pod --show-labels
NAME                                READY   STATUS    RESTARTS   AGE     LABELS
nginx-deployment-66b9f7ff85-2mqpj   1/1     Running   0          1m13s   app=nginx,pod-template-hash=66b9f7ff85
nginx-deployment-66b9f7ff85-d9rqv   1/1     Running   0          1m13s   app=nginx,pod-template-hash=66b9f7ff85
nginx-deployment-66b9f7ff85-db8fk   1/1     Running   0          1m13s   app=nginx,pod-template-hash=66b9f7ff85

2、更新版本

(1)通过set修改

[root@master01 ~]# kubectl get deployment -o wide
NAME               READY   UP-TO-DATE   AVAILABLE   AGE   CONTAINERS   IMAGES         SELECTOR
nginx-deployment   3/3     3            3           15m   nginx        nginx:latest   app=nginx
[root@master01 ~]# kubectl set image deployment/nginx-deployment nginx=nginx:1.18
deployment.apps/nginx-deployment image updated
[root@master01 ~]# kubectl get deployment -o wide
NAME               READY   UP-TO-DATE   AVAILABLE   AGE   CONTAINERS   IMAGES       SELECTOR
nginx-deployment   3/3     1            3           15m   nginx        nginx:1.18   app=nginx

(2)通过edit修改

[root@master01 ~]# kubectl edit deployment nginx-deployment
[root@master01 ~]# kubectl get deployment -o wide
NAME               READY   UP-TO-DATE   AVAILABLE   AGE   CONTAINERS   IMAGES       SELECTOR
nginx-deployment   3/3     1            3           17m   nginx        nginx:1.19   app=nginx

[root@master01 ~]# kubectl rollout status deployment nginx-deployment      #查看更新状态
deployment "nginx-deployment" successfully rolled out

在这里插入图片描述

3、发布策略

(1)Recreate

. 此技术意味着服务的停机时间取决于应用程序的关闭和启动持续时间


[root@master01 ~]# cat nginx-deploy.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
  labels:
    app: nginx
spec:
  strategy:
    rollingUpdate:
    type: Recreate
  replicas: 3
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.19
        imagePullPolicy: IfNotPresent
        ports:
        - containerPort: 80

[root@master01 ~]# kubectl apply -f nginx-deploy.yaml
[root@master01 ~]# kubectl get pod -w     #开另外一个terminal查看过程

(2)滚动更新(rolling-update)

滚动更新通过逐个替换实例来逐步部署新版本的应用,直到所有实例都被替换完成为止。

[root@master01 ~]# cat nginx-deploy.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
  labels:
    app: nginx
spec:
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxSurge: 25%
      maxUnavailable: 25%
  replicas: 3
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.19
        imagePullPolicy: IfNotPresent
        ports:
        - containerPort: 80

[root@master01 ~]# kubectl apply -f nginx-deploy.yaml

4、回滚

[root@master01 ~]# kubectl set image deployment/nginx-deployment nginx=nginx:1.19  --record=true    #更新记录方便回滚
[root@master01 ~]# kubectl rollout history deployment nginx-deployment    #查看历史
deployment.apps/nginx-deployment
REVISION  CHANGE-CAUSE
2         <none>
4         <none>
7         kubectl set image deployment/nginx-deployment nginx=nginx:1.19 --record=true

[root@master01 ~]# kubectl rollout history deployment nginx-deployment --revision=7  #查看细节
deployment.apps/nginx-deployment with revision #7
Pod Template:
  Labels:       app=nginx
        pod-template-hash=6f777cb8b7
  Annotations:  kubernetes.io/change-cause: kubectl set image deployment/nginx-deployment nginx=nginx:1.19 --record=true
  Containers:
   nginx:
    Image:      nginx:1.19
    Port:       80/TCP
    Host Port:  0/TCP
    Environment:        <none>
    Mounts:     <none>
  Volumes:      <none>

[root@master01 ~]# kubectl rollout undo deployment nginx-deployment      #回滚上一个版本
[root@master01 ~]# kubectl rollout undo undo deployment nginx-deployment --to-revision=7  #回滚指定版本

5、添加注释

(1)通过命令

[root@master01 ~]# kubectl annotate deployments.apps nginx-deployment kubernetes.io/change-cause="image update to 1.19"   #写注释

(2)通过文件


[root@master01 ~]# cat nginx-deploy.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
  annotations:
    kubernetes.io/change-cause: "Image update to 1.19"
  labels:
    app: nginx
spec:
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxSurge: 25%
      maxUnavailable: 25%
  replicas: 3
  selector:
    matchLabels:
      app: nginx
  revisionHistoryLimit: 20
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.19
        imagePullPolicy: IfNotPresent
        ports:
        - containerPort: 80

[root@master01 ~]# kubectl apply -f nginx-deploy.yaml
[root@master01 ~]# kubectl describe deployment nginx-deployment

在这里插入图片描述

6、patch操作

[root@master01 ~]# cat nginx-deploy.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
  annotations:
    kubernetes.io/change-cause: "Image update to latest"
  labels:
    app: nginx
spec:
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxSurge: 25%
      maxUnavailable: 25%
  replicas: 10
  selector:
    matchLabels:
      app: nginx
  revisionHistoryLimit: 20
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:latest
        imagePullPolicy: IfNotPresent
        ports:
        - containerPort: 80

[root@master01 ~]# kubectl apply -f nginx-deploy.yaml
[root@master01 ~]# kubectl patch deployments.apps nginx-deployment --type=json -p='[{"op":"replace","path":"/spec/template/spec/containers/0/image","value":"nginx:1.19"}]'

[root@master01 ~]# kubectl get deployment  -owide
NAME               READY   UP-TO-DATE   AVAILABLE   AGE   CONTAINERS   IMAGES       SELECTOR
nginx-deployment   10/10    10           10           3h    nginx        nginx:1.19   app=nginx

[root@master01 ~]# kubectl patch deployments.apps nginx-deployment -p '{"spec":{"replicas":3}}'
[root@master01 ~]# kubectl get deployment  -owide
NAME               READY   UP-TO-DATE   AVAILABLE   AGE    CONTAINERS   IMAGES       SELECTOR
nginx-deployment   3/3     3            3           3h4m   nginx        nginx:1.19   app=nginx

7、通过不同文件更新

[root@master01 ~]# kubectl delete -f nginx-deploy.yaml
[root@master01 ~]# cat nginx-deploy-v2.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
  annotations:
    kubernetes.io/change-cause: "Image update to latest"
  labels:
    app: nginx
spec:
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxSurge: 25%
      maxUnavailable: 25%
  replicas: 10
  selector:
    matchLabels:
      app: nginx
  revisionHistoryLimit: 20
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.21
        imagePullPolicy: IfNotPresent
        ports:
        - containerPort: 80

[root@master01 ~]# kubectl delete -f nginx-deploy.yaml
[root@master01 ~]# kubectl replace -f nginx-deploy-v2.yaml

8、副本数量操作

  • 如果总数为10
  • maxUnavailable: 10 -(10*25%)向下取整,结果为8
  • maxSurge = 10 + (10*25%)向上取整,结果为13
[root@master01 ~]# kubectl apply -f nginx-deploy.yaml
[root@master01 ~]# kubectl get pod
NAME                                READY   STATUS    RESTARTS   AGE
nginx-deployment-66b9f7ff85-5cs67   1/1     Running   0          5s
nginx-deployment-66b9f7ff85-6jkq8   1/1     Running   0          5s
nginx-deployment-66b9f7ff85-6pv4x   1/1     Running   0          5s
nginx-deployment-66b9f7ff85-8s8mm   1/1     Running   0          5s
nginx-deployment-66b9f7ff85-hhv97   1/1     Running   0          5s
nginx-deployment-66b9f7ff85-htkwj   1/1     Running   0          5s
nginx-deployment-66b9f7ff85-j8h22   1/1     Running   0          5s
nginx-deployment-66b9f7ff85-k7fwn   1/1     Running   0          5s
nginx-deployment-66b9f7ff85-n7fdn   1/1     Running   0          5s
nginx-deployment-66b9f7ff85-zzsqb   1/1     Running   0          5s

[root@master01 ~]# kubectl scale deployment nginx-deployment --replicas 3
deployment.apps/nginx-deployment scaled
[root@master01 ~]# kubectl get pod
NAME                                READY   STATUS    RESTARTS   AGE
nginx-deployment-66b9f7ff85-hhv97   1/1     Running   0          92s
nginx-deployment-66b9f7ff85-j8h22   1/1     Running   0          92s
nginx-deployment-66b9f7ff85-k7fwn   1/1     Running   0          92s

[root@master01 ~]# kubectl scale deployment nginx-deployment --replicas 10
[root@master01 ~]# kubectl get pod
NAME                                READY   STATUS    RESTARTS   AGE
nginx-deployment-66b9f7ff85-6jh8k   1/1     Running   0          3s
nginx-deployment-66b9f7ff85-9dzfj   1/1     Running   0          3s
nginx-deployment-66b9f7ff85-ght2r   1/1     Running   0          3s
nginx-deployment-66b9f7ff85-hhv97   1/1     Running   0          115s
nginx-deployment-66b9f7ff85-j8h22   1/1     Running   0          115s
nginx-deployment-66b9f7ff85-k7fwn   1/1     Running   0          115s
nginx-deployment-66b9f7ff85-kp969   1/1     Running   0          3s
nginx-deployment-66b9f7ff85-w7f8t   1/1     Running   0          3s
nginx-deployment-66b9f7ff85-zhkjn   1/1     Running   0          3s
nginx-deployment-66b9f7ff85-zjmlg   1/1     Running   0          3s

二、探针使用


1、readinessProbe

(1)Exec探针

[root@master01 ~]# cat read-pod.yaml
apiVersion: v1
kind: Pod
metadata:
  name: readiness
  labels:
     test: readiness
spec:
  containers:
  - name: readiness
    image: busybox:latest
    command:
    - "/bin/sh"
    - "-c"
    - "touch /tmp/healthy;sleep 30; rm -rf /tmp/healthy;sleep 100000000000"
    readinessProbe:
      exec:
        command:
        - cat
        - /tmp/healthy
      initialDelaySeconds: 10
      periodSeconds: 5

[root@master01 ~]# kubectl apply -f read-pod.yaml
[root@master01 ~]# kubectl get pod -w
[root@master01 ~]# kubectl describe pod readiness

在这里插入图片描述
在这里插入图片描述
(2)httpGet和Socket探针

[root@master01 ~]# cat nginx-deploy.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
  annotations:
    kubernetes.io/change-cause: "Image update to latest"
  labels:
    app: nginx
spec:
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxSurge: 25%
      maxUnavailable: 25%
  minReadySeconds: 10
  progressDeadlineSeconds: 600
  replicas: 10
  selector:
    matchLabels:
      app: nginx
  revisionHistoryLimit: 20
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:latest
        imagePullPolicy: IfNotPresent
        ports:
        - containerPort: 80
        readinessProbe:
          #httpGet:
          #  path: /
          #  port: 80
          #periodSeconds: 1
          tcpSocket:
            port: 80
          initialDelaySeconds: 15
          periodSeconds: 20


[root@master01 ~]# kubectl apply -f nginx-deploy.yaml
[root@master01 ~]# kubectl describe deployment nginx-deployment

2、Liveness探针

(1)Exec

[root@master01 ~]# cat live-pod.yaml
apiVersion: v1
kind: Pod
metadata:
  name: liveness
  labels:
     test: liveness
spec:
  containers:
  - name: liveness
    image: busybox:latest
    command:
    - "/bin/sh"
    - "-c"
    - "touch /tmp/healthy;sleep 30; rm -rf /tmp/healthy;sleep 100000000000"
    livenessProbe:
      exec:
        command:
        - cat
        - /tmp/healthy
      initialDelaySeconds: 10
      periodSeconds: 5

[root@master01 ~]# kubectl apply -f live-pod.yaml
[root@master01 ~]# kubectl get pod -w

在这里插入图片描述
(2)httpGet探针

[root@master01 ~]# cat nginx-deploy.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
  annotations:
    kubernetes.io/change-cause: "Image update to latest"
  labels:
    app: nginx
spec:
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxSurge: 25%
      maxUnavailable: 25%
  minReadySeconds: 10
  progressDeadlineSeconds: 600
  replicas: 10
  selector:
    matchLabels:
      app: nginx
  revisionHistoryLimit: 20
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:latest
        imagePullPolicy: IfNotPresent
        ports:
        - name: liveneess-port
          containerPort: 80
        readinessProbe:
          #httpGet:
          #  path: /
          #  port: 80
          #periodSeconds: 1
          tcpSocket:
            port: 80
          initialDelaySeconds: 15
          periodSeconds: 20

        livenessProbe:
          httpGet:
            path: /
            port: liveneess-port

[root@master01 ~]# kubectl apply -f nginx-deploy.yaml
[root@master01 ~]# kubectl describe deployment nginx-deployment

在这里插入图片描述

3、startupProbe

(1)httpGet

[root@master01 ~]# cat nginx-deploy.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
  annotations:
    kubernetes.io/change-cause: "Image update to latest"
  labels:
    app: nginx
spec:
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxSurge: 25%
      maxUnavailable: 25%
  minReadySeconds: 10
  progressDeadlineSeconds: 600
  replicas: 10
  selector:
    matchLabels:
      app: nginx
  revisionHistoryLimit: 20
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:latest
        imagePullPolicy: IfNotPresent
        ports:
        - name: liveneess-port
          containerPort: 80
        readinessProbe:
          #httpGet:
          #  path: /
          #  port: 80
          #periodSeconds: 1
          tcpSocket:
            port: 80
          initialDelaySeconds: 15
          periodSeconds: 20

        livenessProbe:
          httpGet:
            path: /
            port: liveneess-port
        startupProbe:
          httpGet:
            path: /
            port: liveneess-port
          failureThreshold: 30
          periodSeconds: 20

[root@master01 ~]# kubectl apply -f nginx-deploy.yaml
[root@master01 ~]# kubectl describe deployment nginx-deployment

在这里插入图片描述
(2)滚动更新

[root@master01 ~]# cat app.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: app
spec:
  minReadySeconds: 10
  selector:
    matchLabels:
      run: app
  replicas: 10
  template:
    metadata:
      labels:
        run: app
    spec:
      containers:
      - name: app
        image: busybox:latest
        args:
        - /bin/sh
        - -c
        - sleep 10; touch /tmp/healthy;sleep 100000000000
        readinessProbe:
          exec:
            command:
            - cat
            - /tmp/healthy
          initialDelaySeconds: 10
          periodSeconds: 5

[root@master01 ~]# cat app_v2.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: app
spec:
  minReadySeconds: 10
  selector:
    matchLabels:
      run: app
  replicas: 10
  template:
    metadata:
      labels:
        run: app
    spec:
      containers:
      - name: app
        image: busybox:latest
        args:
        - /bin/sh
        - -c
        - sleep 100000000000
        readinessProbe:
          exec:
            command:
            - cat
            - /tmp/healthy
          initialDelaySeconds: 10
          periodSeconds: 5

[root@master01 ~]# kubectl apply -f app.yaml
[root@master01 ~]# kubectl apply -f app_v2.yaml
[root@master01 ~]# kubectl get pod
NAME                   READY   STATUS        RESTARTS   AGE
app-6fb66c48fc-58dpt   1/1     Running       0          2m18s
app-6fb66c48fc-5sx5w   1/1     Running       0          2m18s
app-6fb66c48fc-75dtw   1/1     Running       0          2m18s
app-6fb66c48fc-79nhq   1/1     Running       0          2m18s
app-6fb66c48fc-8v9hs   1/1     Terminating   0          2m18s
app-6fb66c48fc-cgxj6   1/1     Running       0          2m18s
app-6fb66c48fc-cztkt   1/1     Running       0          2m18s
app-6fb66c48fc-f4npw   1/1     Terminating   0          2m18s
app-6fb66c48fc-g5vsv   1/1     Running       0          2m18s
app-6fb66c48fc-wjq5b   1/1     Running       0          2m18s
app-d7855499b-8lv5l    0/1     Running       0          23s
app-d7855499b-chgg9    0/1     Running       0          23s
app-d7855499b-ph7jw    0/1     Running       0          22s
app-d7855499b-q8xd7    0/1     Running       0          22s
app-d7855499b-qmqc6    0/1     Running       0          23s
[root@master01 ~]# kubectl rollout status deployment app
Waiting for deployment "app" rollout to finish: 5 out of 10 new replicas have been updated...

[root@master01 ~]# kubectl delete -f app_v2.yaml

三、DaemonSet


1、部署cAdvisor-RollingUpdate

如果不是每个节点都安装,那么需要加tolerations
通过set image就可以进行更新

[root@master01 ~]# cat cadvisor.yaml
apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: cadvisor
  labels:
    k8s-app: cadvisor
spec:
  selector:
    matchLabels:
      name: cadvisor
  updateStrategy:
    type: RollingUpdate
    rollingUpdate:
      maxUnavailable: 1
  template:
    metadata:
      labels:
        name: cadvisor
    spec:
      hostNetwork: true
      containers:
      - name: cadvisor
        image: google/cadvisor:latest
        ports:
        - containerPort: 8080
        volumeMounts:
        - name: rootfs
          mountPath: /rootfs
          readOnly: true
        - name: sys
          mountPath: /sys
          readOnly: true
        - name: containerd
          mountPath: /var/lib/containerd
          readOnly: true
        - name: disk
          mountPath: /dev/disk
          readOnly: true
      volumes:
        - name: rootfs
          hostPath:
            path: /
        - name: sys
          hostPath:
            path: /sys
        - name: containerd
          hostPath:
            path: /var/lib/containerd
        - name: disk
          hostPath:
            path: /dev/disk

[root@master01 ~]# kubectl apply -f cadvisor.yaml
[root@master01 ~]# kubectl get pod -owide
NAME             READY   STATUS    RESTARTS   AGE   IP            NODE       NOMINATED NODE   READINESS GATES
cadvisor-5mfxm   1/1     Running   0          44s   10.10.10.23   master03   <none>           <none>
cadvisor-d6mj9   1/1     Running   0          44s   10.10.10.21   master01   <none>           <none>
cadvisor-hl4nx   1/1     Running   0          44s   10.10.10.24   node01     <none>           <none>
cadvisor-w6lm4   1/1     Running   0          44s   10.10.10.22   master02   <none>           <none>
cadvisor-wcf4d   1/1     Running   0          44s   10.10.10.25   node02     <none>           <none>

[root@master01 ~]# kubectl rollout history daemonset cadvisor      #查看更新记录

2、部署cAdvisor-OnDelete

手动更新,自己去删除更新

[root@master01 ~]# cat cadvisor.yaml
apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: cadvisor
  labels:
    k8s-app: cadvisor
spec:
  selector:
    matchLabels:
      name: cadvisor
  updateStrategy:
    type: OnDelete
  template:
    metadata:
      labels:
        name: cadvisor
    spec:
      hostNetwork: true
      containers:
      - name: cadvisor
        image: google/cadvisor:latest
        ports:
        - containerPort: 8080
        volumeMounts:
        - name: rootfs
          mountPath: /rootfs
          readOnly: true
        - name: sys
          mountPath: /sys
          readOnly: true
        - name: containerd
          mountPath: /var/lib/containerd
          readOnly: true
        - name: disk
          mountPath: /dev/disk
          readOnly: true
      volumes:
        - name: rootfs
          hostPath:
            path: /
        - name: sys
          hostPath:
            path: /sys
        - name: containerd
          hostPath:
            path: /var/lib/containerd
        - name: disk
          hostPath:
            path: /dev/disk

[root@master01 ~]# kubectl apply -f cadvisor.yaml
[root@master01 ~]# kubectl delete -f cadvisor.yaml

四、Job与CronJob


1、Job初体验

restartPolicy: alway、Never、OnFailure
Never:如果发生错误会一直新建pod,会把资源耗尽,可通过backoffLimit:限制最多几次 activeDeadlineSeconds:多少秒就删除 ttlSecondsAfterFinished:清理失败或者成功job时间

[root@master01 ~]# cat myjob.yaml
apiVersion: batch/v1
kind: Job
metadata:
  name: myjob
spec:
  backoffLimit: 3
  activeDeadlineSeconds: 10
  ttlSecondsAfterFinished: 30
  template:
    spec:
      containers:
      - name: myjob
        image: busybox
        command: ["echo","hello world!"]
      restartPolicy: Never
[root@master01 ~]# cat myjob.yaml
apiVersion: batch/v1
kind: Job
metadata:
  name: myjob
spec:
  backoffLimit: 3
  activeDeadlineSeconds: 10
  ttlSecondsAfterFinished: 30
  template:
    spec:
      containers:
      - name: myjob
        image: busybox
        command: ["echo","hello world!"]
      restartPolicy: Never

[root@master01 ~]# kubectl apply -f myjob.yaml
[root@master01 ~]# kubectl get pod
NAME          READY   STATUS      RESTARTS   AGE
myjob-cqmxf   0/1     Completed   0          19s

[root@master01 ~]# kubectl get jobs myjob
NAME    COMPLETIONS   DURATION   AGE
myjob   1/1           5s         2m1s

[root@master01 ~]# kubectl logs myjob-cqmxf
hello world!

[root@master01 ~]# kubectl delete -f myjob.yaml

在这里插入图片描述
(2)同时运行2个

completions:执行总量

[root@master01 ~]# cat myjob.yaml
apiVersion: batch/v1
kind: Job
metadata:
  name: myjob
spec:
  parallelism: 2
  completions: 10
  completionMode: Indexed
  backoffLimit: 3
  activeDeadlineSeconds: 120
  ttlSecondsAfterFinished: 1200
  template:
    spec:
      containers:
      - name: myjob
        image: busybox
        command: ["echo","hello world!"]
      restartPolicy: Never

[root@master01 ~]# kubectl apply -f myjob.yaml

2、CronJob初体验

设置时区:timeZone: Etc/UTC

[root@master01 ~]# cat cronjob.yaml
apiVersion: batch/v1
kind: CronJob
metadata:
  name: hello
spec:
  schedule: "*/1 * * * *"
  jobTemplate:
    spec:
      template:
        spec:
          containers:
          - name: hello
            image: busybox
            command: ["echo","hello world!"]
          restartPolicy: OnFailure
          
[root@master01 ~]# kubectl apply -f cronjob.yaml

3、CronJob设置参数

  successfulJobsHistoryLimit: 3    #记录成功次数3
  failedJobsHistoryLimit: 3        #记录失败次数3
  startingDeadlineSeconds: 200     #最晚执行时间
  concurrencyPolicy: Allow         #允许叠加,Forbid忽略旧任务 Replace忽略新任务 
[root@master01 ~]# cat cronjob.yaml
apiVersion: batch/v1
kind: CronJob
metadata:
  name: hello
spec:
  successfulJobsHistoryLimit: 3
  failedJobsHistoryLimit: 3
  startingDeadlineSeconds: 200
  concurrencyPolicy: Allow
  schedule: "*/1 * * * *"
  jobTemplate:
    spec:
      template:
        spec:
          containers:
          - name: hello
            image: busybox
            command: ["echo","hello world!"]
          restartPolicy: OnFailure

[root@master01 ~]# kubectl apply -f cronjob.yaml

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/597992.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

一分钟跑出 AI 图像的生成平台

*Stability AI 最近推出了一个名为 StableStudio 的 AI 图像生成平台&#xff0c;这是一个开源的、基于社区驱动的平台&#xff0c;任何人都可以访问和使用。StableStudio 提供了一系列功能强大的工具和库&#xff0c;包括预训练模型、数据集、模型评估和调试工具等&#xff0c…

NSSCTF之Web篇刷题记录(13)

NSSCTF之Web篇刷题记录[12] [GXYCTF 2019]BabyUpload&#xff1a;[GKCTF 2020]cve版签到&#xff1a;[HCTF 2018]Warmup&#xff1a;[GDOUCTF 2023]泄露的伪装&#xff1a;[羊城杯 2020]easycon&#xff1a;[HNCTF 2022 Week1]Interesting_include&#xff1a; NSSCTF平台&…

还有人不知道,加盟连锁店该怎么做?酒店加盟连锁店如何招商?

还有人不知道&#xff0c;加盟连锁店该怎么做&#xff1f;酒店加盟连锁店如何招商&#xff1f; 想要创业的新人&#xff0c;一进到电商行业&#xff0c;看到繁杂的模式以及激烈的竞争关系&#xff0c;都没到平台亏钱的那一步&#xff0c;自己就先泄气了。一个企业能否发展起来&…

The Category-theoretic Perspective of Statistical Learning for Amateurs

统计学习.范畴论视角 title: The Category-theoretic Perspective of Statistical Learning for Amateurs author: Congwei Song description: A representation in BIMSA The Category-theoretical Perspective of Statistical Learning for Amateurs Congwei Song Email: …

基于SSM的疫苗接种平台

末尾获取源码 开发语言&#xff1a;Java Java开发工具&#xff1a;JDK1.8 后端框架&#xff1a;SSM 前端&#xff1a;Vue 数据库&#xff1a;MySQL5.7和Navicat管理工具结合 服务器&#xff1a;Tomcat8.5 开发软件&#xff1a;IDEA / Eclipse 是否Maven项目&#xff1a;是 目录…

抢先看!文档控件aspose.words 新版本23.05 有哪些亮点?

Aspose.Words是一种高级Word文档处理API&#xff0c;用于执行各种文档管理和操作任务。API支持生成&#xff0c;修改&#xff0c;转换&#xff0c;呈现和打印文档&#xff0c;而无需在跨平台应用程序中直接使用Microsoft Word。 Aspose API支持流行文件格式处理&#xff0c;并…

Flutter-布局(Layout)原理

1、约束、尺寸、位置 overrideWidget build(BuildContext context) {return Scaffold(body: LayoutBuilder(builder: (context, constraints) {print("body约束:" constraints.toString());return Container(color: Colors.black,width: 300,height: 300,child: L…

计算机中丢失vcomp140.dll解决方案,可以使用这个3种方法修复

vcomp140.dll是一个动态连接库文件&#xff0c;它是Microsoft Visual Studio 2015应用程序所必需的运行库文件之一。它在Visual C Redistributable for Visual Studio 2015包中提供&#xff0c;是用于支持Microsoft C/C OpenMP Runtime的库文件。计算机中丢失vcomp140.dll无法打…

LNMP网站框架搭建(编译安装)

目录 一、Nginx的工作原理 工作进程&#xff1a; 二、Nginx编译安装安装 三、mysql的编译安装 四、php的编译安装 验证PHP与nginx的是否连接 验证lnmp的是否搭建成功 五、部署 Discuz&#xff01;社区论坛 六、fpm参数优化 一、Nginx的工作原理 php-fpm.conf …

Redis数据类型之String——字符串、数值、bitmap

Redis数据类型之String——字符串、数值、bitmap 注意索引位置一般从左到右 0开始&#xff0c;叫正向索引。从右到左-1开始叫反向索引 字符串 字符串有很多操作set、get、append、setrange、getrange等&#xff0c;每个都有自己对应的用处 SET SET key value 设置指定 key …

单元测试系列:一、了解spring boot单元测试

一、java 单元测试框架 java当前主流的测试框架有两个&#xff1a;JUnit、TestNG。 1、两者相同点 使用annotation&#xff0c;且大部分annotation相同。都可以进行单元测试&#xff08;Unit test&#xff09;。都是针对Java测试的工具。 2、两者不同点 JUnit只能进行单元…

【Axure教程】大小图动态轮播

大小图动态轮播常用于展示多张图片&#xff0c;其中包含两种不同尺寸的图片。这种类型的轮播通常用于网站首页、产品展示、广告宣传等场景&#xff0c;提供更丰富的展示方式&#xff0c;吸引用户的注意力并提供更多信息。通过切换不同的图片&#xff0c;可以有效地传达多个内容…

采购异常支出怎么造成的?如何控制?

采购管理中的"异常支出 "是指在企业预定的支出规则之外进行的交易。虽然大多数大型采购都是与知名供应商合作&#xff0c;并直接通过采购团队的合同进行&#xff0c;但并不是所有的采购都是这样正式进行的&#xff0c;这可能会导致支出不明的问题。 什么原因造成异常…

15-创建Vue3.0工程

目录 1.使用 vue-cli 创建2.使用 vite 创建 1.使用 vue-cli 创建 官方文档&#xff1a;https://cli.vuejs.org/zh/guide/creating-a-project.html#vue-create ## 查看vue/cli版本&#xff0c;确保vue/cli版本在4.5.0以上 vue --version ## 安装或者升级你的vue/cli npm insta…

创建孔、缩放、复制和粘贴

创建孔 项目概况&#xff1a; 在本项目中&#xff0c;您将学习如何使用孔特征从另一个形状中去除材料。 在Tinkercad上查看整个项目 指示 将蓝色多边形形状拖动到工作平面上&#xff0c;并将其放置在以橙色勾勒的区域。 提示&#xff1a; 您可能需要向下滚动形状列表才能找到…

kendoUI中的Observable详解

kendoUI中的Observable方法 一、前言 Kendo UI是一个基于JavaScript的开源UI框架&#xff0c;它提供了一系列的UI组件和工具&#xff0c;包括表格、图表、表单、对话框等。Kendo UI中的Observable是一个非常重要的概念&#xff0c;它可以帮助我们更好地理解和使用Kendo UI。 …

如何把握住数字化时代的浪潮,数据要素是关键

随着美国、欧洲的数字、数据战略相继出现&#xff0c;这意味着数据在未来的价值已经不是什么秘密&#xff0c;而是对未来世界发展的共识。IDC曾经预测过到2025年中国产生的数据总量将会达到48.6ZB&#xff0c;占全球的27.8%。这就是在未来发展数据战略的底气&#xff0c;也标志…

二叉树详解:带你掌握二叉树

目录 前言1. 树型结构1. 1 树的概念1.2 树的特点1.3 树的相关术语 2. 二叉树&#xff08;binary tree&#xff09;2.1 二叉树的概念2.2 二叉树中的特殊树2.2.1 满二叉树2.2.2 完全二叉树 2.3 二叉树的性质 3. 二叉树的遍历3.1 前序遍历3.2 中序遍历3.3 后序遍历3.4 层序遍历 总…

基于matlab使用蒙特卡罗模拟生成雷达系统的接收机工作特性 (ROC) 曲线

一、前言 此示例说明如何使用蒙特卡罗模拟生成雷达系统的接收机工作特性 &#xff08;ROC&#xff09; 曲线。接收器工作特性决定了系统在目标不存在&#xff08;误报&#xff09;时抑制大杂散信号值时检测目标的能力。检测系统将通过将接收到的信号值与预设阈值进行比较来声明…

Angular学习笔记:environment.ts文件

本文是自己的学习笔记&#xff0c;主要参考资料如下。 - B站《Angular全套实战教程》&#xff0c;达内官方账号制作&#xff0c;https://www.bilibili.com/video/BV1i741157Fj?https://www.bilibili.com/video/BV1R54y1J75g/?p32&vd_sourceab2511a81f5c634b6416d4cc1067…