云容器实例 CCI-生命周期管理

时间:2025-02-12 14:55:26

生命周期管理

云容器实例基于Kubernetes,提供了容器生命周期钩子,在容器的生命周期的特定阶段执行调用,比如容器在停止前希望执行某项操作,就可以注册相应的钩子函数。目前提供的生命周期钩子函数如下所示。

  • 启动后处理(PostStart):负载启动后触发。
  • 停止前处理(PreStop):负载停止前触发。

调用接口时,只需配置pod的lifecycle.postStart或lifecycle.preStop参数,如下所示。

apiVersion: v1kind: Podmetadata:  name: nginxspec:  containers:  - image: nginx:latest    name: container-0    resources:      limits:        cpu: 500m        memory: 1024Mi      requests:        cpu: 500m        memory: 1024Mi    lifecycle:      postStart:                 # 启动后处理        exec:          command:          - "/postStart.sh"      preStop:                   # 停止前处理        exec:          command:          - "/preStop.sh"  imagePullSecrets:  - name: imagepull-secret
support.huaweicloud.com/devg-cci/cci_05_0012.html