image.png

    image.png

    Adding preStopHook 优雅关闭容器
    image.png
    terminationGracePeriodSeconds: 45

    Kubernetes yamlfile

    1. apiVersion: apps/v1
    2. kind: Deployment
    3. metadata:
    4. name: gracefulshutdown-app
    5. spec:
    6. replicas: 3
    7. selector:
    8. matchLabels:
    9. app: gracefulshutdown-app
    10. template:
    11. metadata:
    12. labels:
    13. app: gracefulshutdown-app
    14. spec:
    15. containers:
    16. - name: graceful-shutdown-test
    17. image: gracefulshutdown-app:latest
    18. ports:
    19. - containerPort: 8080
    20. lifecycle:
    21. preStop:
    22. exec:
    23. command: ["sh", "-c", "sleep 10"] #set prestop hook
    24. terminationGracePeriodSeconds: 45 # terminationGracePeriodSeconds

    https://yashwanth-nimmala.medium.com/kubernetes-graceful-shutdown-73bb23af2abd