![Bild](https://habrastorage.org/getpro/habr/post_images/756/381/101/7563811010ba5a50e8106ea56c5577c1.png)
Ordnungsgemäßes Herunterfahren von Containern in 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’.
![Bild](https://habrastorage.org/getpro/habr/post_images/246/28c/61c/24628c61cd1ecbd753494266e1bb3206.png)
, Node 1. kubectl drain node-1
, kubelet
preStop
, Nginx:
![Bild](https://habrastorage.org/getpro/habr/post_images/e7d/9f1/fcb/e7d9f1fcb365b23407f7d4525098b4be.png)
nginx , . , nginx , , .
, . pod, . , , nginx :
![Bild](https://habrastorage.org/getpro/habr/post_images/833/8d8/2d5/8338d82d59548c68a4be36313f706fa6.png)
, nginx , pod’ drain
:
![Bild](https://habrastorage.org/getpro/habr/post_images/79b/d03/4cc/79bd034cc7c41f175de82eaffe4a17fb.png)
![Bild](https://habrastorage.org/getpro/habr/post_images/d1f/07f/648/d1f07f6483efa36300f788c47bbfd963.png)
, , pod’ , . , , .
? , , ? , pod’ , preStop
, Service
.
Kubernetes AWS , Gruntwork.io.
: