Question

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

A cloud engineer attempts to deploy an updated Kubernetes Deployment manifest to an existing GKE cluster named `inventory-cluster` in zone `us-central1-a` by running `kubectl apply -f deployment.yaml`. The command fails with an error stating `The connection to the server localhost:8080 was refused`, indicating that local command-line tools are not configured to communicate with the GKE control plane. Which command should the engineer execute to correctly fetch cluster credentials and configure the local `kubeconfig` context?

  1. gcloud container clusters get-credentials inventory-cluster --zone us-central1-aAnswer
  2. B
    gcloud config set container/cluster inventory-cluster
  3. C
    gcloud container clusters update inventory-cluster --enable-autoscaling --min-nodes 1 --max-nodes 5 --zone us-central1-a
  4. D
    gcloud container node-pools create spot-pool --cluster inventory-cluster --spot --zone us-central1-a

Answer

The cloud engineer should execute `gcloud container clusters get-credentials inventory-cluster --zone us-central1-a` to populate the local kubeconfig context with the cluster endpoint and credentials.
Running `gcloud container clusters get-credentials` retrieves authentication credentials and cluster endpoint details from Google Kubernetes Engine and writes them to the local `kubeconfig` configuration file, allowing `kubectl` to successfully communicate with the control plane.

Step-by-Step Solution

1
Identify the root cause of the kubectl connection failure.
The error `localhost:8080 was refused` shows that `kubectl` lacks valid endpoint details and credentials for the target GKE cluster, defaulting to a non-existent local server.
Before `kubectl` can communicate with a GKE cluster control plane, credentials and context must be generated locally.
2
Determine the appropriate command to populate kubeconfig.
`gcloud container clusters get-credentials` fetches cluster certificates, API server endpoints, and authentication context.
This command writes the necessary cluster configuration directly into `~/.kube/config`, directing `kubectl` commands to the remote GKE cluster.

Key Concept

Fetching GKE cluster credentials to configure local kubectl context
Rate this question