Middle+
Millised tegurid tagavad sõlme õige lõpetamise sõltuvalt pordi prioriteedist?
sobes.tech AI
Vastus AI-lt
Correct node shutdown is achieved through the following factors:
- Timeouts:
terminationGracePeriodSeconds: Defines the time during which the node will attempt to gracefully terminate pod operations before forcefully destroying them. Default is 30 seconds.pod.spec.terminationGracePeriodSeconds: Can override the timeout for a specific pod.
# Example pod manifest with extended termination timeout apiVersion: v1 kind: Pod metadata: name: my-pod-with-grace-period spec: containers: - name: my-container image: my-image terminationGracePeriodSeconds: 60 # Extended timeout - Signals:
- Kubernetes sends a
SIGTERMsignal to the pod's containers. - The application inside the container should be able to catch
SIGTERMand handle it properly (e.g., close current connections, save state). - If the application does not terminate upon
SIGTERMwithinterminationGracePeriodSeconds, aSIGKILLis sent.
- Kubernetes sends a
- Pod priority (
priorityClassName):- During preemption (e.g., resource shortage or node eviction), lower priority pods are terminated first.
- This ensures that critical (high-priority) pods run longer and have more time to terminate properly if the node becomes unavailable.
# Example pod manifest with priority class apiVersion: v1 kind: Pod metadata: name: my-priority-pod spec: containers: - name: my-container image: my-image priorityClassName: high-priority # Using priority class - PreStop hooks:
- Additional scripts or calls executed inside the container just before
SIGTERMis sent. - Can be used for synchronization, deregistration from services, or other tasks needed for proper shutdown.
# Example PreStop hook apiVersion: v1 kind: Pod metadata: name: my-pod-with-prestop spec: containers: - name: my-container image: my-image lifecycle: preStop: exec: command: ["/bin/sh", "-c", "echo 'Stopping container...' && sleep 5 && exit 0"] # Example command - Additional scripts or calls executed inside the container just before
- Endpoint management:
- Kubernetes removes the pod's IP from the Endpoints object at the start of shutdown so that new traffic is not directed to the terminating pod.
- This allows existing connections to finish during the grace period.
Together, these mechanisms enable Kubernetes to manage the pod termination process on the node, considering their priority, and give them a chance to terminate properly, avoiding forced destruction where possible.