@@ -6,7 +6,7 @@ The example combines a web frontend, a redis master for storage and a replicated
### Step Zero: Prerequisites
This example assumes that you have forked the repository and [turned up a Kubernetes cluster](https://github.com/GoogleCloudPlatform/kubernetes#contents):
This example assumes that you have forked the repository and [turned up a Kubernetes cluster](../../docs/getting-started-guides):
```shell
$ cd kubernetes
...
...
@@ -15,35 +15,37 @@ $ hack/dev-build-and-up.sh
### Step One: Turn up the redis master.
Use the file `examples/guestbook-go/redis-master-pod.json` which describes a single pod running a redis key-value server in a container.
Use the file `examples/guestbook-go/redis-master-controller.json` to create a replication controller which manages a single pod. The pod runs a redis key-value server in a container. Using a replication controller is the preferred way to launch long-running pods, even for 1 replica, so the pod will benefit from self-healing mechanism in kubernetes.
Create the redis pod in your Kubernetes cluster using the `kubectl` CLI:
Create the redis master replication controller in your Kubernetes cluster using the `kubectl` CLI:
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).
List pods in cluster to verify the master is running. 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).
e443647cd064 gurpartap/redis:latest redis-server /etc/r 2 minutes ago Up 2 minutes
CONTAINER ID IMAGE COMMAND CREATED STATUS
d5c458dabe50 gurpartap/redis:latest "/usr/local/bin/redi 5 minutes ago Up 5 minutes
```
(Note that initial `docker pull` may take a few minutes, depending on network conditions.)
...
...
@@ -51,35 +53,30 @@ e443647cd064 gurpartap/redis:latest redis-server /etc/r 2 minutes ago Up 2
### Step Two: Turn up the master service.
A Kubernetes 'service' is a named load balancer that proxies traffic to one or more containers. The services in a Kubernetes cluster are discoverable inside other containers via environment variables. Services find the containers to load balance based on pod labels.
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 `kubectl` cli:
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 in the `kubectl` cli:
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).
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 node is configured to set up a proxy on the specified port (in this case port 6379).
### Step Three: Turn up the replicated slave pods.
Although the redis master is a single pod, the redis read slaves are a 'replicated' pod. In Kubernetes, a replication controller is responsible for managing multiple instances of a replicated pod.
Use the file `examples/guestbook-go/redis-slave-controller.json`
to create the replication controller by running:
Use the file `examples/guestbook-go/redis-slave-controller.json` to create the replication controller:
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:
...
...
@@ -92,10 +89,10 @@ Once that's up you can list the pods in the cluster, to verify that the master a
This is a simple Go net/http ([negroni](https://github.com/codegangsta/negroni) based) server that is configured to talk to either the slave or master services depending on whether the request is a read or a write. It exposes a simple JSON interface, and serves a jQuery-Ajax based UX. Like the redis read slaves it is a replicated service instantiated by a replication controller.
The pod is described in the file `examples/guestbook-go/guestbook-controller.json`:
Using this file, you can turn up your guestbook with:
The pod is described in the file `examples/guestbook-go/guestbook-controller.json`. Using this file, you can turn up your guestbook with:
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:
To play with the service itself, find the external IP of the load balancer from the [Google Cloud Console][cloud-console] or the `gcloud` tool, and visit `http://<ip>:3000`.