Helm部署Redis(哨兵)

2023年 10月 5日 143.1k 0

添加Helm仓库

[root@node1 ~]# helm repo add bitnami https://charts.bitnami.com/bitnami

查找Redis相关Chart

[root@node1 ~]# helm search repo redis
NAME                    CHART VERSION   APP VERSION     DESCRIPTION                                       
bitnami/redis           18.1.2          7.2.1           Redis(R) is an open source, advanced key-value ...
bitnami/redis-cluster   9.0.7           7.2.1           Redis(R) is an open source, scalable, distribut...

下载部署Redis使用的Chart

[root@node1 redis]# helm fetch bitnami/redis
[root@node1 redis]# ls
redis-18.1.2.tgz
[root@node1 redis]# 

解压缩

[root@node1 redis]# tar -xf redis-18.1.2.tgz 
[root@node1 redis]# ls
redis  redis-18.1.2.tgz
[root@node1 redis]# cd redis
[root@node1 redis]# ls
Chart.lock  charts  Chart.yaml  img  README.md  templates  values.schema.json  values.yaml
[root@node1 redis]# 

修改values.yaml文件的配置

global:
  imageRegistry: ""
  ## E.g.
  ## imagePullSecrets:
  ##   - myRegistryKeySecretName
  ##
  imagePullSecrets: []
  storageClass: "rook-ceph-block"  # 此处修改为K8s集群上的storageClass名称
  redis:
    password: "pass_123456"        # 连接Redis所使用的密码
    
 
sentinel:
  ## @param sentinel.enabled Use Redis® Sentinel on Redis® pods.
  ## IMPORTANT: this will disable the master and replicas services and
  ## create a single Redis® service exposing both the Redis and Sentinel ports
  ##
  enabled: true  # 开启sentinel哨兵模式 

安装Redis复制集群

[root@node1 redis]# helm install redis . -f values.yaml 
NAME: redis
LAST DEPLOYED: Wed Oct  4 21:06:27 2023
NAMESPACE: default
STATUS: deployed
REVISION: 1
TEST SUITE: None
NOTES:
CHART NAME: redis
CHART VERSION: 18.1.2
APP VERSION: 7.2.1

** Please be patient while the chart is being deployed **

Redis® can be accessed via port 6379 on the following DNS name from within your cluster:

    redis.default.svc.cluster.local for read only operations

For read/write operations, first access the Redis® Sentinel cluster, which is available in port 26379 using the same domain name above.



To get your password run:

    export REDIS_PASSWORD=$(kubectl get secret --namespace default redis -o jsonpath="{.data.redis-password}" | base64 -d)

To connect to your Redis® server:

1. Run a Redis® pod that you can use as a client:

   kubectl run --namespace default redis-client --restart='Never'  --env REDIS_PASSWORD=$REDIS_PASSWORD  --image docker.io/bitnami/redis:7.2.1-debian-11-r0 --command -- sleep infinity

   Use the following command to attach to the pod:

   kubectl exec --tty -i redis-client \
   --namespace default -- bash

2. Connect using the Redis® CLI:
   REDISCLI_AUTH="$REDIS_PASSWORD" redis-cli -h redis -p 6379 # Read only operations
   REDISCLI_AUTH="$REDIS_PASSWORD" redis-cli -h redis -p 26379 # Sentinel access

To connect to your database from outside the cluster execute the following commands:

    kubectl port-forward --namespace default svc/redis 6379:6379 &
    REDISCLI_AUTH="$REDIS_PASSWORD" redis-cli -h 127.0.0.1 -p 6379

查看Pod部署情况

[root@node1 redis]# kubectl get pods 
NAME           READY   STATUS    RESTARTS   AGE
redis-node-0   2/2     Running   0          6m15s
redis-node-1   2/2     Running   0          4m58s
redis-node-2   2/2     Running   0          3m9s

查看Service

[root@node1 redis]# kubectl get svc
NAME             TYPE        CLUSTER-IP     EXTERNAL-IP   PORT(S)              AGE
kubernetes       ClusterIP   10.96.0.1              443/TCP              5d14h
redis            ClusterIP   10.96.225.57           6379/TCP,26379/TCP   8m7s
redis-headless   ClusterIP   None                   6379/TCP,26379/TCP   8m7s

连接测试

kubectl run --namespace default redis-client --restart='Never'  --env REDIS_PASSWORD=$REDIS_PASSWORD  --image docker.io/bitnami/redis:7.2.1-debian-11-r0 --command -- sleep infinity
   
   
[root@node1 redis]#    kubectl exec --tty -i redis-client \
   --namespace default -- bash   
I have no name!@redis-client:/$  redis-cli -h redis-node-0.redis-headless.default.svc.cluster.local -p 6379 -a pass_123456
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
redis-node-0.redis-headless.default.svc.cluster.local:6379> info replication
# Replication
role:master
connected_slaves:2
slave0:ip=redis-node-1.redis-headless.default.svc.cluster.local,port=6379,state=online,offset=68433,lag=0
slave1:ip=redis-node-2.redis-headless.default.svc.cluster.local,port=6379,state=online,offset=68433,lag=1
master_failover_state:no-failover
master_replid:6010cb66d9586e7518d2ec1572b59e8577373bb2
master_replid2:0000000000000000000000000000000000000000
master_repl_offset:68433
second_repl_offset:-1
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:1
repl_backlog_histlen:68433
redis-node-0.redis-headless.default.svc.cluster.local:6379> 

访问redis-node-0.redis-headless.default.svc.cluster.local即可连接到master

更新集群信息

当修改values.yaml文件后,可以使用如下命令修改部署的集群信息

[root@node1 redis]# helm upgrade -f values.yaml redis .

参考文档

  • github.com/bitnami/cha…
  • blog.csdn.net/weixin_4255…
  • www.cnblogs.com/evescn/p/16…

相关文章

JavaScript2024新功能:Object.groupBy、正则表达式v标志
PHP trim 函数对多字节字符的使用和限制
新函数 json_validate() 、randomizer 类扩展…20 个PHP 8.3 新特性全面解析
使用HTMX为WordPress增效:如何在不使用复杂框架的情况下增强平台功能
为React 19做准备:WordPress 6.6用户指南
如何删除WordPress中的所有评论

发布评论