k8s安装redis
# 1.基于helm安装
- 安装helm不在详述,见其他文章
# 2.创建 redis-cluster 目录
[root@master linux-amd64]# mkdir -p /opt/charts/redis-cluster
[root@master linux-amd64]# cd /opt/charts/redis-cluster/
[root@master redis-cluster]# ll
total 0
1
2
3
4
2
3
4
# 2.下载最新stalbe/redis-ha
[root@master redis-cluster]# helm repo update
WARNING: Kubernetes configuration file is group-readable. This is insecure. Location: /root/.kube/config
WARNING: Kubernetes configuration file is world-readable. This is insecure. Location: /root/.kube/config
Hang tight while we grab the latest from your chart repositories...
...Successfully got an update from the "stable" chart repository
Update Complete. ⎈Happy Helming!⎈
[root@master redis-cluster]# helm pull stable/redis-ha
WARNING: Kubernetes configuration file is group-readable. This is insecure. Location: /root/.kube/config
WARNING: Kubernetes configuration file is world-readable. This is insecure. Location: /root/.kube/config
[root@master redis-cluster]# ll
total 20
-rw-r--r--. 1 root root 17486 Nov 9 09:54 redis-ha-4.4.4.tgz
1
2
3
4
5
6
7
8
9
10
11
12
2
3
4
5
6
7
8
9
10
11
12
# 3.解压 charts,复制 values.yaml设置
[root@master redis-cluster]# tar zxvf redis-ha-*.tgz
redis-ha/Chart.yaml
tar: redis-ha/Chart.yaml: implausibly old time stamp 1970-01-01 08:00:00
redis-ha/values.yaml
tar: redis-ha/values.yaml: implausibly old time stamp 1970-01-01 08:00:00
redis-ha/templates/NOTES.txt
tar: redis-ha/templates/NOTES.txt: implausibly old time stamp 1970-01-01 08:00:00
redis-ha/templates/_configs.tpl
tar: redis-ha/templates/_configs.tpl: implausibly old time stamp 1970-01-01 08:00:00
redis-ha/templates/_helpers.tpl
tar: redis-ha/templates/_helpers.tpl: implausibly old time stamp 1970-01-01 08:00:00
redis-ha/templates/redis-auth-secret.yaml
tar: redis-ha/templates/redis-auth-secret.yaml: implausibly old time stamp 1970-01-01 08:00:00
redis-ha/templates/redis-ha-announce-service.yaml
tar: redis-ha/templates/redis-ha-announce-service.yaml: implausibly old time stamp 1970-01-01 08:00:00
redis-ha/templates/redis-ha-configmap.yaml
tar: redis-ha/templates/redis-ha-configmap.yaml: implausibly old time stamp 1970-01-01 08:00:00
redis-ha/templates/redis-ha-exporter-script-configmap.yaml
tar: redis-ha/templates/redis-ha-exporter-script-configmap.yaml: implausibly old time stamp 1970-01-01 08:00:00
redis-ha/templates/redis-ha-pdb.yaml
tar: redis-ha/templates/redis-ha-pdb.yaml: implausibly old time stamp 1970-01-01 08:00:00
redis-ha/templates/redis-ha-role.yaml
tar: redis-ha/templates/redis-ha-role.yaml: implausibly old time stamp 1970-01-01 08:00:00
redis-ha/templates/redis-ha-rolebinding.yaml
tar: redis-ha/templates/redis-ha-rolebinding.yaml: implausibly old time stamp 1970-01-01 08:00:00
redis-ha/templates/redis-ha-service.yaml
tar: redis-ha/templates/redis-ha-service.yaml: implausibly old time stamp 1970-01-01 08:00:00
redis-ha/templates/redis-ha-serviceaccount.yaml
tar: redis-ha/templates/redis-ha-serviceaccount.yaml: implausibly old time stamp 1970-01-01 08:00:00
redis-ha/templates/redis-ha-servicemonitor.yaml
tar: redis-ha/templates/redis-ha-servicemonitor.yaml: implausibly old time stamp 1970-01-01 08:00:00
redis-ha/templates/redis-ha-statefulset.yaml
tar: redis-ha/templates/redis-ha-statefulset.yaml: implausibly old time stamp 1970-01-01 08:00:00
redis-ha/templates/redis-haproxy-deployment.yaml
tar: redis-ha/templates/redis-haproxy-deployment.yaml: implausibly old time stamp 1970-01-01 08:00:00
redis-ha/templates/redis-haproxy-service.yaml
tar: redis-ha/templates/redis-haproxy-service.yaml: implausibly old time stamp 1970-01-01 08:00:00
redis-ha/templates/redis-haproxy-serviceaccount.yaml
tar: redis-ha/templates/redis-haproxy-serviceaccount.yaml: implausibly old time stamp 1970-01-01 08:00:00
redis-ha/templates/redis-haproxy-servicemonitor.yaml
tar: redis-ha/templates/redis-haproxy-servicemonitor.yaml: implausibly old time stamp 1970-01-01 08:00:00
redis-ha/templates/tests/test-redis-ha-configmap.yaml
tar: redis-ha/templates/tests/test-redis-ha-configmap.yaml: implausibly old time stamp 1970-01-01 08:00:00
redis-ha/templates/tests/test-redis-ha-pod.yaml
tar: redis-ha/templates/tests/test-redis-ha-pod.yaml: implausibly old time stamp 1970-01-01 08:00:00
redis-ha/OWNERS
tar: redis-ha/OWNERS: implausibly old time stamp 1970-01-01 08:00:00
redis-ha/README.md
tar: redis-ha/README.md: implausibly old time stamp 1970-01-01 08:00:00
redis-ha/ci/haproxy-enabled-values.yaml
tar: redis-ha/ci/haproxy-enabled-values.yaml: implausibly old time stamp 1970-01-01 08:00:00
[root@master redis-cluster]# cp redis-ha/values.yaml .
[root@master redis-cluster]# ll
total 32
drwxr-xr-x. 4 root root 101 Nov 9 09:54 redis-ha
-rw-r--r--. 1 root root 17486 Nov 9 09:54 redis-ha-4.4.4.tgz
-rwxr-xr-x. 1 root root 11632 Nov 9 09:55 values.yaml
[root@master 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
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
# 4.创建 start.sh 脚本记录启动命令
[root@master redis-cluster]# vim start.sh
[root@master redis-cluster]# cat start.sh
#!/bin/sh
set -x
cd /opt/charts/redis-cluster
helm install redis --create-namespace --namespace dependency -f ./values.yaml ./redis-ha
[root@master redis-cluster]# ll
total 36
drwxr-xr-x. 4 root root 101 Nov 9 09:54 redis-ha
-rw-r--r--. 1 root root 17486 Nov 9 09:54 redis-ha-4.4.4.tgz
-rw-r--r--. 1 root root 138 Nov 9 10:03 start.sh
-rwxr-xr-x. 1 root root 11632 Nov 9 09:55 values.yaml
[root@master redis-cluster]# pwd
/opt/charts/redis-cluster
[root@master redis-cluster]#
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# 5.修改当前目录的 values.yaml 配置
#举例values.yaml 配置如下,没有启用PV
#cat values.yaml
image:
repository: redis
tag: 5.0.6-alpine
replicas: 2
## Redis specific configuration options
redis:
port: 6379
masterGroupName: "mymaster" # must match ^[\\w-\\.]+$) and can be templated
config:
## For all available options see http://download.redis.io/redis-stable/redis.conf
min-replicas-to-write: 1
min-replicas-max-lag: 5 # Value in seconds
maxmemory: "4g" # Max memory to use for each redis instance. Default is unlimited.
maxmemory-policy: "allkeys-lru" # Max memory policy to use for each redis instance. Default is volatile-lru.
repl-diskless-sync: "yes"
rdbcompression: "yes"
rdbchecksum: "yes"
resources:
requests:
memory: 200Mi
cpu: 100m
limits:
memory: 4000Mi
## Sentinel specific configuration options
sentinel:
port: 26379
quorum: 1
resources:
requests:
memory: 200Mi
cpu: 100m
limits:
memory: 200Mi
hardAntiAffinity: true
## Configures redis with AUTH (requirepass & masterauth conf params)
auth: false
persistentVolume:
enabled: false
hostPath:
path: "/data/mcs-redis/{{ .Release.Name }}"
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
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
# 6.安装
[root@master redis-cluster]# ./start.sh
+ cd /opt/charts/redis-cluster
+ helm install redis --create-namespace --namespace dependency -f ./values.yaml ./redis-ha
WARNING: Kubernetes configuration file is group-readable. This is insecure. Location: /root/.kube/config
WARNING: Kubernetes configuration file is world-readable. This is insecure. Location: /root/.kube/config
NAME: redis
LAST DEPLOYED: Mon Nov 9 11:45:19 2020
NAMESPACE: dependency
STATUS: deployed
REVISION: 1
NOTES:
Redis can be accessed via port 6379 and Sentinel can be accessed via port 26379 on the following DNS name from within your cluster:
redis-redis-ha.dependency.svc.cluster.local
To connect to your Redis server:
1. Run a Redis pod that you can use as a client:
kubectl exec -it redis-redis-ha-server-0 sh -n dependency
2. Connect using the Redis CLI:
redis-cli -h redis-redis-ha.dependency.svc.cluster.local
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# 7.资源验证
[root@master redis-cluster]# helm ls -A
WARNING: Kubernetes configuration file is group-readable. This is insecure. Location: /root/.kube/config
WARNING: Kubernetes configuration file is world-readable. This is insecure. Location: /root/.kube/config
NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION
redis dependency 1 2020-11-09 11:45:19.443314165 +0800 CST deployed redis-ha-4.4.4 5.0.6
[root@master redis-cluster]# kubectl get pod,svc -n dependency
NAME READY STATUS RESTARTS AGE
pod/redis-redis-ha-server-0 2/2 Running 0 3m19s
pod/redis-redis-ha-server-1 2/2 Running 0 2m48s
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/redis-redis-ha ClusterIP None <none> 6379/TCP,26379/TCP 3m20s
service/redis-redis-ha-announce-0 ClusterIP 10.99.224.212 <none> 6379/TCP,26379/TCP 3m19s
service/redis-redis-ha-announce-1 ClusterIP 10.108.123.21 <none> 6379/TCP,26379/TCP 3m20s
1
2
3
4
5
6
7
8
9
10
11
12
13
14
2
3
4
5
6
7
8
9
10
11
12
13
14
# 8.redis验证
[root@master redis-cluster]# kubectl exec -it redis-redis-ha-server-0 sh -n dependency
kubectl exec [POD] [COMMAND] is DEPRECATED and will be removed in a future version. Use kubectl kubectl exec [POD] -- [COMMAND] instead.
Defaulting container name to redis.
Use 'kubectl describe pod/redis-redis-ha-server-0 -n dependency' to see all of the containers in this pod.
/data $
/data $
/data $
/data $ redis-cli -h redis-redis-ha.dependency.svc.cluster.local
redis-redis-ha.dependency.svc.cluster.local:6379> ping
PONG
redis-redis-ha.dependency.svc.cluster.local:6379>
1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11