Question

Difficulty: EasyManaging Google Kubernetes Engine Resources

A cloud administrator needs to configure their local terminal environment to manage an existing Google Kubernetes Engine (GKE) cluster named `prod-cluster` located in zone `us-central1-a` using `kubectl`. Which command should the administrator run to fetch cluster credentials and update the local `kubeconfig` file?

  1. gcloud container clusters get-credentials prod-cluster --zone us-central1-aAnswer
  2. B
    kubectl config set-cluster prod-cluster --zone us-central1-a
  3. C
    gcloud container clusters describe prod-cluster --zone us-central1-a
  4. D
    gcloud iam service-accounts keys create cluster-key.json --iam-account [email protected]

Answer

The command `gcloud container clusters get-credentials prod-cluster --zone us-central1-a` is the standard tool used to populate the local `kubeconfig` file with cluster endpoint details and authentication tokens.
To manage a GKE cluster with `kubectl`, the administrator must retrieve the cluster's endpoint and authentication credentials using `gcloud container clusters get-credentials <cluster-name> --zone <zone>`. This updates the local `kubeconfig` entry automatically.

Step-by-Step Solution

1
Identify the target GKE cluster name and location.
Cluster name is `prod-cluster` located in zone `us-central1-a`.
GKE requires location flags (--zone or --region) to locate specific regional or zonal clusters.
2
Use the Google Cloud CLI `container clusters get-credentials` command.
The local `~/.kube/config` file is generated or updated with context, cluster endpoints, and OAuth credentials.
This bridges GCP IAM permissions with Kubernetes RBAC so `kubectl` CLI commands can authenticate.

Key Concept

Fetching GKE cluster credentials for kubectl authentication
Rate this question