A DevOps engineer creates a new Google Kubernetes Engine (GKE) cluster named `prod-cluster` in the `us-central1` region. From a newly provisioned administrator workstation, the engineer attempts to deploy a application workload using `kubectl apply -f deployment.yaml`. However, the command fails with an error indicating that the connection to server `localhost:8080` was refused. Which action should the engineer take to allow `kubectl` to successfully communicate with the GKE cluster?
- Execute `gcloud container clusters get-credentials prod-cluster --region us-central1` to update the local kubeconfig file with cluster entry details and authentication credentials.Answer
- BExecute `gcloud config set container/cluster prod-cluster` to register the default cluster target in the gcloud configuration settings.
- CRecreate the cluster as a GKE Autopilot cluster because Standard clusters require starting a local API proxy daemon before running kubectl commands.
- DModify the deployment manifest to specify Spot VMs using node selectors so that kubectl can automatically locate available compute nodes.
Answer
Execute `gcloud container clusters get-credentials prod-cluster --region us-central1` to retrieve the cluster kubeconfig credentials.
The option directing the user to run `gcloud container clusters get-credentials prod-cluster --region us-central1` is correct because `kubectl` relies on the local `kubeconfig` file to locate and authenticate against the GKE API server endpoint. Fetching credentials via `gcloud` writes the necessary context and authorization tokens to `kubeconfig`.
Step-by-Step Solution
Key Concept
Configuring kubectl credentials for GKE cluster management using gcloud