Question

Difficulty: MediumManaging Google Kubernetes Engine Resources

A DevOps engineer receives access to a newly provisioned Google Kubernetes Engine (GKE) Standard cluster named `analytics-cluster` located in the `us-east1-b` zone. When running `kubectl get nodes`, the command fails with an error indicating that connection to `localhost:8080` was refused because the local environment lacks cluster endpoint credentials. Which `gcloud` command must the engineer execute to generate the necessary `kubeconfig` entry and enable `kubectl` management?

  1. gcloud container clusters get-credentials analytics-cluster --zone us-east1-bAnswer
  2. B
    gcloud container clusters update analytics-cluster --enable-autoscaling --zone us-east1-b
  3. C
    gcloud iam service-accounts keys create credentials.json --iam-account [email protected]
  4. D
    kubectl config set-cluster analytics-cluster --server us-east1-b

Answer

The command `gcloud container clusters get-credentials analytics-cluster --zone us-east1-b` must be executed to populate the local `kubeconfig` file with the GKE cluster control plane endpoint and authentication credentials.
To manage a GKE cluster using `kubectl`, administrative credentials and endpoint IP information must be downloaded to the local environment. Running `gcloud container clusters get-credentials <cluster-name> --zone <zone>` obtains the cluster API server certificate and authentication token, updating `~/.kube/config` so `kubectl` can target the cluster.

Step-by-Step Solution

1
Identify the root cause of the `kubectl` connection failure.
The terminal error indicating connection to `localhost:8080` confirms that `kubectl` does not have an active context or valid cluster endpoint configured in `~/.kube/config`.
Without active cluster credentials, `kubectl` defaults to attempting a local API server connection.
2
Select the GKE utility command designed to update cluster access contexts.
`gcloud container clusters get-credentials` queries the GKE API for endpoint IP address and authentication certificates.
This command generates or updates entries in the user's `$HOME/.kube/config` file with proper authentication tokens.
3
Verify required parameters for single-zone GKE clusters.
Specifying `--zone us-east1-b` along with the cluster name `analytics-cluster` uniquely identifies the target cluster.
Zonal clusters require the target zone flag to resolve the correct cluster control plane.

Key Concept

GKE Cluster Credential Fetching via gcloud CLI
Rate this question