configmap使用
1.从文件中创建
kubectl create configmap log-config --from-file=log_level.conf -n test
查看
[root@master yaml_test]# kubectl describe cm log-config -n test
Name: log-config
Namespace: test
Labels: <none>
Annotations: <none>
Data
====
log_level.conf:
----
agfaagfsgfdetrtrewfg
fsdgf
BinaryData
====
Events: <none>
这里的key=log_level.conf value为对应的内容
2.创建pod
[root@master yaml_test]# more busybox.yaml
apiVersion: v1
kind: Pod
metadata:
name: configmap-pod
namespace: "test"
spec:
containers:
- name: test
image: registry.cn-shenzhen.aliyuncs.com/hxlk8s/busybox:1.32
command: ['sh', '-c', 'echo "The app is running!" && tail -f /dev/null']
volumeMounts:
- name: config-vol
mountPath: /etc/config
volumes:
- name: config-vol
configMap:
name: log-config
items:
- key: log_level.conf
path: log_level.conf ##这里的path可以定义为其他的文件名称,比如aaaa.conf,不一定与key名称一致
创建pod
kubectl apply -f busybox.yaml
3.登录pod查看
kubectl exec -it configmap-pod -n test -- /bin/sh
/etc/config # pwd
/etc/config
/etc/config # ls
log_level.conf
会在/etc/config这个目录下生成文件log_level.conf
浙公网安备 33010602011771号