Using stateful set to create redis cluster in Kubernetes

This commit is contained in:
2017-07-03 14:12:48 +08:00
parent cafe321d39
commit ff2963f72d
2 changed files with 46 additions and 13 deletions
+3 -13
View File
@@ -2,24 +2,14 @@ This images is aim to help you create a 6 - node Redis cluster in minutes
## Create a Redis cluster on Kubernetes
1. Create a k8s deployment with Redis cluster mode.
1. Create a Redis Statefulset and a Service
```bash
kubectl run redis --image=registry.cn-hangzhou.aliyuncs.com/junv/cluster-redis:latest --command /usr/local/bin/redis-server /root/redis.conf
```
2. Expose the port if you want (optional)
```bash
kubectl expose deployment redis --type=NodePort --port=6379
```
3. Scale up 6 pods
```bash
kubectl scale deployments redis --replicas=6
kubectl create -f redis/redis.yml
```
4. Take a look at the redis pods
```bash
kubectl get pods -o wide | grep redis
kubectl get pods -o wide | grep redis
```
```bash
+43
View File
@@ -0,0 +1,43 @@
---
apiVersion: v1
kind: Service
metadata:
name: redis
labels:
app: redis
spec:
ports:
- port: 6379
name: redis
- port: 16379
name: cluster
clusterIP: None
selector:
app: redis
---
apiVersion: apps/v1beta1
kind: StatefulSet
metadata:
name: redis
spec:
serviceName: "redis"
replicas: 6
template:
metadata:
labels:
app: redis
spec:
containers:
- name: redis
image: registry.cn-hangzhou.aliyuncs.com/junv/cluster-redis:latest
ports:
- containerPort: 6379
name: redis
protocol: "TCP"
- containerPort: 16379
name: cluster
protocol: "TCP"
command:
- "/usr/local/bin/redis-server"
args:
- "/root/redis.conf"