A DevOps engineer is preparing to deploy an updated microservice manifest file (`deployment.yaml`) to an existing GKE cluster named `prod-cluster` located in region `us-central1`. When attempting to run `kubectl apply -f deployment.yaml` from a newly provisioned management terminal, the command fails because `kubectl` is not configured to communicate with the cluster's control plane endpoint. Which command sequence should the engineer execute to successfully authenticate `kubectl` and deploy the workload?
- Execute `gcloud container clusters get-credentials prod-cluster --region us-central1`, and then execute `kubectl apply -f deployment.yaml`.Answer
- BExecute `gcloud config set container/cluster prod-cluster` and `gcloud config set compute/region us-central1`, and then execute `kubectl apply -f deployment.yaml`.
- CExecute `gcloud container clusters create-auto prod-cluster --region us-central1`, and then execute `kubectl apply -f deployment.yaml`.
- DExecute `gcloud container node-pools create spot-pool --cluster=prod-cluster --region=us-central1 --spot`, and then execute `kubectl apply -f deployment.yaml --node-pool=spot-pool`.
Answer
Execute `gcloud container clusters get-credentials prod-cluster --region us-central1` to populate the local kubeconfig context, followed by `kubectl apply -f deployment.yaml`.
To interact with a GKE cluster via `kubectl`, the client must have an active context in the local kubeconfig file containing the control plane API server address and authorization credentials. Running `gcloud container clusters get-credentials prod-cluster --region us-central1` retrieves this data from Google Cloud and updates the local `.kube/config` file, enabling `kubectl apply` to succeed.
Step-by-Step Solution
Key Concept
Configuring kubectl authentication context using gcloud container clusters get-credentials