text stringlengths 0 59.1k |
|---|
... |
``` |
Result: The deployment then creates the single Redis master pod. |
3. To verify that the redis-master pod is running, list the pods you created in cluster with the `kubectl get pods` command: |
```console |
$ kubectl get pods |
NAME READY STATUS RESTARTS AGE |
redis-master-5b97bdb85f-vvk28 1/1 Running 0 35m |
... |
``` |
Result: You'll see a single Redis master pod and the machine where the pod is running after the pod gets placed (may take up to thirty seconds). |
4. To verify what containers are running in the redis-master pod, you can SSH to that machine with `gcloud compute ssh --zone` *`zone_name`* *`host_name`* and then run `docker ps`: |
```console |
me@workstation$ gcloud compute ssh --zone us-central1-b kubernetes-node-bz1p |
me@kubernetes-node-3:~$ sudo docker ps |
CONTAINER ID IMAGE COMMAND CREATED STATUS |
d5c458dabe50 redis "/entrypoint.sh redis" 5 minutes ago Up 5 minutes |
``` |
Note: The initial `docker pull` can take a few minutes, depending on network conditions. |
### Step Two: Create the Redis master service <a id="step-two"></a> |
A Kubernetes [service](https://kubernetes.io/docs/concepts/services-networking/service/) is a named load balancer that proxies traffic to one or more pods. The services in a Kubernetes cluster are discoverable inside other pods via environment variables or DNS. |
Services find the pods to load balance based on pod labels. The pod that you created in Step One has the label `app=redis` and `role=master`. The selector field of the service determines which pods will receive the traffic sent to the service. |
1. Use the [redis-master-service.yaml](redis-master-service.yaml) file to create the service in your Kubernetes cluster by running the `kubectl create -f` *`filename`* command: |
```console |
$ kubectl create -f guestbook-go/redis-master-service.yaml |
``` |
2. To verify that the redis-master service is up, list the services you created in the cluster with the `kubectl get services` command: |
```console |
$ kubectl get services |
NAME CLUSTER_IP EXTERNAL_IP PORT(S) SELECTOR AGE |
redis-master 10.0.136.3 <none> 6379/TCP app=redis,role=master 1h |
... |
``` |
Result: All new pods will see the `redis-master` service running on the host (`$REDIS_MASTER_SERVICE_HOST` environment variable) at port 6379, or running on `redis-master:6379`. After the service is created, the service proxy on each node is configured to set up a proxy on the specified port (in our example, that's... |
### Step Three: Create the Redis replica pods <a id="step-three"></a> |
The Redis master we created earlier is a single pod (REPLICAS = 1), while the Redis read replicas we are creating here are 'replicated' pods. In Kubernetes, a replication controller is responsible for managing the multiple instances of a replicated pod. |
1. Use the file [redis-replica-controller.yaml](redis-replica-controller.yaml) to create the replication controller by running the `kubectl create -f` *`filename`* command: |
```console |
$ kubectl create -f guestbook-go/redis-replica-controller.yaml |
``` |
2. To verify that the redis-replica controller is running, run the `kubectl get rc` command: |
```console |
$ kubectl get rc |
CONTROLLER CONTAINER(S) IMAGE(S) SELECTOR REPLICAS |
redis-replica redis-replica registry.k8s.io/redis-slave:v2 app=redis,role=replica 2 |
... |
``` |
Result: The replication controller creates and configures the Redis replica pods through the redis-master service (name:port pair, in our example that's `redis-master:6379`). |
Example: |
The Redis replicas get started by the replication controller with the following command: |
```console |
redis-server --replicaof redis-master 6379 |
``` |
3. To verify that the Redis master and replicas pods are running, run the `kubectl get pods` command: |
```console |
$ kubectl get pods |
NAME READY STATUS RESTARTS AGE |
redis-master-5b97bdb85f-vvk28 1/1 Running 0 35m |
redis-replica-b6wj4 1/1 Running 0 1m |
redis-replica-iai40 1/1 Running 0 1m |
... |
``` |
Result: You see the single Redis master and two Redis replica pods. |
### Step Four: Create the Redis replica service <a id="step-four"></a> |
Just like the master, we want to have a service to proxy connections to the read replicas. In this case, in addition to discovery, the Redis replica service provides transparent load balancing to clients. |
1. Use the [redis-replica-service.yaml](redis-replica-service.yaml) file to create the Redis replica service by running the `kubectl create -f` *`filename`* command: |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.