Sobes.tech
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:

  1. 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
    
  2. Signals:
    • Kubernetes sends a SIGTERM signal to the pod's containers.
    • The application inside the container should be able to catch SIGTERM and handle it properly (e.g., close current connections, save state).
    • If the application does not terminate upon SIGTERM within terminationGracePeriodSeconds, a SIGKILL is sent.
  3. 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
    
  4. PreStop hooks:
    • Additional scripts or calls executed inside the container just before SIGTERM is 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
    
  5. 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.