pod 容器下線前做些生命周期的操作,如服務從注冊中心下線
1.我們可以寫一些下線的腳本如:(postop.sh)
#!/bin/bash #先從注冊中心下線 curl http://127.0.0.1:9010/server/deregister sleep 20 #睡眠20s,調用springboot優雅關機接口 curl -X POST http://127.0.0.1:9010/actuator/supper-shutdown
在項目打包成鏡像時,將該文件打包到鏡像中,也就是Dockerfile打包鏡像時

2.在部署項目的yaml生命周期上,調用該腳本

spec: imagePullSecrets: - name: aliyuncs-docker-hub #提前在項目下配置訪問阿里云的賬號密碼 containers: - image: $REGISTRY/$DOCKERHUB_NAMESPACE/$APP_NAME:SNAPSHOT-$BUILD_NUMBER # readinessProbe: # httpGet: # path: /actuator/health # port: 8080 # timeoutSeconds: 10 # failureThreshold: 30 # periodSeconds: 5 imagePullPolicy: Always name: app ports: - containerPort: 8080 protocol: TCP resources: limits: cpu: 300m memory: 600Mi lifecycle: preStop: exec: command: ["sh","-c","/app/postop.sh"] #set prestop terminationMessagePath: /dev/termination-log terminationMessagePolicy: File dnsPolicy: ClusterFirst restartPolicy: Always terminationGracePeriodSeconds: 30

浙公網安備 33010602011771號