搭建redis
# 搭建redis
首先使用docker搭建redis的命令是:
sudo docker run -d \
--restart=always \
--name redis \
-p 6379:6379 \
-v /data/redis/redis.conf:/usr/local/etc/redis/redis.conf \
hub.jdkhome.com:8543/jdkhome/redis:6.0 \
redis-server /usr/local/etc/redis/redis.conf
1
2
3
4
5
6
7
2
3
4
5
6
7
在k8s中,我们需要使用ConfigMap来提供 redis.conf
kubectl create configmap redis-configmap --from-file=redis.conf -n base
# 查看配置内容
1
2
2
查看配置内容
kubectl describe configmaps redis-configmap -n base
Name: redis-configmap
Namespace: base
Labels: <none>
Annotations: <none>
Data
====
redis.conf:
----
requirepass xxxxx
Events: <none>
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
使用这个configmap来编写redis的yaml
redis.yaml
---
apiVersion: v1
kind: Service
metadata:
name: redis-nodeport
spec:
type: NodePort
ports:
- port: 6379
nodePort: 30101
selector:
app: redis
---
apiVersion: v1
kind: Service
metadata:
name: redis-service
spec:
type: ClusterIP
ports:
- port: 6379
targetPort: 6379
selector:
app: redis
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: redis-deployment
labels:
app: redis
spec:
replicas: 1
selector:
matchLabels:
app: redis
template:
metadata:
labels:
app: redis
spec:
containers:
- name: redis
image: hub.jdkhome.com:8543/jdkhome/redis:6.0
command:
- redis-server
- "/usr/local/etc/redis/redis.conf"
env:
- name: MASTER
value: "true"
ports:
- containerPort: 6379
volumeMounts:
- mountPath: /usr/local/etc/redis
name: config
volumes:
- name: config
configMap:
name: redis-configmap
items:
- key: redis.conf
path: redis.conf
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
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
启动
kubectl apply -f redis.yaml -n base
1
上次更新: 2020/12/24, 21:12:00