A Kubernetes 'service' is 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 task labels. The task that you created in Step One has the label "name=redis-master", so the corresponding service is defined by that label. Create a file named redis-master-service.json that contains:
```javascript
{
"id": "redismaster",
"port": 10000,
"labels": {
"name": "redis-master"
}
}
```
Once you have that service description, you can create the service with the cloudcfg cli:
Once created, the service proxy on each minion is configured to set up a proxy on the specified port (in this case port 10000).
### Step Three: Turn up the replicated slave service.
Although the redis master is a single task, the redis read slaves are a 'replicated' task, in Kubernetes, a replication controller is responsible for managing multiple instances of a replicated task. Create a file named redis-slave-controller.json that contains:
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:
Once that's up you can list the tasks in the cluster, to verify that the master and slaves are running:
```shell
./src/scripts/cloudcfg.sh list /tasks
```
You should see a single redis master task, and two redis slave tasks.
### Step Four: Create the redis slave service.
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. As before, create a service specification:
This is a simple PHP server that is configured to talk to both the slave and master services depdending on if the request is a read or a write. It exposes a simple AJAX interface, and serves an angular based U/X. Like the redis read slaves it is a replicated service instantiated by a replication controller. Create a file named frontend-controller.json:
To play with the service itself, find the name of a frontend, grab the external IP of that host from the Google Cloud Console, and visit http://<host-ip>:8080. Note, you may need to open the firewall for port 8080 using the console or the gcloud tool.