[TOC]
0x00 前言简述 本章作者实践在 Docker 以及 kubernetes 环境中,快速部署生产环境中所使用的 Redis 内存数据库,帮助 devops工作者 以及 dev 开发者节省部署和开发时间。
如果你还不了解 Redis 数据库的朋友,可以参考我的【Redis学习之路
】系列笔记帮助你快速入门Redis数据库, 关注 WeiyiGeek 公众号回复【Redis学习之路汇总
】即可获得学习资料:
https://www.weiyigeek.top/wechat.html?key=Redis学习之路汇总
Docker 快速部署单实例 redis 数据库 温馨提示:此处实践环境是使用Docker,若你没有安装Docker环境或者不了解的Docker容器的朋友,可以参考博主学习【Docker的系列笔记
】汇总, 关注 WeiyiGeek 公众号回复【Docker容器学习之路汇总
】即可获得学习资料:https://www.weiyigeek.top/wechat.html?key=Docker容器学习之路汇总
Shell 命令示例:
[TOC]
0x00 前言简述 本章作者实践在 Docker 以及 kubernetes 环境中,快速部署生产环境中所使用的 Redis 内存数据库,帮助 devops工作者 以及 dev 开发者节省部署和开发时间。
如果你还不了解 Redis 数据库的朋友,可以参考我的【Redis学习之路
】系列笔记帮助你快速入门Redis数据库, 关注 WeiyiGeek 公众号回复【Redis学习之路汇总
】即可获得学习资料:
https://www.weiyigeek.top/wechat.html?key=Redis学习之路汇总
Docker 快速部署单实例 redis 数据库 温馨提示:此处实践环境是使用Docker,若你没有安装Docker环境或者不了解的Docker容器的朋友,可以参考博主学习【Docker的系列笔记
】汇总, 关注 WeiyiGeek 公众号回复【Docker容器学习之路汇总
】即可获得学习资料:https://www.weiyigeek.top/wechat.html?key=Docker容器学习之路汇总
Shell 命令示例: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 mkdir -vp /app/redis/data tee /app/redis/redis.conf <<'EOF' bind 0.0.0.0port 6379 daemonize no supervised auto pidfile "/var/run/redis.pid" protected-mode no requirepass "123456" dir "/data" maxclients 10000 timeout 60 tcp-keepalive 60 dbfilename "dump.rdb" save 300 10 save 60 10000 rdbcompression yes rdbchecksum yes rdb-save-incremental-fsync yes appendonly yes appendfilename "appendonly.aof" appendfsync everysec rename-command FLUSHDB b840fc02d524045429941cc15f59e41cb7be6c53 rename-command FLUSHALL b840fc02d524045429941cc15f59e41cb7be6c54 rename-command EVAL b840fc02d524045429941cc15f59e41cb7be6c55 rename-command DEBUG b840fc02d524045429941cc15f59e41cb7be6c56 EOF $ docker run -d -p 6379:6379 \ -v /app/redis/redis.conf:/etc/redis/redis.conf \ -v /app/redis/data:/data \ --name redis-server redis:6.2.6-alpine3.15 redis-server /etc/redis/redis.conf $ nerdctl run -d -p 6379:6379 \ -v /app/redis/redis.conf:/etc/redis/redis.conf \ -v /app/redis/data:/data \ --name redis-server redis:6.2.6-alpine3.15 redis-server /etc/redis/redis.conf 5e854a58087ae1bba5a661b2941474560cbecc37f54c7f4e7a28afbaed6aebf0
执行结果: 1 2 3 4 5 6 7 8 9 $ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 2919b8a9478a redis:6.2.6-alpine3.15 "docker-entrypoint.s…" 20 seconds ago Up 19 seconds 0.0.0.0:6379->6379/tcp redis-server $ docker exec -it redis-server redis-cli -a 123456 ping Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe. PONG
Kubernetes 快速部署单实例 redis 数据库 温馨提示:此处实践环境是使用Kubernetes集群,若你没有安装Kubernetes集群环境或者不了解的Kubernetes容器的朋友,可以参考博主学习【Kubernetes的系列笔记
】汇总, 关注 WeiyiGeek 公众号回复【Kubernetes学习之路汇总
】即可获得学习资料https://www.weiyigeek.top/wechat.html?key=Kubernetes学习之路汇总
温馨提示:集群中基于nfs的provisioner的动态持卷环境部署可参考此篇文章( https://blog.weiyigeek.top/2022/6-7-664.html )
步骤01.创建configMap 资源清单配置Redis.conf (此处还是采用上述 /app/redis/redis.conf 配置文件)1 2 3 4 kubectl create configmap -n database redis-single-conf --from-file=/app/redis/redis.conf kubectl get configmap -n database redis-single-conf
步骤02.StatefulSet 与 SVC 资源清单:1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 tee redis-single-server.yaml <<'EOF' apiVersion: apps/v1 kind: StatefulSet metadata: name: __APPNAME__ namespace: __APPNAMESPACE__ annotations: description: redis-single spec: replicas: 1 serviceName: __APPNAME__ selector: matchLabels: app: __APPNAME__ template: metadata: labels: app: __APPNAME__ spec: initContainers: - name: sysctl image: alpine:3.15.4 imagePullPolicy: IfNotPresent command : - sh - -c - | mount -o remount rw /proc/sys sysctl -w net.core.somaxconn=10000 sysctl -w net.ipv4.tcp_tw_reuse=1 sysctl -w net.ipv4.ip_local_port_range="1024 65535" sysctl -w fs.file-max=1048576 sysctl -w fs.inotify.max_user_instances=16384 sysctl -w fs.inotify.max_user_watches=524288 sysctl -w fs.inotify.max_queued_events=16384 echo never > /sys/kernel/mm/transparent_hugepage/enabled securityContext: privileged: true containers: - name: redis image: redis:6.2.6-alpine3.15 imagePullPolicy: IfNotPresent ports: - containerPort: 6379 name: server command : [ "redis-server" , "/conf/redis.conf" ] volumeMounts: - name: conf mountPath: /conf/redis.conf subPath: redis.conf - name: data mountPath: /data - name: timezone mountPath: /etc/localtime volumes: - name: conf configMap: name: redis-single-conf defaultMode: 0755 - name: logs hostPath: type : DirectoryOrCreate path: /app/redis/logs - name: timezone hostPath: path: /usr/share/zoneinfo/Asia/Shanghai volumeClaimTemplates: - metadata: name: data spec: accessModes: [ "ReadWriteOnce" ] storageClassName: "__STORAGECLASSNAME__" resources: requests: storage: 2Gi --- apiVersion: v1 kind: Service metadata: name: __APPNAME__ namespace: __APPNAMESPACE__ spec: type : ClusterIP ports: - port: 6379 targetPort: 6379 name: tcp selector: app: __APPNAME__ EOF sed -i -e 's/__APPNAME__/redis-single/g' -e 's/__APPNAMESPACE__/database/g' -e 's/__STORAGECLASSNAME__/managed-nfs-storage/' redis-single-server.yaml
步骤 03.部署资源清单到Kubernetes集群1 2 3 kubectl apply -f redis-single-server.yaml
步骤 04.验证部署应用资源1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 kubectl get pod -n database -l app=redis-single kubectl get svc -n database redis-single $ telnet 11.19.196.169 6379
温馨提示: 集群中的其它应用,我们可以通过svc的地址或者集群dns域名(redis-single.database
-推荐)来访问该pod。
Kubernetes 快速利用资源清单部署 redis 数据库集群 步骤 01.创建 redis 配置文件使用 configmap 方式进行挂载。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 tee redis-cluster-configmap.yaml << 'EOF' apiVersion: v1 kind: ConfigMap metadata: name: redis-cluster namespace: database data: update-node.sh: | #!/bin/sh CLUSTER_CONFIG="/data/nodes.conf" if [ -f ${CLUSTER_CONFIG} ]; then if [ -z "${POD_IP}" ]; then echo "Unable to determine Pod IP address!" exit 1 fi echo "Updating my IP to ${POD_IP} in ${CLUSTER_CONFIG}" sed -i.bak -e '/myself/ s/[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}/'${POD_IP}'/' ${CLUSTER_CONFIG} fi exec "$@" redis.conf: |+ port 6379 protected-mode no maxclients 32768 masterauth weiyigeek.top requirepass weiyigeek.top # 数据目录 dir /data # 开启 RDB 持久化&触发策略 dbfilename dump.rdb rdb-save-incremental-fsync yes # 开启AOF持久化以及每秒钟同步一次折中的方案 appendonly yes appendfilename appendonly.aof appendfsync everysec no-appendfsync-on-rewrite no auto-aof-rewrite-percentage 100 auto-aof-rewrite-min-size 128mb aof-load-truncated yes aof-use-rdb-preamble yes aof-rewrite-incremental-fsync yes # 集群模式打开 cluster-enabled yes cluster-config-file /data/nodes.conf cluster-node-timeout 5000 # 当负责一个插槽的主库下线且没有相应的从库进行故障恢复时集群仍然可用 cluster-require-full-coverage no # 只有当一个主节点至少拥有其他给定数量个处于正常工作中的从节点的时候,才会分配从节点给集群中孤立的主节点 cluster-migration-barrier 1 # 副本服务陈旧数据 replica-serve-stale-data yes replica-read-only no replica-priority 100 # 复制同步策略 repl-diskless-sync no repl-diskless-sync-delay 5 repl-disable-tcp-nodelay no # 慢查询日志 slowlog-log-slower-than 10000 slowlog-max-len 128 # 内存策略 maxmemory-policy allkeys-lru EOF
温馨提示:masterauth 与 requirepass 认证密码需要根据实际情况进行更改,此外我设置为了我的主页地址。
步骤 02.Redis 集群 SVC 以及 STS 资源清单。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 tee redis-cluster-deploy.yaml <<'EOF' apiVersion: v1 kind: Service metadata: namespace: database name: redis-cluster labels: app: redis-cluster spec: clusterIP: None ports: - port: 6379 targetPort: 6379 name: client - port: 16379 targetPort: 16379 name: gossip selector: app: redis-cluster --- apiVersion: apps/v1 kind: StatefulSet metadata: namespace: database name: redis-cluster labels: app: redis-cluster spec: serviceName: redis-cluster replicas: 6 selector: matchLabels: app: redis-cluster template: metadata: labels: app: redis-cluster spec: affinity: nodeAffinity: requiredDuringSchedulingIgnoredDuringExecution: nodeSelectorTerms: - matchExpressions: - key: node operator: In values: - app podAntiAffinity: preferredDuringSchedulingIgnoredDuringExecution: - weight: 1 podAffinityTerm: topologyKey: app.kubernetes.io/name labelSelector: matchExpressions: - key: node operator: In values: - app containers: - name: redis image: redis:6.2.7-alpine ports: - containerPort: 6379 name: client - containerPort: 16379 name: gossip command: ["/etc/redis/update-node.sh", "redis-server" , "/etc/redis/redis.conf" ] env: - name: POD_IP valueFrom: fieldRef: fieldPath: status.podIP volumeMounts: - name: conf mountPath: /etc/redis/ readOnly: false - name: data mountPath: /data readOnly: false - name: timezone mountPath: /etc/localtime volumes: - name: conf configMap: name: redis-cluster defaultMode: 0755 - name: timezone hostPath: path: /usr/share/zoneinfo/Asia/Shanghai volumeClaimTemplates: - metadata: name: data spec: storageClassName: nfs-dev accessModes: - ReadWriteMany resources: requests: storage: 5 Gi EOF
步骤 03.使用 kubectl apply 部署资源清单,并查看部署结果以及Pod IP,为集群初始化做准备。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 $ kubectl create namespace database $ ls redis-cluster-configmap.yaml redis-cluster-deploy.yaml $ kubectl create -f redis-cluster-configmap.yaml $ kubectl create -f redis-cluster-deploy.yaml $ kubectl get statefulsets,pod,svc -n database NAME READY AGE statefulset.apps/redis-cluster 6/6 13m NAME READY STATUS RESTARTS AGE pod/redis-cluster-0 1/1 Running 0 13m pod/redis-cluster-1 1/1 Running 0 12m pod/redis-cluster-2 1/1 Running 0 12m pod/redis-cluster-3 1/1 Running 0 10m pod/redis-cluster-4 1/1 Running 0 9m19s pod/redis-cluster-5 1/1 Running 0 9m16s NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE service/redis-cluster ClusterIP None <none> 6379/TCP,16379/TCP 13m kubectl get pod -n database -l app=redis-cluster -o jsonpath='{ range.items [*]}{.status.podIP}:6379 ' | sed "s# :6379 ##g"
步骤 04.进入到第一个Pod 终端中进行初始化 Redis 集群操作,验证Redis Cluster集群
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 kubectl exec -n database -it redis-cluster-0 sh /data $ redis-cli -a weiyigeek.top --cluster create --cluster-replicas 1 10.66.35.66:6379 10.66.237.142:6379 10.66.55.76:6379 10.66.53.96:6379 10.66.35.92:6379 10.66.55.77:6379 /data $ redis-cli -c -h redis-cluster.database.svc.cluster.test -a weiyigeek.top redis-cluster.database.svc.cluster.test:6379> CLUSTER INFO cluster_state:ok cluster_slots_assigned:16384 cluster_slots_ok:16384 cluster_slots_pfail:0 cluster_slots_fail:0 cluster_known_nodes:6 cluster_size:3 .... redis-cluster.database.svc.cluster.test:6379> CLUSTER NODES f7ecf69d99129fba7737f8ae9a8f172af19a7b72 10.66.55.77:6379@16379 slave 729af3b961a978ad15263ef96439177207be7821 0 1665234666115 2 connected b13a58f799e058dd9afba221f25a8bd53ae05969 10.66.35.66:6379@16379 master - 0 1665234667119 1 connected 0-5460 50c3d31e7277ce339752a980f14c03d180e2f98a 10.66.55.76:6379@16379 master - 0 1665234667119 3 connected 10923-16383 298d5e8528c38f687c9894b9974eb5368555c652 10.66.35.92:6379@16379 slave b13a58f799e058dd9afba221f25a8bd53ae05969 0 1665234665513 1 connected 729af3b961a978ad15263ef96439177207be7821 10.66.237.142:6379@16379 myself,master - 0 1665234665000 2 connected 5461-10922 ce02a1eb7efbd4de37383f46c300bb883dcd16b4 10.66.53.96:6379@16379 slave 50c3d31e7277ce339752a980f14c03d180e2f98a 0 1665234665110 3 connected
温馨提示:在初始化 redis 集群时必须使用 ip 地址,如果使用域名会报如下错误。 温馨提示:当应用连接 redis 集群时使用 pod 的域名, 格式为 svc名字.ns名字.svc.cluster.local
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 $ nslookup redis-cluster.database.svc.cluster.test Server: 10.96.0.10 Address: 10.96.0.10:53 Name: redis-cluster.database.svc.cluster.test Address: 10.66.35.66 Name: redis-cluster.database.svc.cluster.test Address: 10.66.35.92 Name: redis-cluster.database.svc.cluster.test Address: 10.66.55.76 Name: redis-cluster.database.svc.cluster.test Address: 10.66.53.96 Name: redis-cluster.database.svc.cluster.test Address: 10.66.237.142 Name: redis-cluster.database.svc.cluster.test Address: 10.66.55.77
步骤 05.使用redis cluster进行KV数据插入并查看数据。1 2 3 4 5 6 7 8 9 redis-cluster.database.svc.cluster.test:6379> set domain weiyigeek.top EX 10 -> Redirected to slot [5449] located at 10.66.35.66:6379 OK 10.66.35.66:6379> get domain "weiyigeek.top" 10.66.35.66:6379> get domain "weiyigeek.top" 10.66.35.66:6379> get domain (nil)
温馨提示:如果整个 redis 集群的 pod 全部都挂掉了,pod自动拉起后集群不可用,需要重建集群,此时有两种重建集群方法。
Kubernetes 中使用 Helm 快速部署 redis 多主多从集群 描述:我们可以使用 Bitnami helm chart 在 K8S 中一键部署 Redis cluster 多主多从。 项目地址:https://github.com/bitnami/charts/tree/master/bitnami/redis-cluster
weiyigeek.top-redis单主与redis多主集群
环境依赖:
Kubernetes 1.19+
Helm 3.2.0+
PV provisioner support in the underlying infrastructure
温馨提示:1.集群中基于nfs的provisioner的动态持卷环境部署可参考此篇文章( https://blog.weiyigeek.top/2022/6-7-664.html )
步骤 01.添加 Bitnami chart 仓库,查看可用 redis-cluster 的 chart 及其对应版本,拉取部署所需的 yaml 文件到本地。
1 2 3 $ helm repo add bitnami https://charts.bitnami.com/bitnami $ helm3 search repo bitnami/redis-cluster -l $ helm3 pull bitnami/redis-cluster --version 8.2.4 --untar
步骤 02.修改 redis-cluster 图表的 values.yaml 文件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 vim redis-cluster/values.yaml clusterDomain: cluster.test ..... image: registry: harbor.weiyigeek.top repository: library/redis-cluster tag: 7.0.5-debian-11-r0 ..... podSecurityContext: enabled: true fsGroup: 1001 runAsUser: 1001 sysctls: [] ..... service: ports: redis: 6379 nodePorts: redis: 31379 type : ClusterIP ..... persistence: path: /bitnami/redis/data storageClass: "nfs-local" accessModes: - ReadWriteOnce size: 8Gi ..... redis: resources: limits: cpu: 1000m memory: 4Gi requests: {} ..... cluster: init: true nodes: 6 replicas: 1 ..... metrics: enabled: true image: registry: harbor.weiyigeek.top repository: library/redis-exporter tag: 1.44.0-debian-11-r8 ..... sysctlImage: enabled: true registry: harbor.weiyigeek.top repository: library/bitnami-shell tag: 11-debian-11-r37 command : - /bin/sh - -c - |- sysctl -w net.core.somaxconn=10000 echo never > /host-sys/kernel/mm/transparent_hugepage/enabled mountHostSys: true
步骤 03.为了加快拉取速度我将docker hub上的指定所需镜像拉取到本地Harbor仓库中。1 2 3 4 5 6 7 8 9 10 11 docker pull bitnami/redis-cluster:7.0.5-debian-11-r0 docker tag bitnami/redis-cluster:7.0.5-debian-11-r0 harbor.weiyigeek.top/library/redis-cluster:7.0.5-debian-11-r0 docker push harbor.weiyigeek.top/library/redis-cluster:7.0.5-debian-11-r0 docker pull bitnami/redis-exporter:1.44.0-debian-11-r8; docker pull bitnami/bitnami-shell:11-debian-11-r37 docker tag bitnami/redis-exporter:1.44.0-debian-11-r8 harbor.weiyigeek.top/library/redis-exporter:1.44.0-debian-11-r8 docker tag bitnami/bitnami-shell:11-debian-11-r37 harbor.weiyigeek.top/library/bitnami-shell:11-debian-11-r37 docker push harbor.weiyigeek.top/library/redis-exporter:1.44.0-debian-11-r8 docker push harbor.weiyigeek.top/library/bitnami-shell:11-debian-11-r37
步骤 04.开始安装修改后的 redis-cluster 图表到 database 名称空间中,并查看资源部署情况。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 helm3 install redis ./redis-cluster --set password=weiyigeek.top --namespace database --create-namespace --debug helm3 list -n database kubectl get sts,pod,svc -n database -l app.kubernetes.io/name=redis-cluster
步骤 05.验证使用helm部署的Redis集群
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 export REDIS_PASSWORD=$(kubectl get secret --namespace "database" redis-redis-cluster -o jsonpath="{.data.redis-password}" | base64 -d)kubectl run --namespace database redis-redis-cluster-client --rm --tty -i --restart='Never' \ --env REDIS_PASSWORD=$REDIS_PASSWORD \ --image bitnami/redis-cluster:7.0.5-debian-11-r0 -- bash redis-cli -c -h redis-redis-cluster -a $REDIS_PASSWORD redis-redis-cluster:6379> CLUSTER INFO redis-redis-cluster:6379> CLUSTER NODES redis-redis-cluster:6379> set name weiyigeek OK 10.66.237.149:6379> set domain weiyigeek.top OK 10.66.35.100:6379> set blog blog.weiyigeek.top OK 10.66.237.149:6379> keys * 1) "name" 2) "blog" 10.66.237.149:6379> get name "weiyigeek"
weiyigeek.top-执行结果
至此,快速使用helm安装多主多从redis集群完毕!
Kubernetes 快速部署 RedisInsight 工具连接Redis集群 描述:RedisInsight 是 Redis 官方推荐的可视化工具,其功能强大,支持Redis集群连接。
参考地址:https://docs.redis.com/latest/ri/installing/install-k8s/ 参考文章: 【9.使用RedisInsight工具对Redis集群CURD操作及数据可视化和性能监控】- https://blog.weiyigeek.top/2022/9-20-686.html
步骤 01.集群中快速 redisinsight 部署资源清单。1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 tee redisinsight-1.13.0.yaml <<'EOF' apiVersion: v1 kind: Service metadata: name: redisinsight-service namespace: devops spec: type: LoadBalancer ports: - port: 80 targetPort: 8001 selector: app: redisinsight --- apiVersion: apps/v1 kind: Deployment metadata: name: redisinsight namespace: devops labels: app: redisinsight spec: replicas: 1 strategy: type: Recreate selector: matchLabels: app: redisinsight template: metadata: labels: app: redisinsight spec: volumes: - name: db emptyDir: {} containers: - name: redisinsight image: redislabs/redisinsight:1.13.0 imagePullPolicy: IfNotPresent env: - name: RIHOST value: "0.0.0.0" - name: RIPORT value: "8001" volumeMounts: - name: db mountPath: /db ports: - containerPort: 8001 protocol: TCP livenessProbe: httpGet: path : /healthcheck/ port: 8001 initialDelaySeconds: 5 periodSeconds: 5 failureThreshold: 1 EOF
步骤 02.部署命令1 2 kubectl create ns devops kubectl apply -f redisinsight-1.13.0.yaml
步骤 03.验证服务(你可按照需求使用nodeport或者ingress进行暴露端口)1 2 3 4 5 6 7 8 9 $ kubectl get pod -n devops NAME READY STATUS RESTARTS AGE redisinsight-5c4f954694-jc5cd 1/1 Running 0 95s $ kubectl -n devops port-forward deployment/redisinsight --address 0.0.0.0 30081:8001 Forwarding from 0.0.0.0:30081 -> 8001 Handling connection for 30081 Handling connection for 30081 Handling connection for 30081
步骤 04.浏览器访问 节点IP:30081 即可访问 redisinsight
UI 界面,添加集群IP(服务名称)以及链接端口和认证密码。
Host: redis-redis-cluster.database.svc Port: 6379 Name: redis-cluster Password: weiyigeek.top
weiyigeek.top-redisinsight链接redis集群图
步骤 05.添加完成后我们便可使用redisinsight进行管理查看操作Redis集群了。
weiyigeek.top-使用redisinsight操作redis集群图
至此完毕。