Google Professional Cloud DevOps Engineer Question 21
Select 3Google Cloud PlatformYou are a DevOps Engineer managing a Google Cloud environment. Your team frequently deploys a Kubernetes application to Google Kubernetes Engine (GKE) and wants to automate the deployment process using a Python script. The script should authenticate to Google Cloud, build a Docker image, push the image to Google Container Registry (GCR), and deploy the updated image to the GKE cluster. Which of the following steps should be included in your Python script to ensure a complete and automated deployment process?
- A
Use the Google Cloud SDK Python client library to authenticate using a service account key file.
- B
Build the Docker image using Python's subprocess module to invoke the 'docker build' command.
- C
Push the Docker image to Google Container Registry (GCR) using Python's GCR client library.
- D
Update the Kubernetes deployment to use the new image by modifying the deployment YAML file and applying it using the Kubernetes Python client library.
- E
Manually authenticate to GKE using the 'gcloud container clusters get-credentials' command before running the script.
Show answer and explanation
Correct answers: A, B, D
Explanation
To automate the deployment process, the Python script should handle authentication, Docker image building, and Kubernetes deployment updates programmatically. Using the Google Cloud SDK for authentication, subprocess to build the image, and the Kubernetes Python client library for deployment updates ensures the process is fully automated and reliable. Manual steps, such as authenticating to GKE outside the script, should be avoided to maintain end-to-end automation.
- A. Correct.
This is correct. Authenticating using Google Cloud SDK and a service account key file ensures secure and automated access to Google Cloud resources.
- B. Correct.
This is correct. Using Python's subprocess module to invoke the 'docker build' command is a common way to build Docker images programmatically.
- C. Incorrect.
This is incorrect. There is no Python-specific client library for GCR. The image can be pushed using 'docker push' or by invoking the Google Cloud SDK commands via subprocess.
- D. Correct.
This is correct. Automating the deployment update by modifying the YAML and applying it programmatically ensures the process can run without manual intervention.
- E. Incorrect.
This is incorrect. Manually authenticating to GKE defeats the purpose of automation. The script should handle authentication programmatically.