Question

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

A cloud administrator receives a newly provisioned workstation and installs `kubectl` to manage an existing regional Google Kubernetes Engine (GKE) cluster named `ecommerce-prod` located in the `us-east4` region. When running `kubectl get pods`, the command fails with an error stating `The connection to the server localhost:8080 was refused`. Which `gcloud` command must the administrator execute to populate the local kubeconfig file with cluster context credentials?

  1. gcloud container clusters get-credentials ecommerce-prod --region us-east4Answer
  2. B
    gcloud config set container/cluster ecommerce-prod
  3. C
    gcloud container clusters update ecommerce-prod --enable-autopilot --region us-east4
  4. D
    gcloud container node-pools create spot-pool --cluster=ecommerce-prod --spot --region us-east4

Answer

Execute `gcloud container clusters get-credentials ecommerce-prod --region us-east4` to generate the necessary cluster endpoint entries and authentication tokens in the local kubeconfig file.
Running `gcloud container clusters get-credentials` fetches the control plane certificates and generates an entry in the local `~/.kube/config` file. This configures `kubectl` with the correct cluster API server address and credentials required to perform operations against the target GKE cluster.

Step-by-Step Solution

1
Identify the root cause of the `localhost:8080` connection error.
Recognize that `kubectl` defaults to `localhost:8080` when no active GKE cluster context or API server endpoint exists in the local `~/.kube/config` configuration file.
Before executing cluster commands, `kubectl` must know the control plane IP address and present valid IAM/OAuth credentials.
2
Select the correct Google Cloud CLI command to fetch cluster credentials.
Use `gcloud container clusters get-credentials` with the cluster name and region parameters.
This command fetches the cluster's API endpoint and CA certificate, generates an authentication token, and registers the context entry in `~/.kube/config`.

Key Concept

GKE Kubeconfig Authentication & Context Provisioning
Estimated Time:1m 30s
Rate this question