如何在 Kubernetes 上部署 Redis 集群
我们非常重视原创文章,为尊重知识产权并避免潜在的版权问题,我们在此提供文章的摘要供您初步了解。如果您想要查阅更为详尽的内容,访问作者的公众号页面获取完整文章。
Redis Deployment on Kubernetes Overview
Redis is a versatile open-source platform with a range of use cases including running as a primary database, serving as a message broker, or caching website content. Running Redis on Kubernetes enhances its capabilities by simplifying deployment and improving reliability and performance.
Prerequisites for Deploying Redis on Kubernetes
Before deploying Redis on Kubernetes, the following conditions must be met:
- A Kubernetes cluster compatible with any modern Kubernetes distribution.
- Helm, the package manager for Kubernetes, must be installed to install Redis. Installation options can be found in the Helm documentation if it is not already installed on your system.
- Basic familiarity with Kubernetes is required, although in-depth expertise is not necessary. Knowledge of kubectl and Helm is important.
Deployment Steps
Step 1: Install Redis Helm
To install Redis, use the Redis Helm chart by running the command helm install my-release oci://registry-1.docker.io/bitnamicharts/redis-cluster
.
Step 2: Verify Redis Pod Status
After installing the Helm chart, verify that the Redis Pods are running with the command kubectl get pods --all-namespaces
. Initially, the Pods will be in the ContainerCreating status but should transition to Running within a few minutes.
Step 3: Export Cluster Password
Export the cluster password as an environment variable using the command export REDIS_PASSWORD=$(kubectl get secret --namespace "default" my-release-redis-cluster -o jsonpath="{.data.redis-password}" | base64 -d)
to connect to the newly installed Redis cluster.
Step 4: Start a Redis Client Container
Launch a new container to host the Redis client with the command kubectl run --namespace default my-release-redis-cluster-client --rm --tty -i --restart='Never' --env REDIS_PASSWORD=$REDIS_PASSWORD --image docker.io/bitnami/redis-cluster:7.2.4-debian-12-r11 -- bash
.
Step 5: Connect to the Cluster
Once in the client container, connect to the cluster using redis-cli -c -h my-release-redis-cluster -a $REDIS_PASSWORD
. At the command prompt, you can interact with the Redis cluster, and running the command CLUSTER INFO
should output the current state and statistics of the cluster.
想要了解更多内容?
白皮书上线