helm部署redis-culster集群
安装helm
wget https://repo.huaweicloud.com/helm/v3.8.0/helm-v3.8.0-linux-amd64.tar.gz
tar -zxf helm-v3.8.0-linux-amd64.tar.gz
mv linux-amd64/helm /usr/local/bin/helm
helm version
添加仓库
#添加 bitnami仓库
helm repo add bitnami https://charts.bitnami.com/bitnami
#查看仓库
[root@master ~]# helm repo list
NAME URL
bitnami https://charts.bitnami.com/bitnami
#删除仓库
[root@master ~]# helm repo remove bitnami
"bitnami" has been removed from your repositories
下载char包
#查找需要的char应用包
[root@master ~]# helm search repo redis
NAME CHART VERSION APP VERSION DESCRIPTION
bitnami/redis 17.1.8 7.0.5 Redis(R) is an open source, advanced key-value ...
bitnami/redis-cluster 8.2.4 7.0.5 Redis(R) is an open source, scalable, distribut...
#下载char包
[root@master ~]# helm pull bitnami/redis-cluster
#这样我们就在当前目录下得到了一个redis-cluster-8.2.4.tgz的压缩包
[root@master ~]# ll redis-cluster-8.2.4.tgz
-rw-r--r-- 1 root root 106744 9月 22 16:15 redis-cluster-8.2.4.tgz
#解压压缩包并进入
[root@master ~]# tar -zxf redis-cluster-8.2.4.tgz && cd redis-cluster
[root@master redis-cluster]#
#我们查看下目录结构
[root@master redis-cluster]# tree .
.
├── Chart.lock
├── charts
│ └── common
│ ├── Chart.yaml
│ ├── README.md
│ ├── templates
│ │ ├── _affinities.tpl
│ │ ├── _capabilities.tpl
│ │ ├── _errors.tpl
│ │ ├── _images.tpl
│ │ ├── _ingress.tpl
│ │ ├── _labels.tpl
│ │ ├── _names.tpl
│ │ ├── _secrets.tpl
│ │ ├── _storage.tpl
│ │ ├── _tplvalues.tpl
│ │ ├── _utils.tpl
│ │ ├── validations
│ │ │ ├── _cassandra.tpl
│ │ │ ├── _mariadb.tpl
│ │ │ ├── _mongodb.tpl
│ │ │ ├── _mysql.tpl
│ │ │ ├── _postgresql.tpl
│ │ │ ├── _redis.tpl
│ │ │ └── _validations.tpl
│ │ └── _warnings.tpl
│ └── values.yaml
├── Chart.yaml
├── img
│ ├── redis-cluster-topology.png
│ └── redis-topology.png
├── README.md
├── templates
│ ├── configmap.yaml
│ ├── extra-list.yaml
│ ├── headless-svc.yaml
│ ├── _helpers.tpl
│ ├── metrics-prometheus.yaml
│ ├── metrics-svc.yaml
│ ├── networkpolicy.yaml
│ ├── NOTES.txt
│ ├── poddisruptionbudget.yaml
│ ├── prometheusrule.yaml
│ ├── psp.yaml
│ ├── redis-rolebinding.yaml
│ ├── redis-role.yaml
│ ├── redis-serviceaccount.yaml
│ ├── redis-statefulset.yaml
│ ├── redis-svc.yaml
│ ├── scripts-configmap.yaml
│ ├── secret.yaml
│ ├── svc-cluster-external-access.yaml
│ ├── tls-secret.yaml
│ └── update-cluster.yaml
└── values.yaml
6 directories, 49 files
配置
我们主要是需要配置values.yaml里面的内容,将storageClass改为我们使用的持久化存储名称
global:
imageRegistry: ""
## E.g.
## imagePullSecrets:
## - myRegistryKeySecretName
##
imagePullSecrets: []
storageClass: "managed-nfs-storage" #持久化存储
redis:
password: ""
部署
首先创建需要部署到的命名空间,这里我们使用的是redis命名空间
[root@master redis-cluster]# kubectl create ns redis
namespace/redis created
接下来我们部署redis-cluster,安装是异步的,也就是这里提示的只是成功的将chart发布到了k8s中,应用的部署还需要时间
[root@master redis-cluster]# kubectl create ns redis
namespace/redis created
[root@master redis-cluster]# helm install redis-cluster bitnami/redis-cluster -f values.yaml -n redis
NAME: redis-cluster
LAST DEPLOYED: Thu Sep 22 16:25:49 2022
NAMESPACE: redis
STATUS: deployed
REVISION: 1
TEST SUITE: None
NOTES:
CHART NAME: redis-cluster
CHART VERSION: 8.2.4
APP VERSION: 7.0.5** Please be patient while the chart is being deployed **
To get your password run:
export REDIS_PASSWORD=$(kubectl get secret --namespace "redis" redis-cluster -o jsonpath="{.data.redis-password}" | base64 -d)
You have deployed a Redis® Cluster accessible only from within you Kubernetes Cluster.INFO: The Job to create the cluster will be created.To connect to your Redis® cluster:
1. Run a Redis® pod that you can use as a client:
kubectl run --namespace redis redis-cluster-client --rm --tty -i --restart='Never' \
--env REDIS_PASSWORD=$REDIS_PASSWORD \
--image docker.io/bitnami/redis-cluster:7.0.5-debian-11-r0 -- bash
2. Connect using the Redis® CLI:
redis-cli -c -h redis-cluster -a $REDIS_PASSWORD
稍等几分钟后我们可以看到所有pod已经成功运行
[root@master redis-cluster]# kubectl get pod -n redis
NAME READY STATUS RESTARTS AGE
redis-cluster-0 1/1 Running 1 (22s ago) 83s
redis-cluster-1 1/1 Running 1 (50s ago) 83s
redis-cluster-2 1/1 Running 1 (22s ago) 83s
redis-cluster-3 1/1 Running 1 (21s ago) 83s
redis-cluster-4 1/1 Running 1 (21s ago) 83s
redis-cluster-5 1/1 Running 1 (19s ago) 83s
验证
首先我们先获取默认生成的密码
[root@master redis-cluster]# export REDIS_PASSWORD=$(kubectl get secret --namespace "redis" redis-cluster -o jsonpath="{.data.redis-password}" | base64 -d)
[root@master redis-cluster]# echo $REDIS_PASSWORD
USX6SZmvla
然后我们重新打开一个终端
[root@master redis-cluster]# kubectl run --namespace redis redis-cluster-client --rm --tty -i --restart='Never' \
> --env REDIS_PASSWORD=$REDIS_PASSWORD \
> --image docker.io/bitnami/redis-cluster:7.0.5-debian-11-r0 -- bash
If you don't see a command prompt, try pressing enter.
I have no name!@redis-cluster-client:/$
进入到容器之后我们使用刚才获取的密码连接redis,可以看到没有问题,至此redis-culster部署完成
I have no name!@redis-cluster-client:/$ redis-cli -c -h redis-cluster -a USX6SZmvla
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
redis-cluster:6379> info
# Server
redis_version:7.0.5
redis_git_sha1:00000000
redis_git_dirty:0
redis_build_id:150190119493720b
redis_mode:cluster
os:Linux 3.10.0-957.el7.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
process_supervised:no
run_id:2d4e67b93ae0228cd04b1a0505342f5a9cc142a9
tcp_port:6379
server_time_usec:1663835550883712
自定义配置
刚才的连接密码是redis自动帮我们生成的,现在我想使用固定的密码,我们再次修改values.yaml文件
global:
imageRegistry: ""
## E.g.
## imagePullSecrets:
## - myRegistryKeySecretName
##
imagePullSecrets: []
storageClass: "managed-nfs-storage" #持久化存储
redis:
password: "123456" #自定义密码配置
更新配置,注意这里需要我们使用当前的redis密码 --set password=USX6SZmvla
[root@master redis-cluster]# helm upgrade redis-cluster bitnami/redis-cluster -f values.yaml -n redis --set password=USX6SZmvla
Release "redis-cluster" has been upgraded. Happy Helming!
NAME: redis-cluster
LAST DEPLOYED: Thu Sep 22 16:38:46 2022
NAMESPACE: redis
STATUS: deployed
REVISION: 2
TEST SUITE: None
NOTES:
CHART NAME: redis-cluster
CHART VERSION: 8.2.4
APP VERSION: 7.0.5** Please be patient while the chart is being deployed **
To get your password run:
export REDIS_PASSWORD=$(kubectl get secret --namespace "redis" redis-cluster -o jsonpath="{.data.redis-password}" | base64 -d)
You have deployed a Redis® Cluster accessible only from within you Kubernetes Cluster.INFO: The Job to create the cluster will be created.To connect to your Redis® cluster:
1. Run a Redis® pod that you can use as a client:
kubectl run --namespace redis redis-cluster-client --rm --tty -i --restart='Never' \
--env REDIS_PASSWORD=$REDIS_PASSWORD \
--image docker.io/bitnami/redis-cluster:7.0.5-debian-11-r0 -- bash
2. Connect using the Redis® CLI:
redis-cli -c -h redis-cluster -a $REDIS_PASSWORD
稍等几分钟,pod需要重新启动后我们再次验证
I have no name!@redis-cluster-client:/$ redis-cli -c -h redis-cluster -a 123456
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
redis-cluster:6379> info
# Server
redis_version:7.0.5
redis_git_sha1:00000000
redis_git_dirty:0
redis_build_id:150190119493720b
redis_mode:cluster
os:Linux 3.10.0-957.el7.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
process_supervised:no
run_id:309ab65b46372140b1a45d158182f8756bc72dc4
tcp_port:6379
server_time_usec:1663836110842230
uptime_in_seconds:32
uptime_in_days:0
hz:10
configured_hz:10
lru_clock:2891726
executable:/redis-server
config_file:
io_threads_active:0
还有很多自定义的配置,详细参数我们可以看当前目录下的 README.md 文件
回滚
[root@master redis-cluster]# helm ls -n redis
NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION
redis-cluster redis 2 2022-09-22 16:38:46.018087963 +0800 CST deployed redis-cluster-8.2.4 7.0.5
[root@master redis-cluster]# helm history redis-cluster -n redis
REVISION UPDATED STATUS CHART APP VERSION DESCRIPTION
1 Thu Sep 22 16:25:49 2022 superseded redis-cluster-8.2.4 7.0.5 Install complete
2 Thu Sep 22 16:38:46 2022 deployed redis-cluster-8.2.4 7.0.5 Upgrade complete
[root@master redis-cluster]# helm rollback redis-cluster 1 -n redis
Rollback was a success! Happy Helming!
标签:yaml,--,culster,redis,cluster,helm,root
From: https://www.cnblogs.com/devopsyyds/p/16719945.html