gcloud container clusters get-credentials: GKE kubeconfig
Write GKE cluster credentials into kubeconfig so kubectl and helm can target the cluster.
gcloud container clusters get-credentials fetches endpoint and auth data for a GKE cluster and merges it into your kubeconfig. After running it, kubectl uses the gke-gcloud-auth-plugin to authenticate. In CI this is the bridge between gcloud auth and kubectl.
Common flags
CLUSTER- the cluster name (positional)--region=REGIONor--zone=ZONE- cluster location--project=PROJECT_ID- project that owns the cluster
Example in CI
Fetch credentials, then verify kubectl can reach the cluster.
shell
gcloud container clusters get-credentials prod-cluster \
--region=us-central1 --project=my-project
kubectl get nodesCommon errors in CI
- No such file or directory: gke-gcloud-auth-plugin - install the gke-gcloud-auth-plugin component
- You do not currently have an active account selected - gcloud auth not run first
- Required "container.clusters.get" permission ... denied - SA missing roles/container.viewer
Key takeaways
- Merges GKE credentials into kubeconfig for kubectl and helm to use.
- Requires gke-gcloud-auth-plugin to be installed on the runner.
- Provide --region or --zone; clusters are not found without the right location.
Related guides
gcloud auth activate-service-account: Authenticate CIAuthenticate gcloud in CI with a service account key file: required flags, a GitHub Actions example, and the…
kubectl config use-context: Select Clusters in CISwitch the active kubeconfig context in CI: usage, a multi-cluster example, and the errors that mean a missin…
kubectl apply: Deploy Manifests in CIApply Kubernetes manifests declaratively in CI: the flags you use most, a pipeline example, and the apply err…