How to create and use a GKE cluster from Google Cloud Shell step-by-step:
Step-by-Step: Use GKE from Google Cloud Shell
1. Open Google Cloud Shell
- Visit: https://console.cloud.google.com
- Click the Cloud Shell icon (terminal button in the top right)
2. Verify Your Project & Set Zone
gcloud config list
gcloud config set compute/zone us-central1-a
Check available zones:
gcloud compute zones list
3. Enable GKE API
gcloud services enable container.googleapis.com
4. Create a GKE Cluster
gcloud container clusters create demo-cluster --num-nodes=2
Optional: add machine type or auto-scaling flags:
gcloud container clusters create demo-cluster \
--num-nodes=2 \
--machine-type=e2-medium \
--enable-autoscaling --min-nodes=1 --max-nodes=3
5. Configure kubectl for GKE
gcloud container clusters get-credentials demo-cluster
This sets your current kubectl context to the new GKE cluster.
6. Verify Cluster is Working
kubectl get nodes
7. Deploy an Application
kubectl create deployment myapp --image=nginx
kubectl expose deployment myapp --type=LoadBalancer --port=80
8. Access the Application
kubectl get svc
Wait for the EXTERNAL-IP to show up, then open it in your browser.
๐งน Cleanup
To avoid billing charges:
gcloud container clusters delete demo-cluster