Created
October 1, 2020 16:27
-
-
Save mnadeem/d79a75884c2ee922c524f4b08b73d787 to your computer and use it in GitHub Desktop.
Redis HA Master Slave Cluster Kubernetes.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
apiVersion: v1 | |
kind: Template | |
metadata: | |
name: ${NAME} | |
labels: | |
name: ${NAME} | |
annotations: | |
description: Redis master/slave templates based on Statefulsets | |
parameters: | |
- name: NAME | |
description: Application name | |
required: true | |
value: "redis" | |
- name: CPU | |
description: "Number of CPUs per node in milli cores" | |
required: true | |
value: "500m" | |
- name: RAM | |
description: "RAM size per node in gigabytes" | |
required: true | |
value: "1Gi" | |
- name: STORAGE | |
description: "STORAGE size per node in gigabytes" | |
required: true | |
value: "1Gi" | |
- name: DOCKER_PATH_AND_IMAGE | |
description: "Docker Image" | |
required: true | |
value: "redis:6.0.8" | |
objects: | |
- apiVersion: v1 | |
kind: ConfigMap | |
metadata: | |
name: redis-cluster | |
data: | |
update-node.sh: | | |
#!/bin/sh | |
REDIS_NODES="/data/nodes.conf" | |
sed -i -e "/myself/ s/[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}/${POD_IP}/" ${REDIS_NODES} | |
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 yes | |
protected-mode no | |
- apiVersion: apps/v1 | |
kind: StatefulSet | |
metadata: | |
name: redis-cluster | |
spec: | |
serviceName: redis-cluster | |
replicas: 6 | |
selector: | |
matchLabels: | |
app: redis-cluster | |
template: | |
metadata: | |
labels: | |
app: redis-cluster | |
spec: | |
containers: | |
- name: redis | |
image: ${DOCKER_PATH_AND_IMAGE} | |
ports: | |
- containerPort: 6379 | |
name: client | |
- containerPort: 16379 | |
name: gossip | |
command: ["/conf/update-node.sh", "redis-server", "/conf/redis.conf"] | |
env: | |
- name: POD_IP | |
valueFrom: | |
fieldRef: | |
fieldPath: status.podIP | |
volumeMounts: | |
- name: conf | |
mountPath: /conf | |
readOnly: false | |
- name: redis-data | |
mountPath: /data | |
readOnly: false | |
volumes: | |
- name: conf | |
configMap: | |
name: redis-cluster | |
defaultMode: 0755 | |
volumeClaimTemplates: | |
- metadata: | |
name: redis-data | |
spec: | |
accessModes: [ "ReadWriteOnce" ] | |
resources: | |
limits: | |
memory: 1Gi | |
requests: | |
storage: 1Gi | |
memory: 500Mi | |
- apiVersion: v1 | |
kind: Service | |
metadata: | |
name: redis-cluster | |
spec: | |
type: ClusterIP | |
ports: | |
- port: 6379 | |
targetPort: 6379 | |
name: client | |
- port: 16379 | |
targetPort: 16379 | |
name: gossip | |
selector: | |
app: redis-cluster |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment