纠正Kubernetes集群中的Pod关闭

图片
在Kubernetes中正确关闭容器


(. . — ) Kubernetes-. , drain . , : pod’.


pod’


kubectl drain pod’ . , :


  • drain pod’ control plane. kubelet , pod’.
  • kubelet pod’ preStop
  • preStop , kubelet TERM pod’.
  • kubelet ( pod’, ; 30 ) , ( SIGKILL). preStop .

, preStop , “ ” . , , , TERM, , , , . , , TERM (, - ), preStop API, .


Nginx TERM, . preStop . resource lifecycle . lifecycle :


lifecycle:
 preStop:
   exec:
     command: [
       # Gracefully shutdown nginx
       "/usr/sbin/nginx", "-s", "quit"
     ]

, , SIGTERM Nginx /usr/sbin/nginx -s quit. , , Nginx pod, TERM noop ( — .).


Nginx. , Deployment :


---
apiVersion: apps/v1
kind: Deployment
metadata:
 name: nginx-deployment
 labels:
   app: nginx
spec:
 replicas: 2
 selector:
   matchLabels:
     app: nginx
 template:
   metadata:
     labels:
       app: nginx
   spec:
     containers:
     - name: nginx
       image: nginx:1.15
       ports:
       - containerPort: 80
       lifecycle:
         preStop:
           exec:
             command: [
               # Gracefully shutdown nginx
               "/usr/sbin/nginx", "-s", "quit"
             ]

pod’


pod’ Nginx , . , , , Nginx , .


, deployment. , , . . pod’.


图片


, Node 1. kubectl drain node-1, kubelet preStop, Nginx:


图片


nginx , . , nginx , , .


, . pod, . , , nginx :


图片


, nginx , pod’ drain:


图片


图片


, , pod’ , . , , .


? , , ? , pod’ , preStop , Service.


Kubernetes AWS , Gruntwork.io.


:



All Articles