Soru

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

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?

  1. Execute `gcloud container clusters get-credentials prod-cluster --region us-central1`, and then execute `kubectl apply -f deployment.yaml`.Cevap
  2. B
    Execute `gcloud config set container/cluster prod-cluster` and `gcloud config set compute/region us-central1`, and then execute `kubectl apply -f deployment.yaml`.
  3. C
    Execute `gcloud container clusters create-auto prod-cluster --region us-central1`, and then execute `kubectl apply -f deployment.yaml`.
  4. D
    Execute `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`.

Cevap

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.

Adım Adım Çözüm

1
Fetch the cluster credentials and endpoint data using the gcloud CLI.
The local `$HOME/.kube/config` file is created or updated with the necessary API server endpoint, cluster CA certificate, and authentication token provider for `prod-cluster` in `us-central1`.
Before `kubectl` can route requests to a GKE cluster, its local context must be populated with authentication details.
2
Apply the Kubernetes deployment manifest file via `kubectl`.
The Kubernetes API server accepts the manifest and creates or updates the deployment resource in the cluster.
With an active `kubectl` context pointing to the GKE cluster control plane, deployment commands succeed.

Anahtar Kavram

Configuring kubectl authentication context using gcloud container clusters get-credentials
Bu soruyu puanla