Question

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

You have created a Google Kubernetes Engine (GKE) cluster named `demo-cluster` in zone `us-central1-a`. You open a terminal and run `kubectl get nodes`, but the command fails because your local authentication context is missing. Which `gcloud` command must you execute to update your kubeconfig file with credentials for this cluster?

  1. gcloud container clusters get-credentials demo-cluster --zone us-central1-aAnswer
  2. B
    gcloud config set container/cluster demo-cluster
  3. C
    gcloud container node-pools list --cluster demo-cluster --zone us-central1-a
  4. D
    gcloud compute instances list --zone us-central1-a

Answer

Execute `gcloud container clusters get-credentials demo-cluster --zone us-central1-a` to update the local kubeconfig context.
Executing `gcloud container clusters get-credentials demo-cluster --zone us-central1-a` downloads cluster credentials and updates the local `kubeconfig` file, allowing `kubectl` to interact with the GKE cluster.

Step-by-Step Solution

1
Identify the missing prerequisite for executing `kubectl` commands against a newly created GKE cluster.
Recognize that `kubectl` requires endpoint certificates and user credentials stored in the local `~/.kube/config` file.
Without proper kubeconfig context entries, `kubectl` cannot locate or authenticate against the GKE control plane.
2
Determine the appropriate `gcloud` command to retrieve and populate cluster credentials.
`gcloud container clusters get-credentials` fetches authentication tokens and writes the required context into `kubeconfig`.
This is the Google-recommended command for enabling local `kubectl` access to a GKE cluster.

Key Concept

Fetching GKE cluster credentials using gcloud to configure local kubectl context
Estimated Time:45s
Rate this question