Kubernetes on Google cloud

In this blog, I will cover the steps to run Kubernetes on Google compute VM. I used the steps mentioned here.

Pre-requisites:

  • Need Google cloud account.
  • Install Google cloud SDK.

First step is to download and unzip Kubernetes tar file from here.
Next, we create the cluster using the provided script.

export KUBERNETES_PROVIDER=gce
./cluster/kube-up.sh

The above script creates the clusters with 1 master and 4 minions. Also, it sets up all necessary services both in master and minions node.
Lets look at the VMs created:

$ gcloud compute instances list
NAME                   ZONE          MACHINE_TYPE  INTERNAL_IP    EXTERNAL_IP    STATUS
kubernetes-minion-wsh1 us-central1-b n1-standard-1 10.240.154.192 104.197.12.208 RUNNING
kubernetes-minion-ojzz us-central1-b n1-standard-1 10.240.125.199 107.178.220.83 RUNNING
kubernetes-minion-or9g us-central1-b n1-standard-1 10.240.253.95  130.211.148.31 RUNNING
kubernetes-minion-8r0f us-central1-b n1-standard-1 10.240.116.204 104.154.64.190 RUNNING
kubernetes-master      us-central1-b n1-standard-1 10.240.214.74  104.154.44.48  RUNNING

Lets create a nginx pod with 2 replicas:

# run container
cluster/kubectl.sh run-container my-nginx --image=dockerfile/nginx --replicas=2 --port=80

Get list of pods:

$ cluster/kubectl.sh get pods
current-context: "eighth-keyword-474_kubernetes"
Running: cluster/../cluster/gce/../../platforms/linux/amd64/kubectl get pods
POD                                          IP                  CONTAINER(S)            IMAGE(S)                            HOST                                                    LABELS                                                                      STATUS              CREATED                                                                                                                                                          
my-nginx-i7hvs                                                   my-nginx                dockerfile/nginx                    kubernetes-minion-wsh1.c.eighth-keyword-474.internal/   run-container=my-nginx                                                      Unknown             4 minutes
my-nginx-nyxxv                                                   my-nginx                dockerfile/nginx                    kubernetes-minion-or9g.c.eighth-keyword-474.internal/   run-container=my-nginx                                                      Unknown             4 minutes

We should be able to access the webserver now.

Lets delete the pods:

# stop pod
cluster/kubectl.sh stop rc my-nginx
# Delete pod
cluster/kubectl.sh delete rc my-nginx

Lets delete the cluster:

# bringdown cluster
cluster/kube-down.sh

For guestbook application, we can follow the procedure here. This application has multiple pods and services.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s