方式对照
| 维度 | 环境变量 | 挂载卷 |
|---|---|---|
| 更新生效 | 需重启 Pod | ConfigMap/Secret 约 1 分钟同步 |
| 使用难度 | 简单直觉 | 涉及路径与权限 |
| 热更新支持 | 不支持 | 支持(应用需重读) |
| subPath 陷阱 | 无 | subPath 挂载不接收更新 |
| 适用 | 启动参数/开关 | 配置文件/证书轮转 |
挂载示例
挂载示例
volumes:
- name: conf
configMap:
name: app-conf
- name: tls
secret:
secretName: app-example-tls
containers:
- name: app
image: registry.example.com/team/app:1.2.3
volumeMounts:
- { name: conf, mountPath: /etc/app, readOnly: true }
- { name: tls, mountPath: /etc/tls, readOnly: true }
证书轮转常选挂载卷 + 应用热加载;nginx 等进程需要 reload 信号时可配 reloader 类工具实现自动重启。