commit
						3affde29e1
					
				|  | @ -17,24 +17,23 @@ $ hack/dev-build-and-up.sh | |||
| 
 | ||||
| Use the file `examples/guestbook-go/redis-master-pod.json` which describes a single pod running a redis key-value server in a container. | ||||
| 
 | ||||
| Create the redis pod in your Kubernetes cluster using the `kubecfg` CLI: | ||||
| Create the redis pod in your Kubernetes cluster using the `kubectl` CLI: | ||||
| 
 | ||||
| ```shell | ||||
| $ cluster/kubecfg.sh -c examples/guestbook-go/redis-master-pod.json create pods | ||||
| $ cluster/kubectl.sh create -f examples/guestbook-go/redis-master-pod.json | ||||
| ``` | ||||
| 
 | ||||
| Once that's up you can list the pods in the cluster, to verify that the master is running: | ||||
| 
 | ||||
| ```shell | ||||
| $ cluster/kubecfg.sh list pods | ||||
| $ cluster/kubectl.sh get pods | ||||
| ``` | ||||
| 
 | ||||
| You'll see a single redis master pod. It will also display the machine that the pod is running on once it gets placed (may take up to thirty seconds). | ||||
| 
 | ||||
| ``` | ||||
|   ID                Image(s)            Host                                          Labels                 Status | ||||
| ----------          ----------          ----------                                    ----------             ---------- | ||||
| redis-master-pod    gurpartap/redis     kubernetes-minion-3.c.briandpe-api.internal   name=redis,role=master      Running | ||||
| ID                  IMAGE(S)            HOST                                                      LABELS                     STATUS | ||||
| redis-master-pod    gurpartap/redis     kubernetes-minion-3.c.thockin-dev.internal/86.75.30.9     name=redis,role=master     Waiting | ||||
| ``` | ||||
| 
 | ||||
| If you ssh to that machine, you can run `docker ps` to see the actual pod: | ||||
|  | @ -45,7 +44,7 @@ $ sudo docker ps | |||
| 
 | ||||
| me@kubernetes-minion-3:~$ sudo docker ps | ||||
| CONTAINER ID  IMAGE                   COMMAND              CREATED         STATUS | ||||
| e443647cd064  gurpartap/redis:latest  redis-server /etc/r  22 minutes ago  Up 22 minutes | ||||
| e443647cd064  gurpartap/redis:latest  redis-server /etc/r  2 minutes ago   Up 2 minutes | ||||
| ``` | ||||
| 
 | ||||
| (Note that initial `docker pull` may take a few minutes, depending on network conditions.) | ||||
|  | @ -55,16 +54,17 @@ A Kubernetes 'service' is a named load balancer that proxies traffic to one or m | |||
| 
 | ||||
| The pod that you created in Step One has the label `name=redis` and `role=master`. The selector field of the service determines which pods will receive the traffic sent to the service.  Use the file `examples/guestbook-go/redis-master-service.json` | ||||
| 
 | ||||
| To create the service with the `kubecfg` cli: | ||||
| To create the service with the `kubectl` cli: | ||||
| 
 | ||||
| ```shell | ||||
| $ cluster/kubecfg.sh -c examples/guestbook-go/redis-master-service.json create services | ||||
| ID                     Labels              Selector                 Port | ||||
| ----------             ----------          ----------               ---------- | ||||
| redis-master                               name=redis,role=master   6379 | ||||
| $ cluster/kubectl.sh create -f examples/guestbook-go/redis-master-service.json | ||||
| 
 | ||||
| $ cluster/kubectl.sh get services | ||||
| ID                  LABELS                     SELECTOR                   PORT | ||||
| redis-master                                   name=redis,role=master     6379 | ||||
| ``` | ||||
| 
 | ||||
| This will cause all pods to see the redis master apparently running on localhost:6379. | ||||
| This will cause all new pods to see the redis master apparently running on $REDIS_MASTER_SERVICE_HOST at port 6379. | ||||
| 
 | ||||
| Once created, the service proxy on each minion is configured to set up a proxy on the specified port (in this case port 6379). | ||||
| 
 | ||||
|  | @ -76,10 +76,11 @@ Use the file `examples/guestbook-go/redis-slave-controller.json` | |||
| to create the replication controller by running: | ||||
| 
 | ||||
| ```shell | ||||
| $ cluster/kubecfg.sh -c examples/guestbook-go/redis-slave-controller.json create replicationControllers | ||||
|   ID                    Image(s)         Selector               Replicas | ||||
| ----------              ----------       ----------             ---------- | ||||
| redis-slave-controller  gurpartap/redis  name=redis,role=slave  2 | ||||
| $ cluster/kubectl.sh create -f examples/guestbook-go/redis-slave-controller.json | ||||
| 
 | ||||
| $ cluster/kubectl.sh get replicationControllers | ||||
| ID                       IMAGE(S)                    SELECTOR                   REPLICAS | ||||
| redis-slave-controller   gurpartap/redis             name=redis,role=slave      2 | ||||
| ``` | ||||
| 
 | ||||
| The redis slave configures itself by looking for the Kubernetes service environment variables in the container environment. In particular, the redis slave is started with the following command: | ||||
|  | @ -91,12 +92,11 @@ redis-server --slaveof $REDIS_MASTER_SERVICE_HOST $REDIS_MASTER_SERVICE_PORT | |||
| Once that's up you can list the pods in the cluster, to verify that the master and slaves are running: | ||||
| 
 | ||||
| ```shell | ||||
| $ cluster/kubecfg.sh list pods | ||||
|   ID              Image(s)         Host                                         Labels                                                         Status | ||||
| ----------        ----------       ----------                                   ----------                                                     ---------- | ||||
| redis-master-pod  gurpartap/redis  kubernetes-minion-3.c.briandpe-api.internal  name=redis,role=master                                              Running | ||||
| 4d65822107fcfd52  gurpartap/redis  kubernetes-minion-3.c.briandpe-api.internal  name=redis,role=slave,replicationController=redis-slave-controller  Running | ||||
| 78629a0f5f3f164f  gurpartap/redis  kubernetes-minion-4.c.briandpe-api.internal  name=redis,role=slave,replicationController=redis-slave-controller  Running | ||||
| $ cluster/kubectl.sh get pods | ||||
| ID                                    IMAGE(S)            HOST                                                      LABELS                                                               STATUS | ||||
| redis-master-pod                      gurpartap/redis     kubernetes-minion-1.c.thockin-dev.internal/86.75.30.9     name=redis,role=master                                               Running | ||||
| 1472fd26-54d6-11e4-90fd-42010af00690  gurpartap/redis     kubernetes-minion-4.c.thockin-dev.internal/12.34.56.78    name=redis,replicationController=redis-slave-controller,role=slave   Running | ||||
| 1473363e-54d6-11e4-90fd-42010af00690  gurpartap/redis     kubernetes-minion-3.c.thockin-dev.internal/9.3.19.76      name=redis,replicationController=redis-slave-controller,role=slave   Running | ||||
| ``` | ||||
| 
 | ||||
| You will see a single redis master pod and two redis slave pods. | ||||
|  | @ -105,15 +105,17 @@ You will see a single redis master pod and two redis slave pods. | |||
| 
 | ||||
| Just like the master, we want to have a service to proxy connections to the read slaves. In this case, in addition to discovery, the slave service provides transparent load balancing to clients. The service specification for the slaves is in `examples/guestbook-go/redis-slave-service.json` | ||||
| 
 | ||||
| This time the selector for the service is `name=redis,role=slave`, because that identifies the pods running redis slaves. It may also be helpful to set labels on your service itself--as we've done here--to make it easy to locate them with the `kubecfg -l "label=value" list services` command. | ||||
| This time the selector for the service is `name=redis,role=slave`, because that identifies the pods running redis slaves. It may also be helpful to set labels on your service itself--as we've done here--to make it easy to locate them later. | ||||
| 
 | ||||
| Now that you have created the service specification, create it in your cluster with the `kubecfg` CLI: | ||||
| Now that you have created the service specification, create it in your cluster with the `kubectl` CLI: | ||||
| 
 | ||||
| ```shell | ||||
| $ cluster/kubecfg.sh -c examples/guestbook-go/redis-slave-service.json create services | ||||
|   ID         Labels            Selector               Port | ||||
| ----------   ----------        ----------             ---------- | ||||
| redis-slave  name=redis-slave  name=redis,role=slave  6379 | ||||
| $ cluster/kubectl.sh create -f examples/guestbook-go/redis-slave-service.json | ||||
| 
 | ||||
| $ cluster/kubectl.sh get services | ||||
| ID                  LABELS                     SELECTOR                   PORT | ||||
| redis-master                                   name=redis,role=master     6379 | ||||
| redis-slave         name=redis,role=slave      name=redis,role=slave      6379 | ||||
| ``` | ||||
| 
 | ||||
| ### Step Five: Create the guestbook pod. | ||||
|  | @ -125,32 +127,58 @@ The pod is described in the file `examples/guestbook-go/guestbook-controller.jso | |||
| Using this file, you can turn up your guestbook with: | ||||
| 
 | ||||
| ```shell | ||||
| $ cluster/kubecfg.sh -c examples/guestbook-go/guestbook-controller.json create replicationControllers | ||||
|   ID                  Image(s)         Selector       Replicas | ||||
| ----------            ----------       ----------     ---------- | ||||
| guestbook-controller  gurpartap/redis  name=guestbook  3 | ||||
| $ cluster/kubectl.sh create -f examples/guestbook-go/guestbook-controller.json | ||||
| 
 | ||||
| $ cluster/kubectl.sh get replicationControllers | ||||
| ID                       IMAGE(S)               SELECTOR                REPLICAS | ||||
| redis-slave-controller   gurpartap/redis        name=redis,role=slave   2 | ||||
| guestbook-controller     kubernetes/guestbook   name=guestbook          3 | ||||
| ``` | ||||
| 
 | ||||
| Once that's up (it may take ten to thirty seconds to create the pods) you can list the pods in the cluster, to verify that the master, slaves and guestbook frontends are running: | ||||
| 
 | ||||
| ```shell | ||||
| $ cluster/kubecfg.sh list pods | ||||
|   ID              Image(s)              Host                                         Labels                                                              Status | ||||
| ----------        ----------            ----------                                   ----------                                                          ---------- | ||||
| redis-master-pod  gurpartap/redis       kubernetes-minion-3.c.briandpe-api.internal  name=redis,role=master                                              Running | ||||
| 4d65822107fcfd52  gurpartap/redis       kubernetes-minion-3.c.briandpe-api.internal  name=redis,role=slave,replicationController=redis-slave-controller  Running | ||||
| 380704bb7b4d7c03  kubernetes/guestbook  kubernetes-minion-3.c.briandpe-api.internal  name=guestbook,replicationController=guestbook-controller           Running | ||||
| 55104dc76695721d  kubernetes/guestbook  kubernetes-minion-2.c.briandpe-api.internal  name=guestbook,replicationController=guestbook-controller           Running | ||||
| 365a858149c6e2d1  kubernetes/guestbook  kubernetes-minion-1.c.briandpe-api.internal  name=guestbook,replicationController=guestbook-controller           Running | ||||
| 78629a0f5f3f164f  gurpartap/redis       kubernetes-minion-4.c.briandpe-api.internal  name=redis,role=slave,replicationController=redis-slave-controller  Running | ||||
| $ cluster/kubectl.sh get pods | ||||
| ID                                    IMAGE(S)              HOST                                                     LABELS                                                               STATUS | ||||
| redis-master-pod                      gurpartap/redis       kubernetes-minion-1.c.thockin-dev.internal/86.75.30.9    name=redis,role=master                                               Running | ||||
| 1472fd26-54d6-11e4-90fd-42010af00690  gurpartap/redis       kubernetes-minion-4.c.thockin-dev.internal/12.34.56.78   name=redis,replicationController=redis-slave-controller,role=slave   Running | ||||
| 1473363e-54d6-11e4-90fd-42010af00690  gurpartap/redis       kubernetes-minion-3.c.thockin-dev.internal/9.3.19.76     name=redis,replicationController=redis-slave-controller,role=slave   Running | ||||
| fc58aa01-54d6-11e4-90fd-42010af00690  kubernetes/guestbook  kubernetes-minion-1.c.thockin-dev.internal/1.18.19.78    name=guestbook,replicationController=guestbook-controller            Running | ||||
| fc592fbb-54d6-11e4-90fd-42010af00690   kubernetes/guestbook   kubernetes-minion-1.c.thockin-dev.internal/12.9.20.9   name=guestbook,replicationController=guestbook-controller            Running | ||||
| fc59569e-54d6-11e4-90fd-42010af00690   kubernetes/guestbook   kubernetes-minion-2.c.thockin-dev.internal/1.11.20.13  name=guestbook,replicationController=guestbook-controller            Running | ||||
| 
 | ||||
| ``` | ||||
| 
 | ||||
| You will see a single redis master pod, two redis slaves, and three guestbook pods. | ||||
| 
 | ||||
| To play with the service itself, find the name of a guestbook, grab the external IP of that host from the [Google Cloud Console][cloud-console] or the `gcutil` tool, and visit `http://<host-ip>:3000`. | ||||
| ### Step Six: Create the guestbook service. | ||||
| 
 | ||||
| Just like the others, you want a service to group your guestbook pods.  The service specification for the guestbook is in `examples/guestbook-go/guestbook-service.json`.  There's a twist this time - because we want it to be externally visible, we set the `createExternalLoadBalancer` flag on the service. | ||||
| 
 | ||||
| ```shell | ||||
| $ gcutil listinstances | ||||
| $ cluster/kubectl.sh create -f examples/guestbook-go/guestbook-service.json | ||||
| 
 | ||||
| $ cluster/kubectl.sh get services | ||||
| ID                  LABELS                  SELECTOR                 IP                  PORT | ||||
| redis-master                                name=redis,role=master   10.0.0.1            6379 | ||||
| redis-slave         name=redis,role=slave   name=redis,role=slave    10.0.0.2            6379 | ||||
| guestbook                                   name=guestbook           10.0.0.3            3000 | ||||
| ``` | ||||
| 
 | ||||
| To play with the service itself, find the external IP of the load balancer from the [Google Cloud Console][cloud-console] or the `gcutil` tool, and visit `http://<ip>:3000`. | ||||
| 
 | ||||
| ```shell | ||||
| $ gcutil getforwardingrule guestbook | ||||
| +---------------+-----------------------------------+ | ||||
| | name          | guestbook                         | | ||||
| | description   |                                   | | ||||
| | creation-time | 2014-10-15T19:07:24.837-07:00     | | ||||
| | region        | us-central1                       | | ||||
| | ip            | 12.34.56.78                       | | ||||
| | protocol      | TCP                               | | ||||
| | port-range    | 3000-3000                         | | ||||
| | target        | us-central1/targetPools/guestbook | | ||||
| +---------------+-----------------------------------+ | ||||
| ``` | ||||
| 
 | ||||
| You may need to open the firewall for port 3000 using the [console][cloud-console] or the `gcutil` tool. The following command will allow traffic from any source to instances tagged `kubernetes-minion`: | ||||
|  | @ -165,7 +193,7 @@ For details about limiting traffic to specific sources, see the [gcutil document | |||
| [cloud-console]: https://console.developer.google.com | ||||
| [gcutil-docs]: https://developers.google.com/compute/docs/gcutil/reference/firewall#addfirewall | ||||
| 
 | ||||
| ### Step Six: Cleanup | ||||
| ### Step Seven: Cleanup | ||||
| 
 | ||||
| To turn down a Kubernetes cluster: | ||||
| 
 | ||||
|  |  | |||
|  | @ -4,5 +4,6 @@ | |||
|   "id": "guestbook", | ||||
|   "port": 3000, | ||||
|   "containerPort": "http-server", | ||||
|   "selector": { "name": "guestbook" } | ||||
|   "selector": { "name": "guestbook" }, | ||||
|   "createExternalLoadBalancer": true | ||||
| } | ||||
|  |  | |||
|  | @ -13,7 +13,7 @@ | |||
|           "containers": [{ | ||||
|             "name": "redis-slave", | ||||
|             "image": "gurpartap/redis", | ||||
|             "command": ["sh", "-c", "redis-server /etc/redis/redis.conf --slaveof $SERVICE_HOST $REDIS_MASTER_SERVICE_PORT"], | ||||
|             "command": ["sh", "-c", "redis-server /etc/redis/redis.conf --slaveof $REDIS_MASTER_SERVICE_HOST $REDIS_MASTER_SERVICE_PORT"], | ||||
|             "ports": [{ "name": "redis-server", "containerPort": 6379 }] | ||||
|           }] | ||||
|         } | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue