Question

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

A cloud administrator recently created a new Google Kubernetes Engine (GKE) cluster named `analytics-cluster` in the `us-east1` region. When attempting to run `kubectl get pods` from their local workstation terminal, the command fails because `kubectl` is not configured to communicate with the cluster. Which command must the administrator execute to fetch the cluster credentials and automatically update their local `kubeconfig` file?

  1. gcloud container clusters get-credentials analytics-cluster --region us-east1Answer
  2. B
    gcloud config set container/cluster analytics-cluster
  3. C
    gcloud container clusters create analytics-cluster --enable-autopilot --region us-east1
  4. D
    gcloud compute instances create analytics-node --spot

Answer

The command 'gcloud container clusters get-credentials analytics-cluster --region us-east1' is correct because it populates the local kubeconfig file with the necessary API endpoint and authentication credentials required by kubectl.
Executing 'gcloud container clusters get-credentials' retrieves the API endpoint and authentication tokens for the cluster and updates the local kubeconfig configuration file, allowing kubectl commands to succeed.

Step-by-Step Solution

1
Identify the requirement to connect a local kubectl client to an existing GKE cluster.
Recognize that kubectl requires valid API credentials and context entries in the local kubeconfig file.
Creating a cluster in GKE does not automatically configure remote developer workstations.
2
Select the correct gcloud CLI command for fetching Kubernetes credentials.
Use 'gcloud container clusters get-credentials' specifying the cluster name and region/zone.
This command generates the certificate/token entries and sets the current context for kubectl.

Key Concept

Fetching GKE cluster credentials for kubectl management
Estimated Time:45s
Rate this question