k8s_redis_sentinel_1
Redis-Sentinel on Kubernetes Prep ①
Manifest (YAML) overview
Redis-Sentinel overview
Redis-Sentinel stores (and manages) data on one Redis Pod (the master) and keeps two backup (replica) Pods.
Three Sentinel Pods monitor the Redis master and, if the master goes down, promote one of the replicas to master.
🔗 See here for a full Redis-Sentinel overview.
1. Redis-Sentinel manifests (YAML)
When you deploy Redis-Sentinel on Kubernetes, split the work across four YAML files: config (Config), Service, Redis Pod creation, and Sentinel Pod creation (two StatefulSets).
2. File contents in deploy order
🟢 [Step 1] Redis-Sentinel config: redis-sentinel-config.yaml
- Kind: ConfigMap
- Name (metadata:name): redis-sentinel-config
⚠️ Names are strictly limited to lowercase (a-z), digits (0-9), and hyphens (`-`) (uppercase is not allowed)
- This is the ConfigMap. Directives here are used to build redis.conf and sentinel.conf.
- The default redis.conf and sentinel.conf that come with the tarball are not used.
- If each Redis instance (Pod) needs a different value, you can set it dynamically with a command script in the StatefulSet. Example) replica-priority 100, 110, 120
🧑💻 Key values
- bind * -::* # IPs are assigned dynamically and change, so accept all IPs.
KISA (Korea Internet & Security Agency) [Cloud Vulnerability Assessment Guide] insists on setting a specific IP on bind for security. That is correct on VMs/physical servers, but you cannot do that in Kubernetes.
(You need to explain this clearly to auditors on public-sector/finance projects.) - protected-mode no # Because we set 'bind *', 'yes' would block external connections.
It looks like a security violation, but Kubernetes has its own isolation, so this setting is fine. - daemonize no # Do not set this to 'yes'.
- requirepass password # 💥Always set a password.
Even in a lab, if the server or PC is on the Internet, set a password.
Redis is not hacked by 🕵️people; 💻programs scan 24 hours a day.
Without a password, even a few minutes of a "dev only" instance can be compromised immediately.
See here for details. 🔗 Redis Hacking
If you configure users.acl, you do not need to set 'requirepass'. - masterauth password # Always set this.
- replica-priority 100 # 📍Redis-0 100, Redis-1 110, Redis-2 120
Injected dynamically from redis-statefulset.yaml initContainer:command. - replica-announce-ip # 📍redis-0.redis-service...
Injected dynamically from redis-statefulset.yaml initContainer:command.
echo "replica-announce-ip redis-$INDEX.redis-service.default.svc.cluster.local" >> /data/redis.conf - users.acl: lines 66–67. The password ('#0cbc...' 64 chars) must be set separately.
See here for details. 🔗 ACL
💾 View redis-sentinel-config.yaml
The values shown here are redis.conf settings that redisGate has applied at 90%+ of more than 100 sites we installed and operate.
(Adjust maxmemory to match your data size)
💻 On physical servers/VMs, change the following values.
- bind 114.x.y.z 127.0.0.1 -::1 -> bind a specific IP
- protected-mode yes
- port -> default 💥port 6379 is a primary hacking target. Always use a different port.
- daemonize yes
- dir /app/redis -> pidfile, logfile, etc. also live under this dir
- aclfile /app/redis/users.acl -> per-user privileges: recommended
- #maxmemory <bytes> -> commented (default)
① On a Redis-dedicated server, set 50%–90% of system memory
② If you have plenty of RAM: e.g. 16GB system memory and Redis using 1–2GB, you do not really need to set it
③ 💥 If Redis consumes all system memory, the OS (Linux) will kill the Redis process. - # replica-announce-ip -> commented (default)
🟢 [Step 2] Service config: redis-sentinel-service.yaml
- Kind: Service
- Name (metadata:name): redis-service / sentinel-service
⚠️ Names are strictly limited to lowercase (a-z), digits (0-9), and hyphens (`-`) (uppercase is not allowed)
- This is the Service spec.
It prepares a network "directory" so you can reach each Redis by a stable domain name
(FQDN: Fully Qualified Domain Name) even when Pod IPs change.
🧑💻 Key values
- clusterIP: None # 📍Set to 'None' (to identify each Pod by DNS)
- port: 18504 # Redis port
- port: 28504 # Sentinel port
💾 View redis-sentinel-service.yaml
🟢 [Step 3-1] Redis Pod manifest: redis-statefulset.yaml
Manifest for Redis Pods (replicas, initContainers, memory, pvc(disk volume)).
- Kind: StatefulSet
- Name: metadata: name: redis
⚠️ Names are limited to lowercase (a-z), digits (0-9), and hyphens (`-`) (uppercase is not allowed)
This name is used to name Pods with a suffix: redis-0,1,2.
Pod name plus serviceName form an FQDN (Fully Qualified Domain Name) as follows.
redis-0.redis-service.default.svc.cluster.local
Each Redis has a unique FQDN for Redis-to-Redis, Sentinel-to-Redis, and Redis/Sentinel-to-App communication. When the IP changes, the new IP is bound to that FQDN.
🧑💻 Key values
- configMap: name: redis-sentinel-config (linked to Step 1 Redis/Sentinel config)
- serviceName: redis-service (linked to Step 2 Service)
- replicas: 3 # Master: 1, Replica: 2 -> replicaof set dynamically
- image: redis:8.8.2 # version 8.8.2 released Monday, August 17, 2026
- imagePullPolicy: IfNotPresent # use the local image
- command script: copy ConfigMap files from Step 1 and apply dynamic settings
- volumeMounts: mountPath: /data: stores all files Redis uses/manages (redis.conf, users.acl, aof files, etc.).
💾 redis-statefulset.yaml
🧑💻 initContainers: command: script
- Extract the Pod index (redis-0 -> 0, redis-1 -> 1, redis-2 -> 2) and use it for per-Pod
dynamic settings.
- Do not copy redis.conf if it already exists. (copy only on first boot)
Redis writes to redis.conf on important events, so on Pod restart you must not overwrite the generated file.
🧑💻 containers: command: script
- Add a few convenient aliases to .bashrc
With '--color=auto', filenames are colored as follows.
dir file: redis-sentinel-model
exec file: cluster_create.sh
tar file: file redis-8.8.2.tar
- The redis.tar timestamps are UTC (UK). Switch to host OS time (Korea time in this lab).
🟢 [Step 3-2] Sentinel Pod manifest: sentinel-statefulset.yaml
Manifest for Sentinel Pods (replicas, initContainers, memory, pvc(disk volume)).
- Kind: StatefulSet
- Name: metadata: name: sentinel
⚠️ Names are limited to lowercase (a-z), digits (0-9), and hyphens (`-`) (uppercase is not allowed)
This name is used to name Pods with a suffix: sentinel-0,1,2.
Pod name plus serviceName form an FQDN (Fully Qualified Domain Name) as follows.
sentinel-0.sentinel-service.default.svc.cluster.local
Each Sentinel has a unique FQDN for Sentinel-to-Sentinel or Sentinel-to-App communication.
When the IP changes, the new IP is bound to that FQDN.
💾 sentinel-statefulset.yaml
➡ Prep is done. Next we create the Pods.
| << K8s Redis-Cluster App ② | K8s Redis-Sentinel Setup ② >> |
|---|
