Soru

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

A DevOps team has provisioned a new regional Google Kubernetes Engine (GKE) cluster named `app-prod-cluster` in the `us-central1` region. A cloud engineer attempts to deploy an application manifest to the cluster by running `kubectl apply -f deployment.yaml` on their workstation, but receives the error: `The connection to the server localhost:8080 was refused`. Which command must the engineer execute to resolve this error?

  1. gcloud container clusters get-credentials app-prod-cluster --region us-central1Cevap
  2. B
    gcloud config set container/cluster app-prod-cluster
  3. C
    gcloud container clusters update app-prod-cluster --enable-autopilot --region us-central1
  4. D
    gcloud iam service-accounts keys create key.json --iam-account [email protected]

Cevap

Execute `gcloud container clusters get-credentials app-prod-cluster --region us-central1` to retrieve the cluster's endpoint and authentication data into the local kubeconfig file.
Executing `gcloud container clusters get-credentials` retrieves the API endpoint and authentication credentials for the specified cluster and updates the local `~/.kube/config` configuration file. This allows `kubectl` to successfully discover and authenticate against the GKE control plane.

Adım Adım Çözüm

1
Diagnose the cause of the kubectl connection failure
The error `connection to the server localhost:8080 was refused` indicates that `kubectl` does not have a configured cluster context in `~/.kube/config` and is falling back to the default localhost address.
Before `kubectl` can communicate with a GKE control plane, it requires the cluster's API endpoint IP and certificate authority authority data.
2
Retrieve GKE cluster credentials using the Cloud SDK
Running `gcloud container clusters get-credentials app-prod-cluster --region us-central1` downloads the necessary context and updates `~/.kube/config`.
This command connects to the GKE control plane, generates auth entries, and sets the current-context to the target cluster.

Anahtar Kavram

Configuring kubectl cluster context with gcloud container clusters get-credentials
Bu soruyu puanla