nerdexam
Google

PROFESSIONAL-CLOUD-DEVELOPER · Question #254

You noticed that your application was forcefully shut down during a Deployment update in Google Kubernetes Engine. Your application didn't close the database connection before it was terminated. You…

The correct answer is A. Update your code to process a received SIGTERM signal to gracefully disconnect from the. When Kubernetes terminates a pod, it first sends a SIGTERM signal to the container process, then waits for the terminationGracePeriodSeconds duration before sending SIGKILL. The correct fix is to instrument the application to catch SIGTERM and, upon receiving it, finish…

Manage application reliability

Question

You noticed that your application was forcefully shut down during a Deployment update in Google Kubernetes Engine. Your application didn't close the database connection before it was terminated. You want to update your application to make sure that it completes a graceful shutdown. What should you do?

Options

  • AUpdate your code to process a received SIGTERM signal to gracefully disconnect from the
  • BConfigure a PodDisruptionBudget to prevent the Pod from being forcefully shut down.
  • CIncrease the terminationGracePeriodSeconds for your application.
  • DConfigure a PreStop hook to shut down your application.

How the community answered

(39 responses)
  • A
    82% (32)
  • B
    3% (1)
  • C
    5% (2)
  • D
    10% (4)

Explanation

When Kubernetes terminates a pod, it first sends a SIGTERM signal to the container process, then waits for the terminationGracePeriodSeconds duration before sending SIGKILL. The correct fix is to instrument the application to catch SIGTERM and, upon receiving it, finish in-flight requests, close database connections, and then exit cleanly. This is the idiomatic container shutdown pattern. Option B (PodDisruptionBudget) controls the minimum number of available pods during voluntary disruptions; it does not affect how a single pod shuts down. Option C (increasing terminationGracePeriodSeconds) gives the pod more time to die but does nothing if the code never handles the signal - the connection will still be dropped forcefully at SIGKILL. Option D (PreStop hook) executes a command or HTTP call before the SIGTERM is sent; it can add a delay but does not directly close the database connection the way in-process signal handling does.

Topics

#Graceful Shutdown#Kubernetes Pod Lifecycle#SIGTERM#Application Resilience

Community Discussion

No community discussion yet for this question.

Full PROFESSIONAL-CLOUD-DEVELOPER Practice