Google Container Engine

(notes for when I doing the Guestbook Tutorial)

Preparation

first, install the gcloud command line tool. note, debian/ubuntu package doesn't support components update, must install via shell.

run gcloud components update and gcloud components update kubectl to install/update kubernetes.

then setup some default variables.

download tutorial files.

Setup Clusters

tutorial uses command line to create a cluster (guestbook is the cluster name):

$ gcloud container clusters create guestbook

but I just create my clusters on web console, called cluster-guestbook.

to check cluster infos:

$ gcloud container clusters list
$ gcloud container clusters describe cluster-guestbook

Create First Pod

first read docs about what is Pod, and how Pod configuration file works.

tutorial uses this line to create a pod (redis-master-controller.json is within the zip file downloaded above):

$ kubectl create -f redis-master-controller.json

however this doesn't work, because it will connect to localhost for master. need to config the master node first.

google already hosts the master node for you, this line will config the master node autometically:

$ gcloud container clusters get-credentials cluster-guestbook

use kubectl config view can check what have been set by the gcloud command.

after the master node has been set, pod can be created by:

$ kubectl create -f redis-master-controller.json
check the pod is running:
$ kubectl get pods

(get pod and get pods are the same)

or use selector -l:

$ kubectl get pods -l name=redis-master

more details:

$ kubectl describe pods -l name=redis-master

can ssh into a node (you can find the node id from the describe command above):

$ gcloud compute ssh gke-cluster-guestbook-xxxxxxxx-node-xxxx

(gcloud will generate a new ssh key for you for first time)

when you inside the node, just docker it:

$ sudo docker ps

Setup Service

first read what is a services and how to define a service.

create the service:

$ kubectl create -f redis-master-service.json

view services:

$ kubectl get service

(get service and get services are the same)

or

$ kubectl get service -l name=redis-service

Setup Workers

(relationships are all defined in the json files)

create the worker pod:

$ kubectl create -f redis-worker-controller.json

check replication controllers:

$ kubectl get rc

check pods (you can see 1 master and 2 slaves running):

$ kubectl get pods

then setup the service for workers:

$ kubectl create -f redis-worker-service.json

again, kubectl get service to get list of services.

Setup Webserver Pods

create the pod:

$ kubectl create -f frontend-controller.json 

check replication:

$ kubectl get rc

check pods:

$ kubectl get pods

setup the service:

$ kubectl create -f frontend-service.json 

verify services:

$ kubectl get service

to get the access point, run this:

$ kubectl describe services frontend | grep "LoadBalancer Ingress"

open the ip address in your browser, you can see the guestbook app is running.

Resizing Replication Controller

to set more pods for frontend, simply:

$ kubectl scale --replicas=5 rc frontend

to verify:

$ kubectl get pods

Cleanup

delete a service:

$ kubectl delete services frontend

shutdown the cluster:

$ gcloud container clusters delete cluster-guestbook

The End

this note focuses on operating, but all the relationship and configuration are in the json files. so a lot of details are not covered.

Search Blog: