2.4、深入pod-configMap
2019-06-16 本文已影响0人
yezide
1、 创建configMap
1.1 yaml文件方式
太长,详见此
创建命令
kubectl create -f cm-appconfigfiles.yaml
1.2 命令行方式
kubectl create cm cm_test --from-literal=k1=v1
1.3 pod通过环境变量使用cm
apiVersion: v1
kind: ConfigMap
metadata:
name: cm-appvars
data:
appLogLevel: info
appDataDir: /var/data
创建个容器使用cm
apiVersion: v1
kind: Pod
metadata:
name: cm-test-pod
spec:
containers:
- name: cm-test-container
image: busybox
command: ["/bin/sh", "-c", "env | grep APP"]
env:
- name: APPLOGLEVEL
valueFrom:
configMapKeyRef:
name: cm-appvars
key: appLogLevel
- name: APPDATADIR
valueFrom:
configMapKeyRef:
name: cm-appvars
key: appDataDir
1.4 通过volumeMount方式使用
apiVersion: v1
kind: Pod
metadata:
name: cm-test-app
spec:
containers:
- name: cm-test-app
image: kubeguide/tomcat-app:v1
ports:
- containerPort: 80
volumeMounts:
- name: v-serverxml #引用的volume名
mountPath: /configs
volumes:
- name: v-serverxml
configMap:
name: cm-appconfigfiles #使用这个名字的cm
items:
- key: key-svr-xml
path: server.xml
- key: key-log4j-pro
path: logging.properties
登陆容器,看/configs目录下是否有2个文件server.xml和logging.properties
kubectl exec -it cm-test-app -- bash
cd /configs
ls -l