k8s官方案例练习-使用 ConfigMap 来配置 Redis
Posted jackluo
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了k8s官方案例练习-使用 ConfigMap 来配置 Redis相关的知识,希望对你有一定的参考价值。
使用 ConfigMap 来配置 Redis
[root@master01 ~]# mkdir kustomization [root@master01 ~]# cd kustomization/ [root@master01 kustomization]# vi kustomization.yaml [root@master01 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"} [root@master01 kustomization]#
[root@master01 kustomization]# ls
kustomization.yaml redis-config redis-pod.yaml
[root@master01 kustomization]# cat kustomization.yaml
configMapGenerator:
- name: example-redis-config
files:
- redis-config
resources:
- redis-pod.yaml
[root@master01 kustomization]# cat redis-config
maxmemory 2mb
maxmemory-policy allkeys-lru
[root@master01 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
[root@master01 kustomization]#
[root@master01 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
[root@master01 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 [root@master01 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
删除
[root@master01 kustomization]# kubectl apply -k . configmap/example-redis-config-dgh9dg555m unchanged pod/redis configured [root@master01 kustomization]# kubectl delete pod redis pod "redis" deleted [root@master01 kustomization]#
以上是关于k8s官方案例练习-使用 ConfigMap 来配置 Redis的主要内容,如果未能解决你的问题,请参考以下文章
k8s官方案例练习-使用 Redis 部署 PHP 留言板应用程序