K8S Redis-Cluster安装(含redis-cluster-proxy、RedisInsight)

2024-05-06 10:12

本文主要是介绍K8S Redis-Cluster安装(含redis-cluster-proxy、RedisInsight),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

参考:在 K8S 中快速部署 Redis Cluster & Redisinsight
参考:Redis 中文文档(一)

helm   redis-cluster

[root@k8s-master01 redis-cluster]# helm search repo redis-cluster
NAME                    CHART VERSION   APP VERSION     DESCRIPTION
bitnami/redis-cluster   9.1.3           7.2.3           Redis(R) is an open source, scalable, distribut...[root@k8s-master01 redis-cluster]# helm pull bitnami/redis-cluster

解压,查看使用到的镜像文件,提前下载并上传私有仓库

[root@k8s-master01 redis-cluster]# cat Chart.yaml
annotations:
category: Database
images: |
- name: os-shell
image: docker.io/bitnami/os-shell:11-debian-11-r91
- name: redis-cluster
image: docker.io/bitnami/redis-cluster:7.2.3-debian-11-r1
- name: redis-exporter
image: docker.io/bitnami/redis-exporter:1.55.0-debian-11-r2

配置私有仓库

docker tag docker.io/bitnami/redis-exporter:1.55.0-debian-11-r2  harbor.david.org/bitnami/redis-exporter:1.55.0-debian-11-r2
docker tag docker.io/bitnami/redis-cluster:7.2.3-debian-11-r1  harbor.david.org/bitnami/redis-cluster:7.2.3-debian-11-r1
docker tag docker.io/bitnami/os-shell:11-debian-11-r91  harbor.david.org/bitnami/os-shell:11-debian-11-r91
docker tag docker.io/redislabs/redisinsight:latest  harbor.david.org/redislabs/redisinsight:latest

helm安装redis-cluster

使用之前的storyageClass

StorageClass
helm install redis-cluster bitnami/redis-cluster -n develop \--values values.yaml \--set persistence.storageClass=nfs-sc \--set image.registry=harbor.david.org \--set volumePermissions.image.registry=harbor.david.org \--set metrics.image.registry=harbor.david.org \--set sysctlImage.image.registry=harbor.david.org

安装完成


NAME: redis-cluster
LAST DEPLOYED: Fri Nov 24 14:05:41 2023
NAMESPACE: develop
STATUS: deployed
REVISION: 1
TEST SUITE: None
NOTES:
CHART NAME: redis-cluster
CHART VERSION: 9.1.3
APP VERSION: 7.2.3** Please be patient while the chart is being deployed **To get your password run:export REDIS_PASSWORD=$(kubectl get secret --namespace "develop" 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 develop redis-cluster-client --rm --tty -i --restart='Never' \--env REDIS_PASSWORD=$REDIS_PASSWORD \
--image harbor.david.org/bitnami/redis-cluster:7.2.3-debian-11-r1 -- bash2. Connect using the Redis® CLI:redis-cli -c -h redis-cluster -a $REDIS_PASSWORD


查看密码

[root@k8s-master01 redis-cluster]# kubectl get secret --namespace "develop" redis-cluster -o jsonpath="{.data.redis-password}" | base64 -d


 

导出所有节点的地址为ClusterIp(如果需要)

参考: VMware Tanzu Application Catalog (Applications Tutorials) Documentation

 helm upgrade redis-cluster --set "password=xxxxxxxxxx,cluster.externalAccess.enabled=true bitnami/redis-cluster -n develop
[root@k8s-master01 redis]# helm upgrade redis-cluster bitnami/redis-cluster --set cluster.externalAccess.enabled=true --set password=An1y6Hh0Cv -n develop
Release "redis-cluster" has been upgraded. Happy Helming!
NAME: redis-cluster
LAST DEPLOYED: Sun Nov 26 18:10:15 2023
NAMESPACE: develop
STATUS: deployed
REVISION: 3
TEST SUITE: None
NOTES:
CHART NAME: redis-cluster
CHART VERSION: 9.1.3
APP VERSION: 7.2.3** Please be patient while the chart is being deployed **To get your password run:export REDIS_PASSWORD=$(kubectl get secret --namespace "develop" redis-cluster -o jsonpath="{.data.redis-password}" | base64 -d)To connect to your Redis® server from outside the cluster check the following information:NOTE: It may take a few minutes for the LoadBalancer IP to be available.Watch the status with: 'kubectl get svc --namespace develop -w redis-cluster'You will have a different external IP for each Redis® node. Get the external ip from `-external` suffixed services: `kubectl get svc`.Redis® port: 6379Once the LoadBalancerIPs are ready, you need to provide them and perform a Helm Upgrade:helm upgrade --namespace develop redis-cluster --set "cluster.externalAccess.enabled=true,cluster.externalAccess.service.type=LoadBalancer,cluster.externalAccess.service.loadBalancerIP[0]=load-balancerip-0,cluster.externalAccess.service.loadBalancerIP[1]=load-balancerip-1,cluster.externalAccess.service.loadBalancerIP[2]=load-balancerip-2,cluster.externalAccess.service.loadBalancerIP[3]=load-balancerip-3,cluster.externalAccess.service.loadBalancerIP[4]=load-balancerip-4,cluster.externalAccess.service.loadBalancerIP[5]=load-balancerip-5" oci://registry-1.docker.io/bitnamicharts/redis-clusterWhere loadbalancer-ip-i are the LoadBalancerIPs provided by the cluster.

helm upgrade ingress-nginx导出redis 6379端口

参考:K8s and Redis; a tale of Layer 4 Ingress

helm upgrade ingress-nginx ingress-nginx/ingress-nginx -n ingress-nginx \--values values.yaml \--set tcp.26379="develop/redis-cluster:6379" --debug

修改端口为你想要的端口

 [root@k8s-master01 ~]# kubectl edit svc -n ingress-nginx ingress-nginx-controllerservice/ingress-nginx-controller edited[root@k8s-master01 ~]# kubectl get svc -n ingress-nginx

也可以使用port-forward进行临时转发端口,不过得一直挂着

参考: 使用端口转发来访问集群中的应用
参考: kubectl port-forward 踩坑记录

 [root@k8s-master01 redis]# kubectl port-forward service/redis-cluster -n develop 30009:6379 --address 0.0.0.0Forwarding from 0.0.0.0:30009 -> 6379Handling connection for 30009


 使用ingress-nginx进行转发(集群方式下不推荐) 


 因为集群会涉及到不同的key在不同的slot上,
 Redis会进行重定向,将内网IP返回给客户端
 但客户端并不能访问到内网地址

 参考: 浅谈Redis Cluster 集群的MOVED、ASK重定向
 

 ingress-nginx导出TCP端口

 配置redis-cluster-proxy代理(外网客户端及程序可连接)
 参考: 【Redis】——引入redis-cluster-proxy使得Redis Cluster对Kubernetes外部可提供服务
 参考: Redis系列(十五)、Redis6新特性之集群代理(Cluster Proxy)

 linux上安装redis-cluster-proxy

 依赖gcc需要提前安装


 gcc version 9.3.1
 参考: CentOS/Ubuntu安装最新的gcc-9 

参考:

【已解决】Error: Failed to download metadata for repo ‘appstream‘: Cannot prepare internal mirrorlist

 或者参考下面的dockerfile

 make redis-cluster-proxy

# Make Install 
git clone https://github.com/artix75/redis-cluster-proxy
cd redis-cluster-proxy
make PREFIX=/usr/local/redis_cluster_proxy install dockerfile在目录/usr/local/redis_cluster_proxy/bin/ 下复制redis-cluster-proxy到当前目录,然后创建dockerfile 内容如下redis_cluster_proxy使用C编写,需要gcc version 9.3.1环境https://blog.csdn.net/weixin_43252521/article/details/124409151
[root@master01 redis-cluster-proxy]# vi dockerfile
FROM centos:8WORKDIR /dataRUN sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-*
RUN sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-*
RUN yum makecache
#RUN yum update -yRUN rpm -ivh https://cbs.centos.org/kojifiles/packages/centos-release-scl-rh/2/3.el7.centos/noarch/centos-release-scl-rh-2-3.el7.centos.noarch.rpm
RUN rpm -ivh https://cbs.centos.org/kojifiles/packages/centos-release-scl/2/3.el7.centos/noarch/centos-release-scl-2-3.el7.centos.noarch.rpmRUN yum install -y centos-release-scl
RUN yum install -y devtoolset-9-gcc devtoolset-9-gcc-c++RUN echo "scl enable devtoolset-9 bash" >> /etc/profile
RUN echo "source /opt/rh/devtoolset-9/enable" >> /etc/profileRUN source /etc/profileRUN yum install -y wget
RUN wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-8.repo
RUN sed -i  's/$releasever/8/g' /etc/yum.repos.d/CentOS-Base.repo
RUN yum repolistRUN yum install -y  gcc
RUN gcc -vADD redis-cluster-proxy /usr/local/bin/EXPOSE 7777docker build . -t redis-cluster-proxy:v1.0.0
 [root@k8s-master01 ~]# docker tag redis-cluster-proxy:v1.0.0  harbor.david.org/redislabs/redis-cluster-proxy:v1.0.0[root@k8s-master01 ~]# docker push  harbor.david.org/redislabs/redis-cluster-proxy:v1.0.0

 配置redis-cluster-proxy configmap

[root@master01 redis-cluster-proxy]# vi configMap.yaml
---
# Redis-Proxy Config
apiVersion: v1
kind: ConfigMap
metadata:name: redis-cluster-proxynamespace: develop
data:proxy.conf: |cluster redis-cluster:6379     # 配置为Redis Cluster Servicebind 0.0.0.0port 7777   # redis-cluster-proxy 对外暴露端口threads 8   # 线程数量daemonize noenable-cross-slot yesauth An1y6Hh0Cv     # 配置Redis Cluster 认证密码log-level error
[root@master01 redis-cluster-proxy]#
kubectl apply -f configMap.yaml  -n develop

配置deployment.yaml

[root@master01 redis-cluster-proxy]# vi deployment.yaml
---
# Redis-Proxy NodePort
apiVersion: v1
kind: Service
metadata:name: redis-cluster-proxynamespace: develop
spec:type: NodePort # 对K8S外部提供服务ports:- name: redis-cluster-proxynodePort: 30009   # 对外提供的端口port: 7777protocol: TCPtargetPort: 7777selector:app: redis-cluster-proxy
---
# Redis-Proxy Deployment
apiVersion: apps/v1
kind: Deployment
metadata:name: redis-cluster-proxynamespace: develop
spec:replicas: 1selector:matchLabels:app: redis-cluster-proxytemplate:metadata:labels:app: redis-cluster-proxyspec:#imagePullSecrets:#  - name: harborcontainers:- name: redis-cluster-proxyimage: harbor.david.org/redislabs/redis-cluster-proxy:v1.0.0imagePullPolicy: Alwayscommand: ["redis-cluster-proxy"]args:- -c- /data/proxy.conf   # 指定启动配置文件ports:- name: redis-7777containerPort: 7777protocol: TCPvolumeMounts:- name: redis-proxy-confmountPath: /data/volumes:   # 挂载proxy配置文件- name: redis-proxy-confconfigMap:name: redis-cluster-proxy
[root@master01 redis-cluster-proxy]#
kubectl apply -f deployment.yaml  -n develop[root@master01 redis-cluster-proxy]# kubectl get pods -n develop
NAME                                   READY   STATUS    RESTARTS        AGE
redis-cluster-proxy-6679cb8f78-nbgr4   1/1     Running   0               167m[root@master01 redis-cluster-proxy]# kubectl get svc -n develop |grep redis
redis-cluster                   ClusterIP   10.102.144.124   <none>        6379/TCP                        5d21h
redis-cluster-headless          ClusterIP   None             <none>        6379/TCP,16379/TCP              5d21h
redis-cluster-proxy             NodePort    10.103.13.20     <none>        7777:30009/TCP                  167m

安装redisinsight

 参考:redisinsight
 打开网页右上角的 install

helm repo add redisinsight https://spy86.github.io/redisinsight[root@k8s-master01 ~]# helm search hub redisinsight -o json
[{"url":"https://artifacthub.io/packages/helm/redisinsight/redisinsight","version":"0.1.0","app_version":"0.1.0","description":"A Helm chart for Redis Insight.","repository":{"url":"https://spy86.github.io/redisinsight","name":"redisinsight"}},{"url":"https://artifacthub.io/packages/helm/truecharts/redisinsight","version":"3.0.13","app_version":"1.14.0","description":"GUI for Redis.","repository":{"url":"https://charts.truecharts.org/","name":"truecharts"}},{"url":"https://artifacthub.io/packages/helm/riftbit/redisinsight","version":"0.1.0","app_version":"v1.0.0","description":"RedisInsight - The GUI for Redis","repository":{"url":"https://charts.riftbit.com/","name":"riftbit"}},{"url":"https://artifacthub.io/packages/helm/heywood8-helm-charts/redisinsight","version":"0.4.5","app_version":"2.28.0","description":"A Redisinsight Helm chart for kubernetes","repository":{"url":"https://heywood8.github.io/helm-charts/","name":"heywood8-helm-charts"}},{"url":"https://artifacthub.io/packages/helm/eximiait/openshift-secured-redisinsight","version":"0.9.0","app_version":"","description":"A secured version of RedisInsight for OpenShift","repository":{"url":"https://charts.eximiait.com.ar","name":"eximiait"}}]
[root@k8s-master01 ~]#[root@k8s-master01 ~]# helm search repo redisinsight
NAME                            CHART VERSION   APP VERSION     DESCRIPTION
redisinsight/redisinsight       0.1.0           0.1.0           A Helm chart for Redis Insight.
[root@k8s-master01 ~]#

[root@k8s-master01 ~]# helm pull redisinsight/redisinsight


解压,查看values.yaml


helm install redisinsight redisinsight/redisinsight -n develop \
--values values.yaml \
--set namespace.name=develop \
--set image.repository=harbor.david.org/redislabs/redisinsightNAME: redisinsight
LAST DEPLOYED: Fri Nov 24 14:36:26 2023
NAMESPACE: develop
STATUS: deployed
REVISION: 1
NOTES:
1. Get the application URL by running these commands:export POD_NAME=$(kubectl get pods --namespace develop -l "app.kubernetes.io/name=redisinsight,app.kubernetes.io/instance=redisinsight" -o jsonpath="{.items[0].metadata.name}")echo "Visit http://127.0.0.1:8001 to use your application"kubectl --namespace develop port-forward $POD_NAME 8001:8001

配置ingress-nginx转发

vi ingress-nginx.yamlapiVersion: networking.k8s.io/v1
kind: Ingress
metadata:name: redisinsight-ingressnamespace: develop
spec:ingressClassName: nginxrules: # 一个ingress可以配置多个rules- host: redisinsight.david.org # 域名配置,可以不写,匹配*,或者写 *.bar.comhttp:        paths: # 相当于nginx的location,同一个host可以配置多个path- pathType: Prefixbackend:service:name: redisinsight  # 代理到哪个svcport:number: 80 # svc的端口path: /


 应用

 kubectl apply -f ingress-nginx.yaml

 配置hosts

 192.168.221.132 redisinsight.david.org

 访问测试
 
 http://redisinsight.david.org

这篇关于K8S Redis-Cluster安装(含redis-cluster-proxy、RedisInsight)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/964090

相关文章

Redis实现延迟任务的三种方法详解

《Redis实现延迟任务的三种方法详解》延迟任务(DelayedTask)是指在未来的某个时间点,执行相应的任务,本文为大家整理了三种常见的实现方法,感兴趣的小伙伴可以参考一下... 目录1.前言2.Redis如何实现延迟任务3.代码实现3.1. 过期键通知事件实现3.2. 使用ZSet实现延迟任务3.3

如何解决mmcv无法安装或安装之后报错问题

《如何解决mmcv无法安装或安装之后报错问题》:本文主要介绍如何解决mmcv无法安装或安装之后报错问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录mmcv无法安装或安装之后报错问题1.当我们运行YOwww.chinasem.cnLO时遇到2.找到下图所示这里3.

Python 安装和配置flask, flask_cors的图文教程

《Python安装和配置flask,flask_cors的图文教程》:本文主要介绍Python安装和配置flask,flask_cors的图文教程,本文通过图文并茂的形式给大家介绍的非常详细,... 目录一.python安装:二,配置环境变量,三:检查Python安装和环境变量,四:安装flask和flas

Redis分片集群的实现

《Redis分片集群的实现》Redis分片集群是一种将Redis数据库分散到多个节点上的方式,以提供更高的性能和可伸缩性,本文主要介绍了Redis分片集群的实现,具有一定的参考价值,感兴趣的可以了解一... 目录1. Redis Cluster的核心概念哈希槽(Hash Slots)主从复制与故障转移2.

详解nginx 中location和 proxy_pass的匹配规则

《详解nginx中location和proxy_pass的匹配规则》location是Nginx中用来匹配客户端请求URI的指令,决定如何处理特定路径的请求,它定义了请求的路由规则,后续的配置(如... 目录location 的作用语法示例:location /www.chinasem.cntestproxy

Win11安装PostgreSQL数据库的两种方式详细步骤

《Win11安装PostgreSQL数据库的两种方式详细步骤》PostgreSQL是备受业界青睐的关系型数据库,尤其是在地理空间和移动领域,:本文主要介绍Win11安装PostgreSQL数据库的... 目录一、exe文件安装 (推荐)下载安装包1. 选择操作系统2. 跳转到EDB(PostgreSQL 的

Linux系统中卸载与安装JDK的详细教程

《Linux系统中卸载与安装JDK的详细教程》本文详细介绍了如何在Linux系统中通过Xshell和Xftp工具连接与传输文件,然后进行JDK的安装与卸载,安装步骤包括连接Linux、传输JDK安装包... 目录1、卸载1.1 linux删除自带的JDK1.2 Linux上卸载自己安装的JDK2、安装2.1

Linux卸载自带jdk并安装新jdk版本的图文教程

《Linux卸载自带jdk并安装新jdk版本的图文教程》在Linux系统中,有时需要卸载预装的OpenJDK并安装特定版本的JDK,例如JDK1.8,所以本文给大家详细介绍了Linux卸载自带jdk并... 目录Ⅰ、卸载自带jdkⅡ、安装新版jdkⅠ、卸载自带jdk1、输入命令查看旧jdkrpm -qa

MySQL Workbench 安装教程(保姆级)

《MySQLWorkbench安装教程(保姆级)》MySQLWorkbench是一款强大的数据库设计和管理工具,本文主要介绍了MySQLWorkbench安装教程,文中通过图文介绍的非常详细,对大... 目录前言:详细步骤:一、检查安装的数据库版本二、在官网下载对应的mysql Workbench版本,要是

Redis 中的热点键和数据倾斜示例详解

《Redis中的热点键和数据倾斜示例详解》热点键是指在Redis中被频繁访问的特定键,这些键由于其高访问频率,可能导致Redis服务器的性能问题,尤其是在高并发场景下,本文给大家介绍Redis中的热... 目录Redis 中的热点键和数据倾斜热点键(Hot Key)定义特点应对策略示例数据倾斜(Data S