{"id":13463735,"url":"https://github.com/sobotklp/kubernetes-redis-cluster","last_synced_at":"2025-03-25T09:31:00.597Z","repository":{"id":44894829,"uuid":"62984723","full_name":"sobotklp/kubernetes-redis-cluster","owner":"sobotklp","description":"Redis Cluster on Kubernetes","archived":false,"fork":false,"pushed_at":"2024-06-24T15:38:44.000Z","size":16,"stargazers_count":160,"open_issues_count":2,"forks_count":80,"subscribers_count":9,"default_branch":"master","last_synced_at":"2024-12-18T19:47:10.594Z","etag":null,"topics":["kubernetes","redis-cluster"],"latest_commit_sha":null,"homepage":null,"language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sobotklp.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-07-10T06:13:04.000Z","updated_at":"2024-10-30T12:43:43.000Z","dependencies_parsed_at":"2024-10-29T14:31:21.242Z","dependency_job_id":null,"html_url":"https://github.com/sobotklp/kubernetes-redis-cluster","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sobotklp%2Fkubernetes-redis-cluster","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sobotklp%2Fkubernetes-redis-cluster/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sobotklp%2Fkubernetes-redis-cluster/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sobotklp%2Fkubernetes-redis-cluster/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sobotklp","download_url":"https://codeload.github.com/sobotklp/kubernetes-redis-cluster/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245435075,"owners_count":20614823,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["kubernetes","redis-cluster"],"created_at":"2024-07-31T14:00:27.724Z","updated_at":"2025-03-25T09:31:00.270Z","avatar_url":"https://github.com/sobotklp.png","language":"Shell","funding_links":[],"categories":["Tools","Shell"],"sub_categories":[],"readme":"# Redis Cluster on Kubernetes\n\nThis module is intended to simplify the creation and operation of a Redis Cluster deployment in Kubernetes.\nI don't recommend that you run this in production - it's just meant to be an illustrative example of a nontrivial Stateful Set deployment.\n\n## Requirements\n\n- Kubernetes 1.17.0+\n- Minikube to run the module locally\n\n## How it works\n\nThese directions assume some familiarity with [Redis Cluster](http://redis.io/topics/cluster-tutorial). \n\nWhen you create the resources in Kubernetes, it will create a 6-member (the minimum recommended size) [Stateful Set](https://kubernetes.io/docs/concepts/workloads/controllers/statefulsets/) cluster where members 0-2 are master nodes and all other members are replicas.\n\n## Testing it out\n\nTo launch the cluster, have Kubernetes create all the resources in redis-cluster.yml:\n\n```\n$ kubectl create -f redis-cluster.yml\nservice/redis-cluster created\nconfigmap \"redis-cluster-config\" configured\npoddisruptionbudget.policy/redis-cluster-pdb created\nstatefulset.apps/redis-cluster created\n```\n\nWait a bit for the service to initialize.\n\nOnce all the pods are initialized, you can see that Pod \"redis-cluster-0\" became the cluster master with the other nodes as slaves.\n\n```\n$ kubectl exec redis-cluster-0 -- redis-cli cluster nodes\nDefaulted container \"redis-cluster\" out of: redis-cluster, init-redis-cluster (init)\n532505ce41c64ddf4aff143406eb90424c29c138 10.1.0.136:6379@16379 myself,master - 0 1642662784000 1 connected 0-5461\n1f188afd5f2a228320cc43753e4b6a1c01c32445 10.1.0.139:6379@16379 slave 532505ce41c64ddf4aff143406eb90424c29c138 0 1642662785392 1 connected\n07939f1e633cd3538f8730017aa5ce1d0f8ba680 10.1.0.140:6379@16379 slave de3b3a6d02c81f4104566828e8a523b46e31cd02 0 1642662785000 0 connected\nde3b3a6d02c81f4104566828e8a523b46e31cd02 10.1.0.137:6379@16379 master - 0 1642662784386 0 connected 5462-10922\nc53e989fa503b04ecc7c651f448a7fc07ac3c975 10.1.0.138:6379@16379 master - 0 1642662786399 2 connected 10923-16383\na43a4a9d81ae095bfdd373ed2c9aebbe958d086a 10.1.0.141:6379@16379 slave c53e989fa503b04ecc7c651f448a7fc07ac3c975 0 1642662784000 2 connected\n```\n\nAlso, you should be able to use redis-cli to connect to a cluster node we just created\n```\n$ kubectl exec -it redis-cluster-0 -- redis-cli\n```\n\nYou can also check the slot configuration here:\n```\n$ kubectl exec redis-cluster-0 -- redis-cli --cluster check localhost 6379\nDefaulted container \"redis-cluster\" out of: redis-cluster, init-redis-cluster (init)\nlocalhost:6379 (55a74f86...) -\u003e 0 keys | 5462 slots | 1 slaves.\n10.1.0.126:6379 (f5b39569...) -\u003e 0 keys | 5461 slots | 1 slaves.\n10.1.0.125:6379 (742cf86e...) -\u003e 0 keys | 5461 slots | 1 slaves.\n[OK] 0 keys in 3 masters.\n0.00 keys per slot on average.\n\u003e\u003e\u003e Performing Cluster Check (using node localhost:6379)\nM: 55a74f86cf241a90f66a94a6c1789e031adbcc0c localhost:6379\n   slots:[0-5461] (5462 slots) master\n   1 additional replica(s)\nM: f5b39569a75fe72cb16e207f2947d22c625a39ab 10.1.0.126:6379\n   slots:[10923-16383] (5461 slots) master\n   1 additional replica(s)\nS: ddea6fbe8baa7938504f9f1ff503f0f190b49bc3 10.1.0.127:6379\n   slots: (0 slots) slave\n   replicates 55a74f86cf241a90f66a94a6c1789e031adbcc0c\nM: 742cf86e53a93473d17d352d2100b7db9dc61b72 10.1.0.125:6379\n   slots:[5462-10922] (5461 slots) master\n   1 additional replica(s)\nS: 054f92cfb064e5cd762e466799311fbc21228049 10.1.0.128:6379\n   slots: (0 slots) slave\n   replicates 742cf86e53a93473d17d352d2100b7db9dc61b72\nS: ccc463f1aa52c9afd12aa945d7869c2a44f81c9d 10.1.0.129:6379\n   slots: (0 slots) slave\n   replicates f5b39569a75fe72cb16e207f2947d22c625a39ab\n[OK] All nodes agree about slots configuration.\n\u003e\u003e\u003e Check for open slots...\n\u003e\u003e\u003e Check slots coverage...\n[OK] All 16384 slots covered.\n```\n\nTo add more nodes to the cluster, you can simply use normal stateful set scaling:\n```\nkubectl scale -n default statefulset redis-cluster --replicas=12\n```\nNewly-created nodes will join the cluster as replicas.\n\n\nTo clean this mess off your Minikube VM:\n```\n$ kubectl delete service,statefulsets redis-cluster\n$ kubectl delete configmaps redis-cluster-config\n$ kubectl delete poddisruptionbudgets.policy redis-cluster-pd\n\n# To prevent potential data loss, deleting a statefulset doesn't delete the pods. Gotta do that manually.\n$ kubectl delete pod redis-cluster-0 redis-cluster-1 redis-cluster-2 redis-cluster-3 redis-cluster-4 redis-cluster-5\n```\n\n## TODO\n- Add documentation for common Redis Cluster operations: adding nodes, resharding, deleting nodes\n- Test some failure scenarios\n- Use a persistentvolume to store backup files\n- Create a ScheduledJob to do automated backups once [this feature](https://github.com/antirez/redis/issues/2463) is finished.\n- Make it easier to assign new masters\n- Cluster members should check whether nodes.conf exists and if so, skip pod initialization.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsobotklp%2Fkubernetes-redis-cluster","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsobotklp%2Fkubernetes-redis-cluster","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsobotklp%2Fkubernetes-redis-cluster/lists"}