kubectl), set up the GKE authentication plugin, and configure access to your Google Kubernetes Engine (GKE) cluster. By the end, you’ll verify your setup and deploy a sample Nginx application.
Prerequisites
- A Google Cloud project with GKE API enabled.
gcloudCLI installed and authenticated (gcloud init).- A GKE cluster created (e.g., name:
gke-deep-dive, region/zone:us-west1).
1. Install or Verify kubectl
If you’re using Google Cloud Shell,
kubectl comes pre-installed. You can skip directly to verifying its version.kubectl:
2. Install the GKE Authentication Plugin
GKE clusters requiregke-gcloud-auth-plugin to retrieve authentication tokens for kubectl. Choose one of the methods below:
| Method | Command | When to Use |
|---|---|---|
| A. gcloud Components | gcloud components install gke-gcloud-auth-plugin | Default if component manager is enabled in Cloud SDK. |
| B. apt-get | sudo apt-get install -y google-cloud-sdk-gke-gcloud-auth-plugin | Use if component manager is disabled or on Linux distros. |
If you seeswitch to Method B.
3. Configure GKE Cluster Credentials
Fetch and merge your cluster’s credentials into your local kubeconfig:~/.kube/config with the cluster’s API endpoint, certificates, and user context.
4. Verify kubectl Configuration
4.1 List All Namespaces
4.2 Inspect Full Kubeconfig
Your context and cluster names are prefixed with your project and location. Use these exact identifiers with flags like
--cluster or --context.5. Deploy a Sample Nginx Application
Run an Nginx pod using the Google Cloud Marketplace image:kubectl, configured GKE authentication, and deployed your first application.