Question

Difficulty: MediumDeploying and Managing Google Kubernetes Engine (GKE) Clusters and Workloads

A Cloud Engineer needs to provision a new Google Kubernetes Engine (GKE) cluster in zone `us-central1-a` named `web-cluster`, configure local command-line access, and deploy an application defined in a local file named `web-deployment.yaml`. In which sequence should the engineer execute the following commands to successfully deploy and verify the workload?

  1. 1`gcloud container clusters create web-cluster --zone us-central1-a`
  2. 2`gcloud container clusters get-credentials web-cluster --zone us-central1-a`
  3. 3`kubectl apply -f web-deployment.yaml`
  4. 4`kubectl get pods`

Answer

The correct operational sequence is: 1) Create the GKE cluster using `gcloud container clusters create`, 2) Generate local authentication credentials with `gcloud container clusters get-credentials`, 3) Deploy the workload manifest using `kubectl apply -f web-deployment.yaml`, and 4) Verify pod status using `kubectl get pods`.
The correct operational order follows the logical deployment lifecycle in GCP: first create the cluster infrastructure (`gcloud container clusters create`), then obtain API cluster credentials and configure local context (`gcloud container clusters get-credentials`), next apply the workload deployment manifest (`kubectl apply -f`), and finally verify that the pods are running correctly (`kubectl get pods`).

Step-by-Step Solution

1
Provision the GKE cluster control plane and worker nodes.
The GKE cluster `web-cluster` becomes active and accessible in the target Google Cloud zone.
You cannot retrieve credentials or apply Kubernetes manifests without an active running cluster.
2
Execute `gcloud container clusters get-credentials` for the cluster.
The local `~/.kube/config` file is populated with entry endpoints and auth tokens for `web-cluster`.
`kubectl` requires local authentication parameters and cluster endpoints to communicate with the GKE control plane API.
3
Execute `kubectl apply -f web-deployment.yaml`.
Kubernetes API creates the specified Deployment object and starts scheduling Pods.
Manifests can only be applied after `kubectl` has a valid active context pointing to the target cluster.
4
Execute `kubectl get pods` to verify execution.
Returns the status (e.g., Running) of the newly spawned application pods.
Checking resource status confirms whether image pulling, scheduling, and pod startup succeeded.

Key Concept

GKE Cluster Deployment and Administration Lifecycle
Rate this question