容器生命周期配置

发布时间 2023-07-03 21:21:02作者: MhaiM

1、容器启动命令

spec:
    affinity: {}
    containers:
    -  args:
        - while true; do echo hello; sleep 10; done
        command:
        - /bin/sh
        - -c
        image: nginx:latest
        imagePullPolicy: IfNotPresent
        name: nginx

2、启动后处理

spec:
    affinity: {}
    containers:
    - image: nginx:latest
      imagePullPolicy: IfNotPresent
      lifecycle:
      postStart:
          exec:
              command:
              - /bin/sh
              - -c
              - apt-get update && apt-get install curl
      name: nginx

3、停止前处理

spec:
     affinity: {}
     containers:
     -   image: nginx:latest
         imagePullPolicy: IfNotPresent
         lifecycle:
           preStop:
              exec:
                  command:
                  - /bin/sh
                  - -c
                  - wait-shutdown
         name: nginx