GKE Cluster Provisioning and Management
Advanced20 min
Create a Google Kubernetes Engine cluster, connect kubectl, deploy workloads, and configure autoscaling.
Prerequisites
- -gcloud CLI installed
- -kubectl installed
- -GCP project with billing enabled
- -Basic Kubernetes knowledge
Steps
1
Enable the GKE API
Activates the Kubernetes Engine API for the project.
$ gcloud services enable container.googleapis.com
2
Create a GKE Autopilot cluster
Autopilot manages nodes automatically. You only define pods and GKE handles the infrastructure.
$ gcloud container clusters create-auto mycluster --region us-central1
Use Autopilot for most workloads. Use Standard mode only when you need node-level control.
Cluster creation takes 5-10 minutes.
3
Get cluster credentials
Configures kubectl to communicate with the new GKE cluster.
$ gcloud container clusters get-credentials mycluster --region us-central1
4
Deploy a workload
Deploys a sample app and exposes it through a Google Cloud Load Balancer.
$ kubectl create deployment hello-app --image=us-docker.pkg.dev/google-samples/containers/gke/hello-app:1.0 && kubectl expose deployment hello-app --type=LoadBalancer --port=80 --target-port=8080
5
Check the external IP
Waits for the LoadBalancer to provision an external IP address.
$ kubectl get service hello-app --watch
6
Scale the deployment
Scales the deployment to three replicas for higher availability.
$ kubectl scale deployment hello-app --replicas=3
Full Script
FAQ
Discussion
Loading comments...