Skip to content

ConfigMap

一句话解释

ConfigMap 是 Kubernetes resource 那个存储非-confidential 配置数据 in 键-值 pairs, separate 从容器镜像.

用大白话说

A ConfigMap lets you store configuration data outside of your container image, so you can change configuration without rebuilding the image. It holds non-sensitive data as key-value pairs.

例如, you might store a database host name, a log level, or a feature flag URL in a ConfigMap. Your application reads these values at startup, and you can update them by editing the ConfigMap — no image rebuild needed.

ConfigMaps are perfect for environment-specific settings: you can have different ConfigMaps for development, staging, and production, all using the same container image. For sensitive data like passwords, use a Secret instead.

示例

yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: app-config
data:
  LOG_LEVEL: "debug"
  DB_HOST: "db.example.com"
  MAX_CONNECTIONS: "100"

这个 ConfigMap 存储 three 配置值 那个能 是 injected 到 Pod as 环境变量.

工作原理

  1. You create a ConfigMap with key-value configuration data.
  2. You reference it in your Pod spec — as environment variables or mounted files.
  3. The container reads the configuration at startup.
  4. Update the ConfigMap and restart the Pod to apply changes.

常见混淆

  • 容易混淆的对象: Secret

    关键区别: ConfigMaps 存储非-sensitive 数据 in plain 文本; Secrets 存储 sensitive 数据如 密码 and 令牌, base64-encoded.

相关术语

解读错误信息

用大白话解释常见错误——什么意思、为什么发生、如何修复。

查看错误

← 返回术语表