반응형
🍳머리말
redis cluster를 k8s환경에 statefulset으로 배포하는 예제 file입니다.
📕 Prerequisite
📔 k8s cluster
📔 redis image
DNS로 cluster create하는 것은 redis 7부터 지원합니다.
📕 ConfigMap, Service, StatefulSet 작성
📔 yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: redis-cluster
namespace: redis
labels:
app: redis-cluster
data:
fix-ip.sh: |
#!/bin/sh
CLUSTER_CONFIG="/data/nodes.conf"
if [ -f ${CLUSTER_CONFIG} ]; then
if [ -z "${POD_IP}" ]; then
echo "Unable to determine Pod IP address!"
exit 1
fi
echo "Updating my IP to ${POD_IP} in ${CLUSTER_CONFIG}"
sed -i.bak -e "/myself/ s/[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}/${POD_IP}/" ${CLUSTER_CONFIG}
fi
exec "$@"
redis.conf: |+
cluster-enabled yes
cluster-require-full-coverage no
cluster-node-timeout 15000
cluster-config-file /data/nodes.conf
cluster-migration-barrier 1
appendonly no
save ""
protected-mode no
---
apiVersion: v1
kind: Service
metadata:
name: redis-cluster
namespace: redis
labels:
app: redis-cluster
spec:
ports:
- port: 6379
targetPort: 6379
name: client
- port: 16379
targetPort: 16379
name: gossip
type: ClusterIP
selector:
app: redis-cluster
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: redis-cluster
namespace: redis
labels:
app: redis-cluster
spec:
serviceName: redis-cluster
replicas: 6
selector:
matchLabels:
app: redis-cluster
template:
metadata:
labels:
app: redis-cluster
spec:
containers:
- name: redis
image: redis:6.2-rc
ports:
- containerPort: 6379
name: client
- containerPort: 16379
name: gossip
command: ["/conf/fix-ip.sh", "redis-server", "/conf/redis.conf"]
readinessProbe:
exec:
command:
- sh
- -c
- "redis-cli -h $(hostname) ping"
initialDelaySeconds: 15
timeoutSeconds: 5
livenessProbe:
exec:
command:
- sh
- -c
- "redis-cli -h $(hostname) ping"
initialDelaySeconds: 20
periodSeconds: 3
env:
- name: POD_IP
valueFrom:
fieldRef:
fieldPath: status.podIP
volumeMounts:
- name: conf
mountPath: /conf
readOnly: false
- name: data
mountPath: /data
readOnly: false
volumes:
- name: conf
configMap:
name: redis-cluster
defaultMode: 0755
volumeClaimTemplates:
- metadata:
name: data
labels:
name: redis-cluster
spec:
accessModes: [ "ReadWriteOnce" ]
#storageClassName: efs-sc
resources:
requests:
storage: 100Mi
'Cloud' 카테고리의 다른 글
(Terraform) - Window에 설치 (0) | 2022.04.25 |
---|---|
(Kubernetes) - TLS/SSL secret 생성하기 (0) | 2022.04.19 |
(NGINX Ingress Controller) - TCP, UDP service 노출해 redis cluster와 연결하기 (0) | 2022.04.06 |
(Kubernetes) - resouce 생성 예시 file (0) | 2022.03.31 |
(Redis Operator) - 설치방법 (0) | 2022.01.26 |