K8S之ConfigMap

参考视频:https://ke.qq.com/user/index/index.html#/plan/cid=1709963&term_id=102815140

一、概念

Pod使用ConfigMap挂载的两种方式

  • 变量注入

  • 数据卷挂载

二、实例

2.1.创建一个configmap

apiVersion: v1
kind: ConfigMap
metadata:
  name: redis-cfg
data:
  #以键值对的形式定义
  abc: "123"
  bcd: "456"

  #以文本的形式定义,适用于多行文件
  redis.properties: |
    port: 6379
    host: 192.168.1.10

2.2.Pod使用configmap

apiVersion: v1
kind: Pod
metadata:
  name: configmap-demo-pod
spec:
  containers:
    - name: demo
      image: nginx
      imagePullPolicy: IfNotPresent
      env:
        - name: ABC
          valueFrom:
            configMapKeyRef:
              name: redis-cfg
              key: abc
        - name: BCD
          valueFrom:
            configMapKeyRef:
              name: redis-cfg
              key: bcd
      volumeMounts:
      - name: config
        mountPath: "/config"
        readOnly: true
  volumes:
    - name: config
      configMap:
        name: redis-cfg
        items:
        - key: "redis.properties"
          path: "redis_config"

进入到容器中查看
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/anqixiang/article/details/109012315