Login to gcloud with
gcloud auth login
Set default region
gcloud config set compute/zone us-central1-a
To create a cluser, run
gcloud container clusters create CLUSTER-NAME
To create a cluster with 2 nodes, run
gcloud container clusters create CLUSTER-NAME --num-nodes 2
To specify compute engine type during cluster creation, run
gcloud container clusters create CLUSTER-NAME --num-nodes 2 --machine-type n1-standard-2
You can also specify scopes, this allow you to give the cluster permission to access other google cloud resources. For example to allow cluster access Cloud Source Repositories and Google Container Registry. run
gcloud container clusters create CLUSTER-NAME --num-nodes 2 --machine-type n1-standard-2 --scopes "https://www.googleapis.com/auth/projecthosting,cloud-platform"
To list your container, run
gcloud container clusters list
Before you can use cluser, you need to get authentication credentials with command
gcloud container clusters get-credentials CLUSTER-NAME
To interact with Kubernetes, you need kubectl, on Ubuntu, yu can install it with
sudo snap install kubectl --classic
To deploy a container, run
kubectl run hello-server --image=gcr.io/google-samples/hello-app:1.0 --port 8080
This will deploy google provided hello-app container to the cluser.
To make the application available to public, create a loadbalancer service.
kubectl expose deployment hello-server --type="LoadBalancer"
Now find IP of the LoadBalacner service with command
kubectl get services
From the result, we found EXTERNAL-IP for LoadBalancer is 35.232.226.216. To access the application, go to url
http://35.232.226.216:8080
See Kubernetes