安装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
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
# 添加repo
[root@k8s-master ~]# helm repo add bitnami https://charts.bitnami.com/bitnami
# 更新repo仓库资源
[root@k8s-master ~]# helm repo update
# 拉取helm包
[root@k8s-master ~]# helm pull bitnami/redis-cluster --untar
# 修改配置
[root@k8s-master ~]# cd redis-cluster/
[root@k8s-master redis-cluster]# vim values.yaml
global:
storageClass: "nfs"
redis:
password: "password"
cluster:
init: true # nodes:是包括副本在内的节点总数。这意味着将有 3 个主节点和 3 个副本节点
nodes: 6
replicas: 1
metrics:
enabled: true # 启用prometheus监控

# 安装
[root@k8s-master redis-cluster]# helm install redis -n redis . -f values.yaml --create-namespace
NAME: redis
LAST DEPLOYED: Tue Oct 15 14:22:35 2024
NAMESPACE: redis
STATUS: deployed
REVISION: 1
TEST SUITE: None
NOTES:
CHART NAME: redis-cluster
CHART VERSION: 11.0.6
APP VERSION: 7.4.1** Please be patient while the chart is being deployed **


To get your password run:
export REDIS_PASSWORD=$(kubectl get secret --namespace "redis" 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-redis-cluster-client --rm --tty -i --restart='Never' \
--env REDIS_PASSWORD=$REDIS_PASSWORD \
--image docker.io/bitnami/redis-cluster:7.4.1-debian-12-r0 -- bash

2. Connect using the Redis® CLI:

redis-cli -c -h redis-redis-cluster -a $REDIS_PASSWORD



WARNING: There are "resources" sections in the chart not set. Using "resourcesPreset" is not recommended for production. For production installations, please set the following values according to your workload needs:
- redis.resources
- updateJob.resources
+info https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
# 查看验证
kubectl get pod -n redis
NAME READY STATUS RESTARTS AGE
redis-redis-cluster-0 1/1 Running 0 3m
redis-redis-cluster-1 1/1 Running 0 3m
redis-redis-cluster-2 1/1 Running 0 3m
redis-redis-cluster-3 1/1 Running 0 3m
redis-redis-cluster-4 1/1 Running 0 3m
redis-redis-cluster-5 1/1 Running 0 3m

部署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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: redisinsight-pvc
namespace: redis
labels:
app: redisinsight
spec:
storageClassName: nfs
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 500Mi
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: redisinsight
namespace: redis
labels:
app: redisinsight
spec:
replicas: 1
selector:
matchLabels:
app: redisinsight
template:
metadata:
labels:
app: redisinsight
spec:
containers:
- name: redisinsight
image: redisinsight:2.58
imagePullPolicy: IfNotPresent
securityContext:
runAsUser: 0
volumeMounts:
- name: db
mountPath: /db
ports:
- containerPort: 5540
protocol: TCP
resources:
limits:
memory: "1Gi"
cpu: "500m"
volumes:
- name: db
persistentVolumeClaim:
claimName: redisinsight-pvc
---
apiVersion: v1
kind: Service
metadata:
name: redisinsight
namespace: redis
spec:
selector:
app: redisinsight
ports:
- port: 5540
targetPort: 5540
---
apiVersion: traefik.io/v1alpha1
kind: IngressRoute
metadata:
name: redisinsight
namespace: redis
spec:
entryPoints:
- web
routes:
- match: Host(`redisinsight.maka.sensetime.com`)
kind: Rule
services:
- name: redisinsight
port: 5540

添加域名解析后访问验证