K8S 通过configMap引用环境变量
K8S 通过configMap引用环境变量以nginx为例1. 创建configMapconf.yaml配置中新建两个环境变量ENV_1和ENV_NAMEapiVersion: v1kind: ConfigMapmetadata:name: nginx-confdata:ENV_1: "111.111.111.111"ENV_NAME: "test"kubectl apply -f conf.ya
·
K8S 通过configMap引用环境变量
- 以nginx为例
1. 创建configMap
- conf.yaml
- 配置中新建两个环境变量ENV_1和ENV_NAME
apiVersion: v1
kind: ConfigMap
metadata:
name: nginx-conf
data:
ENV_1: "111.111.111.111"
ENV_NAME: "test"
kubectl apply -f conf.yaml
2. 创建pod,批量引用环境变量
- nginx.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx
spec:
replicas: 1
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx
ports:
- containerPort: 80
# 导入环境变量
envFrom:
# 使用configMap
- configMapRef:
# name为configMap中的metadata name
name: nginx-config
- 部署
# 部署
kubectl apply -f nginx.yaml
# 查看pod
kubectl get pods
# 查看pod内部环境变量
kubectl exec -it nginx-587df9cfb6-67k72 -- env
- 完成
更多推荐
已为社区贡献2条内容
所有评论(0)