9.4、环境变量(env)
1、创建pod-env.yaml文件,内容如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| apiVersion: v1 kind: Pod metadata: name: pod-env namespace: dev labels: version: "3.0" env: "busybox" spec: containers: - name: busybox image: registry.cn-hangzhou.aliyuncs.com/zznn/mycentos:busybox-1.30 imagePullPolicy: Always command: ["/bin/sh","-c","while true;do /bin/echo $(date +%T);sleep 60; done;"] env: - name: "username" value: "admin" - name: "password" value: "123456"
|
备注:env,环境变量,用于在pod中的容器设置环境变量。
2、验证
1 2 3 4 5 6 7 8
| kubectl create -f pod-env.yaml
kubectl exec pod-env -n dev -c busybox -it /bin/sh / admin / 123456
|
这种方式不是很推荐,推荐将这些配置单独存储在配置文件中,这种方式将在后面介绍。**