
Answer-first summary for fast verification
Answer: Create the Deployment with a livenessProbe for the container that will fail if the container can't connect to the database. Configure a Prestop lifecycle handler that runs the shutdown script if the container is failing.
The correct approach is to use a livenessProbe to check database connectivity and a PreStop lifecycle handler for graceful shutdown. The livenessProbe continuously verifies if the container can connect to the database. If it fails, Kubernetes triggers a restart. Before termination, the PreStop hook executes the shutdown script, ensuring a graceful exit. Option C's PostStart is a one-time check at startup, not ongoing. Option D's initContainer only checks during initialization, not runtime. Option A uses Jobs, which are unrelated to the pod lifecycle. Thus, option B is correct.
Author: LeetQuiz Editorial Team
Ultimate access to all questions.
No comments yet.
How should you configure a Deployment in Google Kubernetes Engine (GKE) to include a database connection check and ensure a graceful shutdown with a container script if the connection fails?
(Optionally include a corrected code block if the original contained syntax errors or typos related to liveness/readiness probes or lifecycle hooks.)
A
Create two jobs: one that checks whether the container can connect to the database, and another that runs the shutdown script if the Pod is failing.
B
Create the Deployment with a livenessProbe for the container that will fail if the container can't connect to the database. Configure a Prestop lifecycle handler that runs the shutdown script if the container is failing.
C
Create the Deployment with a PostStart lifecycle handler that checks the service availability. Configure a PreStop lifecycle handler that runs the shutdown script if the container is failing.
D
Create the Deployment with an initContainer that checks the service availability. Configure a Prestop lifecycle handler that runs the shutdown script if the Pod is failing.