Updated on 2023-02-07 GMT+08:00

Lifecycle Management

Based on Kubernetes, CCI provides containers with lifecycle hooks. The hooks enable containers to run code triggered by events during their management lifecycle. For example, if you want a container to perform a certain operation before it is stopped, you can register a hook. The following lifecycle hooks are provided:

  • Post-Start Processing: triggered immediately after the workload is started
  • Pre-Stop Processing: triggered immediately before the workload is stopped

When calling an API, you only need to set the lifecycle.postStart or lifecycle.preStop parameter of the pod, as shown in the following:

apiVersion: v1
kind: Pod
metadata:
  name: nginx
spec:
  containers:
  - image: nginx:latest
    name: container-0
    resources:
      limits:
        cpu: 500m
        memory: 1024Mi
      requests:
        cpu: 500m
        memory: 1024Mi
    lifecycle:
      postStart:                 # Post-start processing
        exec:
          command:
          - "/postStart.sh"
      preStop:                   # Pre-stop processing
        exec:
          command:
          - "/preStop.sh"
  imagePullSecrets:
  - name: imagepull-secret