diff --git a/redis/README.md b/redis/README.md index 231f25f..3c45c86 100644 --- a/redis/README.md +++ b/redis/README.md @@ -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 diff --git a/redis/redis.yml b/redis/redis.yml new file mode 100644 index 0000000..aabf3fa --- /dev/null +++ b/redis/redis.yml @@ -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"