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:
----
agfaagfsgfdetrtrewfgfsdgfBinaryData
====Events: <none>
这里的key=log_level.conf value为对应的内容
2.创建pod
[root@master yaml_test]# more busybox.yaml
apiVersion: v1
kind: Pod
metadata:name: configmap-podnamespace: "test"
spec:containers:- name: testimage: registry.cn-shenzhen.aliyuncs.com/hxlk8s/busybox:1.32command: ['sh', '-c', 'echo "The app is running!" && tail -f /dev/null']volumeMounts:- name: config-volmountPath: /etc/configvolumes:- name: config-volconfigMap:name: log-configitems:- key: log_level.confpath: log_level.conf
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
