1) Introduction to Redis Redis Operator - jangjaelee/tutorials-redis-operator GitHub Wiki
2022.06. ์ด์ฅ์ฌ ๐ง [email protected] ๐ https://github.com/jangjaelee ๐ http://www.awx.kr
ย
What is Redis?
Redis(Remote Dictionary System)๋ ๋ชจ๋ ๋ฐ์ดํฐ๋ฅผ ๋์คํฌ๋ฅผ ๊ฑฐ์น์ง ์๊ณ ๋ฉ๋ชจ๋ฆฌ(in-memory)๋ก ๋ถ๋ฌ์์ ์ฒ๋ฆฌํ๋ฉฐ, ๋ฉ๋ชจ๋ฆฌ ๊ธฐ๋ฐ์ key-value ๊ตฌ์กฐ์ ๋น์ ํ ๋ฐ์ดํฐ(unstructured data)๋ฅผ ์ ์ฅํ๊ณ ๊ด๋ฆฌํ๊ธฐ ์ํ ์คํ ์์ค ๊ธฐ๋ฐ์ ๋น๊ตฌ์กฐํ ์ฟผ๋ฆฌ ์ธ์ด(NoSQL)์ ์ง์ํ๋ ๋น๊ด๊ณํ ๋ฐ์ดํฐ๋ฒ ์ด์ค ๊ด๋ฆฌ ์์คํ (non-RDBMS)์ ๋๋ค.
๋ํ, Redis๋ in-memory ๋ฐ์ดํฐ ์ ์ฅ์๋ database, cache, message broker ๊ทธ๋ฆฌ๊ณ streaming engie์ผ๋ก ์ฌ์ฉ๋๊ณ ์์ต๋๋ค.
2009๋ Salvatore Sanfilippo(์ด๋ฐํ ๋ฅด ์ฐํ๋ฆฌํฌ)์ ์ํด ANSI C๋ก ์์ฑ ๋์์ผ๋ฉฐ, Linux, BSD ๊ทธ๋ฆฌ๊ณ MacOS์ ๊ฐ์ ๋๋ถ๋ถ์ POSIX ์์คํ ์์ ์ธ๋ถ ์ข ์์ฑ ์์ด ์๋ ํฉ๋๋ค.
2015๋ ๋ถํฐ Redis Labs์์ ์ง์ํ๊ณ ์์ผ๋ฉฐ, BSD License๋ฅผ ๋ฐ๋ฆ
Redis Overview
Redis๋ replication, Lua scripting, LRU eviction, transactions ๊ทธ๋ฆฌ๊ณ ๋ค์ํ ์์ค์ on-disk persistence ๊ธฐ๋ฅ์ ๋ด์ฅํ๊ณ ์์ต๋๋ค. ๊ทธ๋ฆฌ๊ณ Redis Sentinel์ ํตํ ๊ณ ๊ฐ์ฉ์ฑ(High Availability) ๋ฐ Redis Cluster๋ฅผ ํตํ ์๋ ํํฐ์ ๋์ ์ ๊ณต
Redis Data Structures

[์ถ์ฒ] https://askmiddlewareexpert.com/redis-introduction/
ย
Redis Replication vs Sharding
Redis๋ ๋ ๊ฐ์ง ๋ฐ์ดํฐ ๊ณต์ ์ ํ replicaiton(mirroring ์ด๋ผ๊ณ ๋ ํจ)์ ํตํด ๋ฐ์ดํฐ ๋ณต์ ์ sharding(partitioning ์ด๋ผ๊ณ ๋ ํ๋ฉฐ)์ ํตํด ๋ฐ์ดํฐ ๋ถํ ์ ์ง์ ํฉ๋๋ค. ๊ทธ๋ฆฌ๊ณ Redis Cluster๋ ๋ ๊ฐ์ง ๋ฐฉ๋ฒ์ ๋์์ ์ฌ์ฉ ๊ฐ๋ฅํฉ๋๋ค.
Replication
ํ๋ ์ด์์ ์ฌ๋ ์ด๋ธ ๋ ธ๋์ ๋ํ ์์ฒญ์ ํ์ฉํ๊ณ ํด๋น ๋ ธ๋ ์ค ์ผ๋ถ๊ฐ ๋ค์ด๋ ๊ฒฝ์ฐ ๋ฐ์ดํฐ ์ง์์ฑ์ ์ ์งํ์ฌ ๊ณ ๊ฐ์ฉ์ฑ์ ์ ๊ณตํ๋ ํด๋ฌ์คํฐ์ ์ ์ฒด Redis ๋ ธ๋๋ฅผ ์ฒ๋ฆฌํ๋ ๋ฐ์ดํฐ์ ๋๋ค. ์ด ์ ๊ทผ ๋ฐฉ์์ ์ฌ์ฉํ๋ฉด ์ฝ๊ธฐ ์์ฒญ์ด ๋ ๋นจ๋ผ์ง๋๋ค.
- Replication ๋งํฌ(https://redis.io/docs/manual/replication/)
- Redis Cluster master-replica model ๋งํฌ(https://redis.io/docs/manual/scaling/#redis-cluster-master-replica-model)
Sharding
๋ฐ์ดํฐ ๋ถํ ์ ์ฌ์ฉํ๋ฉด ๋ชจ๋ ๋ฐ์ดํฐ๊ฐ ๋ช ๋ถ๋ถ์ผ๋ก ๋ถํ ๋๊ณ ๋ฐ์ดํฐ์ ์ผ๋ถ๋ง ์ ์ฅํ๊ณ ๋ชจ๋ ์์ฒญ์ ์ฒ๋ฆฌํ์ง ์์ผ๋ฏ๋ก ๊ฐ ๋ ธ๋์ ์ฑ๋ฅ์ด ํฅ์ ๋ฉ๋๋ค. ์ด ์ ๊ทผ ๋ฐฉ์์ ์ฌ์ฉํ๋ฉด ์ฐ๊ธฐ ์์ฒญ์ด ๋ ๋นจ๋ผ์ง๋๋ค.
- Redis Cluster data sharding ๋งํฌ(https://redis.io/docs/manual/scaling/#redis-cluster-data-sharding)
ย
Redis Sentinel vs Cluster
Sentinel
Redis v2.4๋ถํฐ ์ง์ํ๋ ๊ธฐ๋ฅ์ผ๋ก ๊ธฐ๋ณธ์ ์ผ๋ก master์ replicas์ ๋ํ ๋ชจ๋ํฐ๋ง ์๋น์ค ์ ๋๋ค.
๋ํ, ์๋ฆผ(notification)์ ๋ณด๋ด๊ณ master๊ฐ ๋ค์ด๋ ๊ฒฝ์ฐ ์๋์ผ๋ก master์ replica์ ์ญํ ์ ์ ํํ ์ ์์ต๋๋ค.
Redis Cluster ์์ด master-replica replication ๊ตฌ์กฐ๋ก ์ฌ์ฉ๋ ๋ ์ฌ์ฉ๋๋ฉฐ, sentinel binary ์ฌ์ฉํ๊ฑฐ๋ ๋๋ redis-server์ sentinel mode์์ dedicated daemon์ผ๋ก ์๋ํฉ๋๋ค.
์๋ก์ด ๋ง์คํฐ ์ ์ถ์ ์ํ ์ฟผ๋ผ์ ๊ฐ์ง๊ณ ์์ผ๋ฉฐ Redis node ์ค ํ๋๊ฐ ๋ค์ด๋๋์ง ๊ฒฐ์ ํ๊ธฐ์ํด ์ต์ 3๊ฐ์ Sentinel instance๊ฐ ์๊ตฌ๋ฉ๋๋ค.
Cluster
Redis v3.0๋ถํฐ ์ง์ํ๋ ๊ธฐ๋ฅ์ผ๋ก ๋ถํ , ๋ณต์ ๋ฐ ๋ ธ๋ ๊ด๋ฆฌ๋ฅผ ์ํ Redis Cluster ์๋ฃจ์ ์ ๋๋ค.
๋ฐ์ดํฐ๋ฅผ ์๋์ผ๋ก ์ฌ๋ฌ ๊ฐ์ Redis node์ ๋ถํ ํ์ฌ ์ ์ฅํ๋ ๋ฐฉ๋ฒ๊ณผ ๊ฐ nodes์ ๋ฐ์ดํฐ ๋ณต์ ๋ฅผ ์ํํ๊ณ ์ผ๋ถ ๋ ธ๋๊ฐ ๋ค์ด๋๊ฑฐ๋ ํต์ ์ง ๋จ์ ๋๋๋ผ๋ ์์ ์ ๊ณ์ํ ์ ์๋ ๊ฐ์ฉ์ฑ ๋ฐ ์ ๊ทผ ์ง์์ฑ์ ์ ๊ณตํฉ๋๋ค. ๋จ ๊ณผ๋ฐ์์ master node๊ฐ ์ฃฝ๋ ๊ฒฝ์ฐ๋ Cluster ๋์์ด ์ค๋จ ๋ฉ๋๋ค.
ย
Redis Operation Mode

[์ถ์ฒ] https://loosie.tistory.com/820
Redis Standalone(One Redis instance)
๋ง ๊ทธ๋๋ก Redis๋ฅผ ๋จ์ผ ์ธ์คํด์ค๋ก ๋์์ํค๋ ๋ฐฉ๋ฒ์ ๋๋ค.

- ์ฅ์
- ๊ฐ์ฅ ๋จ์ํ๊ณ ๊ธฐ๋ณธ์ ์ธ ์ค์ ์ด๋ฉฐ ์คํ ๋ฐ ๊ตฌ์ฑ์ด ๊ฐ๋จํจ
- ๋จ์
- ๋จ์ผ Redis instance๊ฐ ๋ค์ด๋๋ ๊ฒฝ์ฐ ๋ชจ๋ ์ข ์ ์๋น์ค๊ฐ ์ค๋จ๋๋ฉฐ ๊ฐ์ฉ์ฑ ๋๋ ๋ด๊ฒฐํจ์ฑ์ด ์ ๊ณต๋์ง ์์
- ์์ง์ผ๋ก๋ง ํ์ฅ ๊ฐ๋ฅํ์ฌ ํธ์คํธ์ ๋ฆฌ์์ค(CPU ๋ฐ ๋ฉ๋ชจ๋ฆฌ)์ ์ํด ์ ํ์ด ๋ฐ์
Redis Replication(master-replica)
์ค์ ์ด์ ํ๊ฒฝ์์ Cache ์ธ์คํด์ค๋ฅผ ํ๋๋ง ๋๋ ๊ฒ์ ์ํํ๊ธฐ ๋๋ฌธ์ 2๊ฐ์ ์ธ์คํด์ค๋ฅผ ์ฌ์ฉํ์ฌ master-replica ๊ด๊ณ๋ฅผ ๊ตฌ์ถํ์ฌ ๋ฐ ๋ฐ์ดํฐ๋ฅผ ๋จ์ํ ๋ณต์ ์ํค๋ ๋ฐฉ๋ฒ์ ๋๋ค.
Master์์ ๋ฐ์ดํฐ ์ฝ๊ธฐ์ฐ๊ธฐ๊ฐ ๋ฐ์ํ๋ฉด ๋น๋๊ธฐ(asynchronous) ๋ฐฉ์์ผ๋ก replica์ ๋ฐ์ดํฐ๋ฅผ ๋ณต์ ํ๋ฉฐ, ๋ณต์ ๋ณธ์ ์๋ก ํต์ ํ์ง ์์ต๋๋ค.

- ์ฅ์
- ์ค์ ๋ฐ ๊ตฌ์ค์ด ๊ฐ๋จํจ
- ํญ์ ์ต์ ๋ฐ์ดํฐ ์ค๋ ์ท์ ๋ณด์ ํ๊ณ ์์
- ๋จ์
- ์ฐ๊ธฐ(write) ์์ ์ master์ ์ํด ์ ํ๋จ
- master๊ฐ ๋ค์ด๋๋ ๊ฒฝ์ฐ ๋ณต์์ ์ํด์๋ ์๋์ผ๋ก replica๋ฅผ ์ฌ๊ตฌ์ฑํ๊ณ replica๋ฅผ master ์ญํ ๋ก ๋ณ๊ฒฝํด์ผํจ
- replica(๋ณต์ ๋ณธ)์ ํ์ฉ์ฑ์ด ๋จ์ด์ง
Redis Sentinel
Replication(master-replica)์ ์ ์ฌํ์ง๋ง Sentinel mode๋ master node๊ฐ ์ข ๋ฃ๋๋ฉด replica๊ฐ ์๋์ผ๋ก master๋ก ์ ์ถํ์ฌ node๋ฅผ ์น๊ฒฉ์ํค๊ณ ์๋ Failover๋ฅผ ์งํํฉ๋๋ค.

- ์ฅ์
- Redis-Sentinel์ Redis binary์ ๋ด์ฅ๋์ด ์ค์ ์ด ์ฌ์
- ๋งค์ฐ ์์ ์ ์ด๋ฉฐ ์๋ ๋ณต์๋ ฅ ๋ฐ ๊ณ ๊ฐ์ฉ์ฑ ์ ๊ณต
- ๋จ์
- ์ต์ 3๊ฐ์ Sentinel instances๊ฐ ํ์(master ์ ์ถํ ๋ ๋ค์๊ฒฐ ํฌํ๋ฅผ ํ๊ธฐ ์ํจ)
- ๋ฐฉํ๋ฒฝ ์ฌ์ฉ์ Sentinels ๊ฐ์ ํต์ ์ ์ํด ๋ฐฉํ๋ฒฝ์ ๊ตฌ์ฑ์ ํด์ผํจ
- client๊ฐ Redis-Sentinel์ ๋ฐ๋์ ์ง์ํด์ผ sentinel ์ํ์ ๋ชจ๋ํฐ๋ง ๋ฐ ๋ง์คํฐ ์ ๋ณด๋ฅผ ์กฐํํ ์ ์์
Redis Cluster
Redis Cluster๋ Redis๊ฐ ์์ฒด์ ์ผ๋ก ์ง์ํ๋ ํด๋ฌ์คํฐ๋ง ์์คํ ์ผ๋ก ์ฌ๋ฌ Redis node์ ๋ฐ์ดํฐ๋ฅผ ์๋์ผ๋ก sharding ํด์ฃผ๋ ๊ธฐ์ ์ ๋๋ค.
๋ํ, ์ ์ฒด ๋ ธ๋ ์ค ์ผ๋ถ์ ์ฅ์ ๊ฐ ๋ฐ์ํ๊ฑฐ๋ ๋๋จธ์ง ํด๋ฌ์คํฐ์ ํต์ ํ ์ ์๋ ๊ฒฝ์ฐ์๋ ์กฐ์ํ ์ ์๋ ๊ธฐ๋ฅ์ ์ ๊ณตํ๋ฉฐ, ๋ถ์ฐ ์คํ ๋ฆฌ์ง๋ฅผ ๊ตฌํํ๊ณ ๋จ์ผ ์ฅ์ ์ง์ (SPOF)๋ฅผ ๋ฐฉ์งํฉ๋๋ค.

- ์ฅ์
- ํด๋ฌ์คํฐ ๋จ์์ ๊ณ ๊ฐ์ฉ์ฑ(HA) ๊ตฌ์ฑ (Master Cluster / Replica Cluster)
- ์ต๋ 1,000๋ ๊น์ง ํ์ฅ์ฑ์ ์ ๊ณต
- ๋ฐ์ดํฐ๋ ์ฌ๋กฏ ์ ์ฅ์ ๋ฐ๋ผ ์ฌ๋ฌ ๋ ธ๋์ ๋ถ์ฐ๋์ด ์์ผ๋ฉฐ, ๋ ธ๋ ์ค ๋ฐ์ดํฐ ๊ณต์ ๋ฐ ๋ถํฌ๋ ๋์ ์ผ๋ก ์กฐ์ ๊ฐ๋ฅ
- ์ด์ ๋ฐ ์ ์ง ๊ด๋ฆฌ ๋น์ฉ์ ์ค์ด๊ณ ์์คํ ํ์ฅ์ฑ๊ณผ ๊ฐ์ฉ์ฑ์ด ํฅ์๋จ
- ๋จ์
- ์์ ์ ์ธ ํด๋ฌ์คํฐ๋ฅผ ์ํด์๋ ์ต์ 6๊ฐ์ nodes๊ฐ ํ์ (3๊ฐ ์ด์์ master, 3๊ฐ ์ด์์ replica)
- ๊ท ์ผํ ๋ณต์๋ ฅ์ ๊ฐ์ง๋ ค๋ฉด ๋ง์คํฐ๋น ๋์ผํ ์์ ๋ณต์ ๋ณธ์ด ํ์
- ๋ฐ์ดํฐ๋ ๋น๋๊ธฐ ๋ฐฉ์์ผ๋ก ๋ณต์ ๋๋ฉฐ ๊ฐ๋ ฅํ ๋ฐ์ดํฐ ์ผ๊ด์ฑ์ ๋ณด์ฅํ์ง๋ ์์
- Redis Cluster๋ฅผ ์ง์ํ๋ client๋ฅผ ์ฌ์ฉํด์ผ shard์ ๋ง๋ ๋ฐ์ดํฐ ์ ๊ทผ์ด ๊ฐ๋ฅ
- Redis Cluster๋ ์ค์ง 0๋ฒ ๋ฐ์ดํฐ๋ฒ ์ด์ค๋ง ์ฌ์ฉ ๊ฐ๋ฅ(๋จ์ผ ์ธ์คํด์ค ์ฒ๋ผ 0~15์ ๋ณต์์ ๋ฐ์ดํฐ๋ฒ ์ด์ค ์ฌ์ฉ ๋ถ๊ฐ)
๐ย Redis replication vs sharding, sentinel vs cluster, topology๋ ์ด ํฌ์คํธ๋งํฌ(https://www.notion.so/Redis-Operator-for-Redis-Sentinel-by-spotahome-b8f56625ac8d497d8908b352f240b170)์ ๋ด์ฉ์ ๋ฒ์ญ ํ์ต๋๋ค.
ย
What is Redis Operator for Kubernetes?
Redis Operator๋ custom resource์ ๋ํ custom controller ์ญํ ์ ํ๋ฉฐ, Redis Server๋ K8s CRD(custom resource definition)๋ฅผ ํตํด ์ ์๋๊ณ YAMLํ์ผ๊ณผ ํจ๊ป ๋ฐฐํฌ๋ฉ๋๋ค.
Kubernetes Cluster์์ ์ฌ์ฉ ๊ฐ๋ฅํ Redis Operator๋ ๋ค์ํ ์ข ๋ฅ๊ฐ ์์ผ๋ฉฐ Open Source๋ก ์ฌ์ฉ๊ฐ๋ฅํ Redis Community์ Redis Labs์ Redis Enterprise๋ฅผ ์ง์ํ๋ Operator๊ฐ ๊ฐ๊ฐ ์์ต๋๋ค.
Redis Community์์ ์ฃผ๋ก ์ฌ์ฉ ๊ฐ๋ฅํ Redis Operator๋ ๋๊ฐ๊ฐ ์์ผ๋ฉฐ, Spotahome์ Redis Sentinel์ ์ง์ํ๋ ๊ฒ๊ณผ Opstree์ Redis Cluster๋ฅผ ์ง์ํ๋ ๊ฒ์ด ์์ต๋๋ค.
- Redis Community
-
Redis Operator for Redis Sentinel (by spotahome) - GitHub ๋งํฌ(https://github.com/spotahome/redis-operator)

-
Redis Operator for Redis Cluster (by opstree) - GitHub ๋งํฌ(https://github.com/OT-CONTAINER-KIT/redis-operator), Doc ๋งํฌ(https://ot-container-kit.github.io/redis-operator/)

-
ย
- Redis Enterprise
-
Redis Enterprise Operator - GitHub ๋งํฌ(https://github.com/RedisLabs/redis-enterprise-k8s-docs), Doc ๋งํฌ(https://docs.redis.com/latest/kubernetes/architecture/operator/)

-
ย
Kakao์์๋ Kubernetes ์์ Redis Cluster๋ฅผ ๊ตฌ์ถํ๊ธฐ ์ํ kredis Operator ๊ฐ๋ฐํ์ฌ ์ฌ์ฉํ๊ธฐ๋ ํฉ๋๋ค.
- Kakao๊ฐ Kubernetes์ Redis Cluster๋ฅผ Operator๋ก ๊ฐ๋ฐํ์ฌ ๊ตฌ์ถํ ์ฌ๋ก kredis ๋งํฌ(https://tech.kakao.com/2022/02/09/k8s-redis/)
- ๋ฐ๋ชจ ์์ฐ ๋์์ - https://tv.kakao.com/channel/3693125/cliplink/423589917
์คํ ์์ค Redis Operator๋ ์ค์ ๊ฐ ์ ์์ฌ์์ Production ํ๊ฒฝ์์ ์ฌ์ฉํ๊ณ ์๋ค๊ณ ํ์ง๋ง Production ํ๊ฒฝ์์ ๋์ ์ ์ํด์๋ ์ถฉ๋ถํ ํ ์คํธ๊ฐ ํ์ํ๋ฉฐ ๋์ ์ ๋ฐ์ํ๋ ์ฑ ์๊ณผ ๋ฐฐ์์ ๋ํ ๊ถ๋ฆฌ ๋ฐ ์๋ฌด๋ ์ฌ์ฉ์์๊ฒ ์์์ ์๋ฆฝ๋๋ค.
ย
Reference
- Redis ์๊ฐ ๋ฐ ๊ธฐ๋ณธ ๊ฐ๋ ์ ๋ฆฌ ๋งํฌ(https://ryu-e.tistory.com/9)
- Redis Cluster ์์ํ๊ธฐ ๋งํฌ(https://sup2is.github.io/2020/07/22/redis-cluster.html)
- Redis Architecture Overview ๋งํฌ(http://redisgate.kr/redis/configuration/redis_overview.php)
- Redis Sharding ๋งํฌ(https://cla9.tistory.com/102)
- Redis replication vs sharding, sentinel vs cluster, topology ๋งํฌ(https://rtfm.co.ua/en/redis-replication-part-1-overview-replication-vs-sharding-sentinel-vs-cluster-redis-topology/)
- Redis Cluster: Architecture, Replication, Sharding and Failover ๋งํฌ(https://blog.opstree.com/2019/10/22/redis-cluster-architecture-replication-sharding-and-failover/)
- Redis sentinel & cluster ์ฐจ์ด์ ๊ทธ๋ฆฌ๊ณ about Redis ๋งํฌ(https://coding-start.tistory.com/128)
- Redis Operation Mode ๋งํฌ(https://blog.octo.com/en/what-redis-deployment-do-you-need/)
- Redis Cluster Tutorial ๋งํฌ(https://medium.com/garimoo/redis-documentation-2-%EB%A0%88%EB%94%94%EC%8A%A4-%ED%81%B4%EB%9F%AC%EC%8A%A4%ED%84%B0-%ED%8A%9C%ED%86%A0%EB%A6%AC%EC%96%BC-911ba145e63)
- Redis Cluster๋ฅผ ์ฌ์ฉํ๋ 5๊ฐ์ง ๋ฐฉ๋ฒ ๋ฐ ์ฅ๋จ์ ๋น๊ต ๋ถ์ ๋งํฌ(https://daydaynews.cc/en/technology/321901.html)
- Redis ์ด์ ๋ฐฉ์ : Cluster vs Sentinel ์ด๋ค ๊ฒ์ ์ ํํด์ผ ํ ๊ฐ? ๋งํฌ(https://velog.io/@always/Redis-์ด์-๋ฐฉ์-Cluster-vs-Sentinel-์ด๋ค-๊ฒ์-์ ํํด์ผ-ํ ๊น)
- ์ฐ์ํ Redis ๋ฆฌ๋ทฐ ๋งํฌ(https://velog.io/@litien/%EB%A6%AC%EB%B7%B0-%EC%9A%B0%EC%95%84%ED%95%9C-Redis)
ย
END