Game of Pods攻略~Redis Islands~
redisHAクラスターの構築です
Game of Pods関連のソースコードを挙げてます
https://github.com/hayama17/Game-of-Pods
作りたい環境
- Redisクラスター(StatefulSet)
- NodePort
- clinet
- port: 6379
- targetport: 6379
- gossip
- port: 16379
- targetPort: 16379
- clinet
- PV6個
- /dataをPVCにマウント
- /confをconfigmapにマウント
- NodePort
PVの作成
6個作る。
一気に作りたかったけどやり方が分らない...
apiVersion: v1
kind: PersistentVolume
metadata:
name: redis(01~06) #合わせて作る
spec:
capacity:
storage: 1Gi
accessModes:
- ReadWriteOnce
hostPath:
path: /redis(01~06) #合わせて作る
type: DirectoryOrCreate
StatefulSetの作成
要件通りに作成
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: redis-cluster
spec:
serviceName: redis-cluster
replicas: 6
selector:
matchLabels:
app: redis
template:
metadata:
labels:
app: redis
spec:
containers:
- image: redis:5.0.1-alpine
name: redis
command: ["/conf/update-node.sh", "redis-server", "/conf/redis.conf"]
env:
- name: POD_IP
valueFrom:
fieldRef:
fieldPath: status.podIP
ports:
- name: client
containerPort: 6379
- name: gossip
containerPort: 16379
volumeMounts:
- name: conf
mountPath: /conf
readOnly: false
- name: data
mountPath: /data
readOnly: false
volumes:
- name: conf
configMap:
name: redis-cluster-configmap
defaultMode: 0755
volumeClaimTemplates:
- metadata:
name: data
spec:
resources:
requests:
storage: 1Gi
accessModes:
- ReadWriteOnce
NodePortの作成
apiVersion: v1
kind: Service
metadata:
name: redis-cluster-service
spec:
ports:
- name: client
port: 6379
targetPort: 6379
- name: gossip
port: 16379
targetPort: 16379
selector:
app: redis
各コンテンナをクラスターとして登録
$ kubectl exec -it redis-cluster-0 -- redis-cli --cluster create --cluster-replicas 1 $(kubectl get pods -l app=redis-cluster -o jsonpath='{range.items[*]}{.status.podIP}:6379 ')
[ERR] Wrong number of arguments for specified --cluster sub command
command terminated with exit code 1
あれ? 動かない...
原因
ラベルが違っていた
yaml app: redis
command app:redis-cluster
解決策
ラベルを変えるだけ
$ kubectl exec -it redis-cluster-0 -- redis-cli --cluster create --cluster-replicas 1 $(kubectl get pods -l app=redis -o jsonpath='{range.items[*]}{.status.podIP}:6379 ')
>>> Performing hash slots allocation on 6 nodes...
.
.
.
Can I set the above configuration? (type 'yes' to accept): yes
>>> Nodes configuration updated
.
.
.
[OK] All 16384 slots covered.
できた!
GitHub