Soru

Zorluk: ZorDeploying and Managing Google Kubernetes Engine (GKE) Clusters and Workloads

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?

  1. 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
  2. B
    Run `gcloud config set container/cluster prod-app-cluster` to bind the default cluster property in gcloud settings.
  3. C
    Recreate 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.
  4. D
    Append 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

1
Identify the root cause of the `localhost:8080 connection refused` error.
Recognize that `kubectl` defaults to `localhost:8080` when no cluster context or credentials are configured in `~/.kube/config`.
`kubectl` requires cluster endpoint address and valid authentication tokens to communicate with the GKE control plane.
2
Select the Google Cloud command designed to generate `kubeconfig` authentication settings.
Use `gcloud container clusters get-credentials` with the cluster name and region/zone flags.
This command securely retrieves the cluster's CA certificate, API endpoint, and generates an authentication token for the active GCP account.
3
Verify execution workflow.
Once `kubeconfig` is updated, `kubectl apply -f deployment.yaml` successfully targets the control plane of `prod-app-cluster`.
The local context is set as current, enabling seamless Kubernetes API requests.

Anahtar Kavram

Fetching GKE Cluster Credentials for kubectl authentication
Bu soruyu puanla