码迷,mamicode.com
首页 > 其他好文 > 详细

k8s官方案例练习-使用 ConfigMap 来配置 Redis

时间:2020-01-22 13:04:26      阅读:301      评论:0      收藏:0      [点我收藏+]

标签:items   info   mit   kubectl   file   source   over   state   delete   

使用 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

标签:items   info   mit   kubectl   file   source   over   state   delete   

原文地址:https://www.cnblogs.com/jackluo/p/12228304.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!