configmap在容器中的使用问题

configmap示例

apiVersion: v1
kind: ConfigMap
metadata:
  name: test-configmap
data:
  # 简单的key-value键值对
  username: "zhangsan"
  password: "password"

  # 文件名作为key,文件内容为value  
  test.conf: |
    host  127.0.0.1
    user  root
    password 123  

configmap日常用法

apiVersion: v1
kind: Pod
metadata:
  name: test-pod
spec:
  containers:
    - name: test
      image: centos
      command:
      - /bin/bash
      args:
      - '-c'
      - while true; do echo hello; sleep 1; done
      env:
        # 环境变量中使用configmap
        - name: USERNAME
          valueFrom:
            configMapKeyRef:
              name: test-configmap  # 设置需要从哪个configmap获取数据
              key: username         # 获取configmap中哪个key的数据
      volumeMounts:
      # 1. 直接将test.conf挂载到/config下,如果/config不为空,目录内容会被覆盖
      - name: config
        mountPath: /config
        readOnly: true
      # 2. 使用subPath,不会覆盖/config目录中原有的内容
      #- name: config
      #  mountPath: /config/test.conf
      #  subPath: test.conf
      #  readOnly: true
  volumes:
    - name: config
      configMap:
        name: test-configmap
        items:
        - key: "test.conf"
          path: "test.conf"
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值