kubernetes》》k8s》》ConfigMap 、Secret

configmap官网

ConfigMap是一种 API 对象,使用时, Pods 可以将其用作环境变量、命令行参数或者存储卷中的配置文件。ConfigMap将配置和Pod解耦,更易于配置文件的更改和管理。ConfigMap 并不提供保密或者加密功能。 如果你想存储的数据是机密的,请使用Secret。

参考资料

ConfigMap的生命周期以及使用方式,


csharp 复制代码
# configmap 配置文件
apiVersion: v1
kind: ConfigMap
metadata:
 name: k8s-config
data:
 key1: hello
 key2: k8s

》》volume挂载

csharp 复制代码
# 在volumes配置中通过对configMap的name进行匹配,然后根据key字段取出对应的配置,并绑定到对印的path上。
volumes:
      - name: "test-log-config"             #创建volume的名称        
        configMap:          
          name: "test-conf"                 #引用configMap卷
          items:
            - key: "log4j2.xml"             #根据key获取configMap指定的配置
              path: "log4j2.xml"
      - name: "test-init-config"
        configMap:
          name: "test-conf"
          items:
            - key: "init-config.json"             #根据key获取configMap指定的配置
              path: "init-config.json"
      - name: "test-application"
        configMap:
          name: "test-conf"
          items:
            - key: "test-application-remote.properties"             #根据key获取configMap指定的配置
              path: "application-remote.properties"
 # 接下来就是使用volumeMounts属性对volume进行mount,当Pod实例化以后会将配置文件生成到具体路径供业务系统使用:
 volumeMounts:
          - name: "test-application"
            mountPath: "/home/test/app/config/application-remote.properties"
            subPath: "application-remote.properties"
          - name: "test-init-config"
            mountPath: "/home/test/app/config/init-config.json"
            subPath: "init-config.json"
          - name: "test-log-config"
            mountPath: "/home/test/app/config/log4j2.xml"
            subPath: "log4j2.xml"
相关推荐
AI攻城狮37 分钟前
OpenClaw Session 管理完全指南:Context 压缩、重置与持久化
人工智能·云原生·aigc
蝎子莱莱爱打怪21 小时前
GitLab CI/CD + Docker Registry + K8s 部署完整实战指南
后端·docker·kubernetes
阿里云云原生4 天前
阿里云获评 Agentic AI 开发平台领导者,函数计算 AgentRun 赢下关键分!
云原生
蝎子莱莱爱打怪4 天前
Centos7中一键安装K8s集群以及Rancher安装记录
运维·后端·kubernetes
崔小汤呀4 天前
Docker部署Nacos
docker·容器
缓解AI焦虑4 天前
Docker + K8s 部署大模型推理服务:资源划分与多实例调度
docker·容器
阿里云云原生4 天前
MSE Nacos Prompt 管理:让 AI Agent 的核心配置真正可治理
微服务·云原生
阿里云云原生5 天前
当 AI Agent 接管手机:移动端如何进行观测
云原生·agent
阿里云云原生5 天前
AI 原生应用开源开发者沙龙·深圳站精彩回顾 & PPT下载
云原生
阿里云云原生5 天前
灵感启发:日产文章 100 篇,打造“实时热点洞察”引擎
云原生