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 guestbookbut I just create my clusters on web console, called cluster-guestbook.
to check cluster infos:
$ gcloud container clusters list
$ gcloud container clusters describe cluster-guestbookCreate 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.jsonhowever 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-guestbookuse 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-mastermore details:
$ kubectl describe pods -l name=redis-mastercan 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 psSetup Service
first read what is a services and how to define a service.
create the service:
$ kubectl create -f redis-master-service.jsonview services:
$ kubectl get service(get service and get services are the same)
or
$ kubectl get service -l name=redis-serviceSetup Workers
(relationships are all defined in the json files)
create the worker pod:
$ kubectl create -f redis-worker-controller.jsoncheck replication controllers:
$ kubectl get rccheck pods (you can see 1 master and 2 slaves running):
$ kubectl get podsthen setup the service for workers:
$ kubectl create -f redis-worker-service.jsonagain, kubectl get service to get list of services.
Setup Webserver Pods
create the pod:
$ kubectl create -f frontend-controller.json check replication:
$ kubectl get rccheck pods:
$ kubectl get podssetup the service:
$ kubectl create -f frontend-service.json verify services:
$ kubectl get serviceto 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 frontendto verify:
$ kubectl get podsCleanup
delete a service:
$ kubectl delete services frontendshutdown the cluster:
$ gcloud container clusters delete cluster-guestbookThe 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.