mirror of
https://github.com/wahyd4/docker-images.git
synced 2026-08-09 04:46:45 +10:00
Using stateful set to create redis cluster in Kubernetes
This commit is contained in:
+3
-13
@@ -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
|
||||
|
||||
@@ -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"
|
||||
Reference in New Issue
Block a user