Create Kubernetes cluser using gcloud
Login to gcloud with
1 |
gcloud auth login |
Set default region
1 |
gcloud config set compute/zone us-central1-a |
To create a cluser, run
1 |
gcloud container clusters create CLUSTER-NAME |
To create a cluster with 2 nodes, run
1 |
gcloud container clusters create CLUSTER-NAME --num-nodes 2 |
To specify compute engine type during cluster creation, run
1 |
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
1 |
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
1 |
gcloud container clusters list |
Before you can use cluser, you need to get authentication credentials with command
1 |
gcloud container clusters get-credentials CLUSTER-NAME |
To interact with Kubernetes, you need kubectl, on Ubuntu, yu can install it with
1 |
sudo snap install kubectl --classic |
To deploy a container, run
1 |
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.
1 |
kubectl expose deployment hello-server --type="LoadBalancer" |
Now find IP of the LoadBalacner service with command
1 |
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