Configmap 文件
[root@k8smaster4 mysql]# cat mysql.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: mysql-configmap
labels:
environment: test
app: mysql
data:
up: "1"
lower: "3"
Pod Yaml 示例
[root@k8smaster4 mysql]# cat mysql-envFrom.yaml
apiVersion: v1
kind: Pod
metadata:
name: mysql-envfrom
labels:
environment: test-envfrom
app: mysql-envfrom
spec:
containers:
- name: mysql-envfrom
image: docker.io/library/busybox
imagePullPolicy: IfNotPresent
command: ["/bin/sh","-c","sleep 3600"]
env:
- name: login_in
valueFrom:
configMapKeyRef:
name: mysql-configmap
key: up
- name: login_off
valueFrom:
configMapKeyRef:
name: mysql-configmap
key: lower
restartPolicy: Never
查看Pod运行结果
[root@k8smaster4 mysql]# kubectl get pods -l app=mysql-envfrom
NAME READY STATUS RESTARTS AGE
mysql-envfrom 1/1 Running 0 103s
查看容器环境参数
[root@k8smaster4 mysql]# kubectl exec -it mysql-envfrom -c mysql-envfrom -- /bin/sh
/ # printenv
login_in=1
KUBERNETES_SERVICE_PORT=443
KUBERNETES_PORT=tcp://10.96.0.1:443
HOSTNAME=mysql-envfrom
SHLVL=1
HOME=/root
NGINX_TEST_SERVICE_HOST=10.105.242.121
NGINX_TEST_PORT=tcp://10.105.242.121:80
NGINX_TEST_SERVICE_PORT=80
TERM=xterm
KUBERNETES_PORT_443_TCP_ADDR=10.96.0.1
NGINX_TEST_SERVICE_PORT_WEB=80
NGINX_TEST_PORT_80_TCP_ADDR=10.105.242.121
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
KUBERNETES_PORT_443_TCP_PORT=443
login_off=3
KUBERNETES_PORT_443_TCP_PROTO=tcp