Lifecycle Hook
İki tane lifecycle hook var. Açıklaması şöylePostStart: This hook is executed right after a container is created. However, the hook might be invoked after the container's ENTRYPOINT is executed. The hook handler must not accept any parameters.PreStop: This hook is executed immediately before a container is terminated due to any reason, such as resource contention, liveness probe failure, etc. You cannot pass any parameters to the handler, and the container will be terminated irrespective of the outcome of the handler.
Lifecycle Hook Handlers
Hook'a iki çeşit handler takabiliriz. Açıklaması şöyle
There are two types of handlers that you can attach to a lifecycle hook:
exec: It executes the specified command in the container's main process. The command is executed in parallel with the container's ENTRYPOINT instruction. If the hook takes too long or fails, the kubelet process will restart the container.httpGet or tcpSocket: It sends an HTTP request or establishes a TCP socket connection against a specific endpoint on the container. Unlike the exec, which is executed by the container, this handler is executed by the kubelet process.
Örnek - postStart
Örnek - preStopŞöyle yaparız
apiVersion: v1
kind: Pod
metadata:
name: sidecar-container-demo
spec:
containers:
- image: busybox
command: ["/bin/sh"]
args:
[
"-c",
"while true; do echo echo $(date -u) 'Written by busybox sidecar container' >> /var/log/index.html; sleep 5;done",
]
name: sidecar-container
resources: {}
volumeMounts:
- name: var-logs
mountPath: /var/log
lifecycle:
postStart:
httpGet:
path: /index.html
port: 80
host: localhost
scheme: HTTP
- image: nginx
name: main-container
resources: {}
ports:
- containerPort: 80
volumeMounts:
- name: var-logs
mountPath: /usr/share/nginx/html
dnsPolicy: Default
volumes:
- name: var-logs
emptyDir: {}Şöyle yaparız
apiVersion: v1kind: Podmetadata:name: prestop-demospec:containers:- image: nginxname: nginx-containerresources: {}ports:- containerPort: 80lifecycle:preStop:exec:command:- sh- -c- echo "Stopping container now...">/proc/1/fd/1 && nginx -s stopdnsPolicy: Default
Hiç yorum yok:
Yorum Gönder