You are deploying a new stateless microservice to an existing Google Kubernetes Engine (GKE) cluster named `prod-app-cluster` located in zone `us-central1-a`. You have authorized the `gcloud` CLI on a new developer workstation with appropriate IAM permissions for the target Google Cloud project. However, when you attempt to execute `kubectl apply -f deployment.yaml`, the command fails with an error stating `The connection to the server localhost:8080 was refused`. Which command should you execute to enable `kubectl` to communicate with the GKE cluster?
- Run `gcloud container clusters get-credentials prod-app-cluster --zone us-central1-a` to update the local kubeconfig file with cluster authentication details and endpoint information.Cevap
- BRun `gcloud config set container/cluster prod-app-cluster` to bind the default cluster property in gcloud settings.
- CRecreate the cluster as a GKE Autopilot cluster, because GKE Standard clusters do not allow external `kubectl` access without setting up an SSH tunnel to a node.
- DAppend the `--enable-spot` flag to the `kubectl apply -f deployment.yaml` command to automatically target available Spot VM nodes.
Cevap
Execute `gcloud container clusters get-credentials prod-app-cluster --zone us-central1-a` to retrieve cluster entry points and credentials into the local environment.
Executing `gcloud container clusters get-credentials prod-app-cluster --zone us-central1-a` writes the cluster endpoint and authentication credentials into the client's `kubeconfig` file (`~/.kube/config`). This step configures `kubectl` with the correct control plane address and token necessary to deploy workloads to GKE.
Adım Adım Çözüm
Anahtar Kavram
Fetching GKE Cluster Credentials for kubectl authentication