Workload HA

General Principles of Application High Availability

  • Applications adhere to The Twelve-Factor App

  • Employ Services and deploy applications with multiple replica Pods

  • Multiple replicas use anti-affinity to avoid application failure due to single node faults

  • Utilize PodDisruptionBudget to prevent application downtime resulting from evictions

  • Use preStopHook and health check probes to ensure smooth service updates

Graceful Shutdown

Configure terminationGracePeriodSeconds for Pods and use a preStop hook to delay the shutting down of container applications to avoid application interruptions during events such as kubectl drain:

restartPolicy: Always
terminationGracePeriodSeconds: 30
containers:
- image: nginx
  lifecycle:
    preStop:
      exec:
        command: [
          "sh", "-c",
          # Introduce a delay to the shutdown sequence to wait for the
          # pod eviction event to propagate. Then, gracefully shutdown
          # nginx.
          "sleep 5 && /usr/sbin/nginx -s quit",
        ]

For the detailed principle, you can refer to the following series of articles:

Reference Documents


Ensuring that your apps never miss a beat, even while you update your digital orchestra, is what high availability is all about. Let's consider the finely-tuned best practices:

  • Treat your applications to the modern methodology of The Twelve-Factor App, ensuring they're as resilient as they are refined.

  • Set up your software symphony using Services and a chorus of multiple replica Pods, each singing the same tune.

  • Should one Pod face the music alone, anti-affinity keeps the performance going by avoiding single node failures that hit a sour note.

  • Employ PodDisruptionBudget like a metronome, keeping rhythm and preventing evictions from throwing you off-beat.

  • PreStopHook and health check probes act like the meticulous conductor, guaranteeing each transition is as smooth as the last.

When it's time for a swan song, here's how you can bring the curtain down on your Pods with elegance and poise:

Set the stage with terminationGracePeriodSeconds and cue the preStop hook to dim the lights gently. This way, when the crowd gets rowdy with kubectl drain commands, your application can exit stage left without dropping a line.

restartPolicy: Always
terminationGracePeriodSeconds: 30
containers:
- image: nginx
  lifecycle:
    preStop:
      exec:
        command: [
          "sh", "-c",
          # This little intermission gives your Pods time to pass the news
          # of their departure. Then, like the grand finale of a symphony,
          # Nginx takes a graceful bow.
          "sleep 5 && /usr/sbin/nginx -s quit",
        ]

Intrigued by the mechanics behind the show? Curtain up! Peek behind the scenes with this enlightening series of articles:

  • Enlightening Series 1: No intermissions in your server performance.

  • Graceful Series 2: Pods that know how to exit the stage properly.

  • Timely Series 3: Ensuring every Pod gets the memo before the lights go out.

  • Safeguarding Series 4: Keep the show going, no matter what happens offstage.

For the theory and technical know-how that underpins your application's resilience, sift through these reference documents:

最后更新于