Question

Difficulty: MediumManaging Google Kubernetes Engine Resources

An infrastructure engineer needs to grant local administrative tools access to a newly created Google Kubernetes Engine (GKE) cluster named `analytics-prod` located in the `us-central1` region. When attempting to execute `kubectl get nodes`, the command fails with a connection refused error because local context credentials are missing. Which command should the engineer run to populate kubeconfig with the required cluster credentials?

  1. gcloud container clusters get-credentials analytics-prod --region us-central1Answer
  2. B
    kubectl config set-cluster analytics-prod --server=https://us-central1-gke.cloud.google.com
  3. C
    gcloud container node-pools update analytics-prod --enable-autoscaling --region us-central1
  4. D
    gcloud container clusters update analytics-prod --enable-autopilot --region us-central1

Answer

The command `gcloud container clusters get-credentials analytics-prod --region us-central1` updates the local kubeconfig file with endpoint details and authentication credentials required by kubectl.
Executing `gcloud container clusters get-credentials analytics-prod --region us-central1` automatically downloads the endpoint information and authentication token helper for the specified cluster, appending or updating the context in the local `kubeconfig` file.

Step-by-Step Solution

1
Identify the requirement to configure local cluster context for kubectl.
Recognize that gcloud CLI manages GKE cluster authentication entry generation.
Directly running `kubectl` without cluster credentials in kubeconfig results in endpoint connection failures.
2
Select the correct gcloud container command and location flags.
`gcloud container clusters get-credentials analytics-prod --region us-central1` writes authentication context into `~/.kube/config`.
Specifying the cluster name and region ensures the correct control plane API endpoint is targeted.

Key Concept

Configuring kubectl credentials for GKE cluster management using gcloud CLI.
Estimated Time:1m 30s
Rate this question