Helm部署redis集群

597 阅读3分钟

添加helm仓库

# 添加bitnami仓库
[root@master redis]# helm repo add bitnami https://charts.bitnami.com/bitnami
"bitnami" already exists with the same configuration, skipping

# 查看所有的仓库
[root@master redis]# helm repo list
NAME            URL                                      
appscode        https://charts.appscode.com/stable/      
harbor          https://helm.goharbor.io                 
kvaps           https://kvaps.github.io/charts           
stable          http://mirror.azure.cn/kubernetes/charts/
bitnami         https://charts.bitnami.com/bitnami

查找redis Chart

[root@master redis]# helm search repo redis
NAME                                    CHART VERSION   APP VERSION     DESCRIPTION                                       
appscode/redis-alerts                   v2023.05.09     v0.2.0          A Helm chart for Redis Alert by AppsCode          
bitnami/redis                           18.0.4          7.2.1           Redis(R) is an open source, advanced key-value ...
bitnami/redis-cluster                   9.0.5           7.2.1           Redis(R) is an open source, scalable, distribut...
stable/prometheus-redis-exporter        3.5.1           1.3.4           DEPRECATED Prometheus exporter for Redis metrics  
stable/redis                            10.5.7          5.0.7           DEPRECATED Open source, advanced key-value stor...
stable/redis-ha                         4.4.6           5.0.6           DEPRECATED - Highly available Kubernetes implem...
stable/sensu                            0.2.5           0.28            DEPRECATED Sensu monitoring framework backed by...

下载bitnami的redis Chart包

[root@master redis]# helm fetch bitnami/redis-cluster
[root@master redis]# ls
redis-cluster-9.0.5.tgz

解压缩并进入目录

[root@master redis]# tar -xf redis-cluster-9.0.5.tgz 
[root@master redis]# cd redis-cluster/
[root@master redis-cluster]# 

修改values.yaml中的一些变量

# 修改下其中的密码和默认的storageclass
global:
  imageRegistry: ""
  ## E.g.
  ## imagePullSecrets:
  ##   - myRegistryKeySecretName
  ##
  imagePullSecrets: []
  storageClass: "rook-ceph-block"
  redis:
    password: "pass_12345678"

创建命名空间

后面使用helm部署的话将资源都创建在namespace下

[root@master redis-cluster]# kubectl create ns redis
namespace/redis created

使用helm部署redis集群

# -n 指定名称空间
# . 表示使用当前修改后的Chart进行部署
[root@master redis-cluster]# helm install redis-cluster . -n redis

查看部署情况

[root@node1 redis-cluster]# kubectl get pods -n redis -owide
NAME              READY   STATUS    RESTARTS      AGE    IP            NODE      NOMINATED NODE   READINESS GATES
redis-cluster-0   1/1     Running   1 (39s ago)   109s   10.244.6.3    desktop   <none>           <none>
redis-cluster-1   1/1     Running   1 (42s ago)   109s   10.244.4.22   node4     <none>           <none>
redis-cluster-2   1/1     Running   1 (16s ago)   109s   10.244.5.15   node5     <none>           <none>
redis-cluster-3   1/1     Running   2 (7s ago)    109s   10.244.1.78   node2     <none>           <none>
redis-cluster-4   1/1     Running   1 (39s ago)   109s   10.244.3.56   node3     <none>           <none>
redis-cluster-5   1/1     Running   0             109s   10.244.0.60   node      <none>           <none>

测试连接

# 查看Service的IP
[root@node1 redis-cluster]# kubectl get service -n redis
NAME                     TYPE        CLUSTER-IP     EXTERNAL-IP   PORT(S)              AGE
redis-cluster            ClusterIP   10.103.8.250   <none>        6379/TCP             90s
redis-cluster-headless   ClusterIP   None           <none>        6379/TCP,16379/TCP   90s

# 先不用密码连接测试操作失败
[root@node1 ~]# redis-cli -c -h 10.103.8.250 
10.110.217.13:6379> 
10.110.217.13:6379> 
10.110.217.13:6379> info
NOAUTH Authentication required.
10.110.217.13:6379> 

# 使用密码登陆,可以获取到集群信息
# -c 参数为开启集群模式
# -h 指定连接哪个redis
# -a 指定密码
[root@node1 ~]# redis-cli -c -h 10.103.8.250  -a pass_12345678
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
10.110.217.13:6379> info
# Server
redis_version:7.2.1
redis_git_sha1:00000000
redis_git_dirty:0
redis_build_id:ed7eac84dd41e25a
redis_mode:cluster
os:Linux 5.14.0-284.30.1.el9_2.x86_64 x86_64
arch_bits:64
monotonic_clock:POSIX clock_gettime
multiplexing_api:epoll
atomicvar_api:c11-builtin
gcc_version:10.2.1
process_id:1

更新redis集群的密码

修改values.yaml文件

global:
  imageRegistry: ""
  ## E.g.
  ## imagePullSecrets:
  ##   - myRegistryKeySecretName
  ##
  imagePullSecrets: []
  storageClass: "rook-ceph-block"  # 修改为自己服务器上的StorageClass名称
  redis:
    password: "pass_12345678"  # 这里修改为新的密码

更新密码

# 注意修改密码的时候要使用--set password=123456指定以前的密码才能操作成功
# 更新密码过程中会重新创建pod,过程可能会比较慢
helm upgrade redis-cluster bitnami/redis-cluster  -f values.yaml -n redis --set password=pass_12345678

测试

# 使用新的密码可以登陆了
[root@node1 ~]# redis-cli -c -h 10.103.8.250 -a new_password
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
10.103.8.250:6379> info
# Server
redis_version:7.2.1
redis_git_sha1:00000000
redis_git_dirty:0
redis_build_id:ed7eac84dd41e25a

参考链接