您的位置 首页 k8s

pod 清单文件configMap 实战 nginx 案例

pod 清单文件configMap 实战 nginx 案例

pod 清单文件configMap 详解 : 连接

案例1 :

需求: 我们配置 nginx  的时候, 希望经常修改 nginx的 80端口。

这个时候可以配置一个 configmap , 把 经常变动的内容写进去。 然后在 pod 清单中,自动的加载, 进去。

接下来我们来做个实战 案例:

kubectl apply -f nginx_conf_mapconfig.yaml

 

[root@master231 ~]#cat nginx_conf_mapconfig.yaml

 


apiVersion: v1
kind: ConfigMap
metadata: 
  name:  nginx-conf
#指定configmap 数据
data: 
  games.conf: | 
      server {
          listen        0.0.0.0:88;
          root          /usr/local/nginx/html/bird/;
          server_name   game01.baimei.com;
      }
      server {
          listen        0.0.0.0:88;
          root          /usr/local/nginx/html/pinshu/;
          server_name   game02.baimei.com;
      }

kubectl get cm nginx-conf 

 

 

然后我们 pod  资源清单中 引用 这个配置文件。

apiVersion: v1
kind: Pod
metadata:
  name: baimei-games-cm-008
spec:
  nodeName: worker233
  # hostNetwork: true
  volumes:
  - name: data01
    configMap:
      name: nginx-conf
  containers:
  - name: games
    image: harbor.baimei.com/baimei-games/games:v0.5
    volumeMounts:
    - name: data01
      #mountPath: /baimei-linux86
      mountPath: /etc/nginx/conf.d/

 

这个时候, 挂载点 里边指定了 data01 这个数据, 为 configMap -》》 nginx-conf

 

kubectl describe cm cm-env 

 

案例2:

env注入configMap环境变量及字段引用 实战案例 valueFrom 字段 : 连接 

欢迎来撩 : 汇总all

白眉大叔

关于白眉大叔linux云计算: 白眉大叔

热门文章