首页 > 数据库 >helm部署redis-culster集群

helm部署redis-culster集群

时间:2022-09-22 16:55:36浏览次数:61  
标签:yaml -- culster redis cluster helm root

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

相关文章

  • Windows中使用Docker安装Redis
    1、拉取Redis以管理员身份运行CMD,执行如下命令拉取Redisdockerpullredis2、在D盘新建目录D:\Net_Program\Net_Docker\Redis 在D盘新建D:\Net_Program\Net_Doc......
  • 第二十章 Redis面试总结
    一、Redis持久化1.RDB与AOF的区别RDB可以理解为是一种全量数据更新机制,AOF可以理解为是一种增量的更新机制,AOF重写可以理解为是一种全量+增量的更新机制(第一次是全量,后面......
  • redis分布式锁,redis中set和setnx的区别
    转自:https://www.zhangshilong.cn/work/320344.html Redis命令SETNX的使用(包含Java分布式锁实现)可以参考Redis官网对SETNX命令的介绍:https://redis.io/commands/setnx......
  • spring-session-data-redis解决多redis的问题
    1:参考这篇文章就好了https://github.com/yugabyte/redis-code-samples/blob/69fe87302de0c9524036c8476cbc5ed90e988165/spring-session/spring-session-data-redis/src/t......
  • Redis与Python连接实例
    2022-09-221、Redis与Python建立连接之前需要先安装“Redis”安装包:在ubantu中,打开终端,输入命令:sudopipinstallredis此时,是安装Python2.0的版本。一般来说,是将3......
  • CTO 说了:谁再用 Redis 过期监听实现定时任务,立马滚蛋!
    作者:Finley来源:https://www.cnblogs.com/Finley/p/16395466.html前言日前拜读阿牛老师的大作《领导:谁再用定时任务实现关闭订单,立马滚蛋!》发现其方案有若干瑕疵,特此抛......
  • 如何远程访问 Redis
    一、修改配置文件.conf1、将配置文件里面的bind127.0.0.1注释掉,改成#bind127.0.0.1 2、将配置文件里面的protected-modeyes改成protected-modeno 3、在redi......
  • Redis——数据操作(3)
    2022-09-22(4)set操作①添加操作(sadd):例:saddstudentAB②查看操作(smembers):例:smembersstudent③移除操作(srem):例:sremstudentA(5)zset(有序集合......
  • 用Go语言&&redis,如何写分布式锁 ?
    为什么需要分布式锁1因为用户下单,需要锁住uid,防止用户重复下单。2用在库存扣减上,锁住库存,可以防止库存超卖。3用在余额扣减场景,锁住账户,防止并发操作。分布式系统......
  • Redis的持久化方式-RDB
    Redis可以将数据持久化到磁盘里,主要通过两种方式,RDB和AOF的方式存储RDB:在redis里通过save和bgsave命令实现RDB的存储save方式是一种阻塞的方式存储数据bgsave方式是非阻......