使用 ConfigMap 来配置 Redis
[[email protected] ~]# mkdir kustomization [[email protected] ~]# cd kustomization/ [[email protected] kustomization]# vi kustomization.yaml [[email protected] kustomization]# kubectl version Client Version: version.Info{Major:"1", Minor:"16", GitVersion:"v1.16.4", GitCommit:"224be7bdce5a9dd0c2fd0d46b83865648e2fe0ba", GitTreeState:"clean", BuildDate:"2019-12-11T12:47:40Z", GoVersion:"go1.12.12", Compiler:"gc", Platform:"linux/amd64"} Server Version: version.Info{Major:"1", Minor:"16", GitVersion:"v1.16.4", GitCommit:"224be7bdce5a9dd0c2fd0d46b83865648e2fe0ba", GitTreeState:"clean", BuildDate:"2019-12-11T12:37:43Z", GoVersion:"go1.12.12", Compiler:"gc", Platform:"linux/amd64"} [[email protected] kustomization]#
[[email protected] kustomization]# ls
kustomization.yaml redis-config redis-pod.yaml
[[email protected] kustomization]# cat kustomization.yaml
configMapGenerator:
- name: example-redis-config
files:
- redis-config
resources:
- redis-pod.yaml
[[email protected] kustomization]# cat redis-config
maxmemory 2mb
maxmemory-policy allkeys-lru
[[email protected] kustomization]# cat redis-pod.yaml
apiVersion: v1
kind: Pod
metadata:
name: redis
spec:
containers:
- name: redis
image: redis:5.0.4
command:
- redis-server
- "/redis-master/redis.conf"
env:
- name: MASTER
value: "true"
ports:
- containerPort: 6379
resources:
limits:
cpu: "0.1"
volumeMounts:
- mountPath: /redis-master-data
name: data
- mountPath: /redis-master
name: config
volumes:
- name: data
emptyDir: {}
- name: config
configMap:
name: example-redis-config
items:
- key: redis-config
path: redis.conf
[[email protected] kustomization]#
[[email protected] kustomization]# kubectl get pod NAME READY STATUS RESTARTS AGE kuard-5cd647675b-65cwg 1/1 Running 0 45h kuard-5cd647675b-65r9c 1/1 Running 0 45h kuard-5cd647675b-f9r9f 1/1 Running 0 45h nginx 1/1 Running 0 42h nginx-78b75497b7-rpt8t 1/1 Running 0 19h redis 0/1 ContainerCreating 0 3m37s
[[email protected] kustomization]# kubectl get pod NAME READY STATUS RESTARTS AGE kuard-5cd647675b-65cwg 1/1 Running 0 45h kuard-5cd647675b-65r9c 1/1 Running 0 45h kuard-5cd647675b-f9r9f 1/1 Running 0 45h nginx 1/1 Running 0 42h nginx-78b75497b7-rpt8t 1/1 Running 0 19h redis 1/1 Running 0 4m10s [[email protected] kustomization]# kubectl exec -it redis redis-cli 127.0.0.1:6379> CONFIG GET maxmemory 1) "maxmemory" 2) "2097152" 127.0.0.1:6379> CONFIG GET maxmemory-policy 1) "maxmemory-policy" 2) "allkeys-lru" 127.0.0.1:6379> exit
删除
[[email protected] kustomization]# kubectl apply -k . configmap/example-redis-config-dgh9dg555m unchanged pod/redis configured [[email protected] kustomization]# kubectl delete pod redis pod "redis" deleted [[email protected] kustomization]#
原文地址:https://www.cnblogs.com/jackluo/p/12228304.html