管理部署中的配置与秘密信息
学习如何将配置外置,并使用环境变量、配置映射和秘密管理器,将 API 密钥等秘密信息安全地注入已部署的 LLM 应用。
管理部署中的配置与秘密信息 是 CoddyKit 上的免费 LLM Apps in Production (RAG + Vector DB + Caching) 课时。 这是第 4 节课,共 4 节。 你可以在下方免费阅读本课时的完整内容 — 然后在浏览器中使用内置代码编辑器和全天候 AI 导师进行实践。 这是 LLM Apps in Production (RAG + Vector DB + Caching) 学习路径的一部分,你的进度在网页和 CoddyKit 应用中同步。 LLM Apps in Production (RAG + Vector DB + Caching) 课程共包含 4 节课。
本课时的部分内容尚未翻译,以英文显示。
Config Belongs Outside Code
The same LLM app image runs in dev, staging, and production. The only difference should be configuration, not the code. Hard-coding endpoints or keys forces a rebuild for every environment.
This is the core idea of config externalization.
Config vs Secrets
Two related but distinct concepts:
- Config — non-sensitive settings: model name, temperature, log level
- Secrets — sensitive values: API keys, DB passwords, tokens
Secrets need stricter handling and must never be logged.
Environment Variables
The simplest portable mechanism is environment variables.
import os
model = os.environ.get('LLM_MODEL', 'gpt-mini')
temp = float(os.environ.get('LLM_TEMPERATURE', '0.2'))
print('Using', model, 'at temp', temp)The Twelve-Factor Approach
The twelve-factor methodology says store config in the environment. This keeps the build artifact identical across environments and avoids accidentally committing secrets into version control.
Kubernetes ConfigMaps
In Kubernetes, non-sensitive config lives in a ConfigMap and is injected as env vars or files.
apiVersion: v1
kind: ConfigMap
metadata:
name: llm-config
data:
LLM_MODEL: 'gpt-mini'
LLM_TEMPERATURE: '0.2'Kubernetes Secrets
Sensitive values go in a Secret object, kept separate from ConfigMaps and mounted with tighter access controls. Base64 encoding is not encryption, so enable encryption at rest.
apiVersion: v1
kind: Secret
metadata:
name: llm-secrets
type: Opaque
stringData:
OPENAI_API_KEY: 'set-via-pipeline'Dedicated Secret Managers
For production, use a dedicated secret manager:
- HashiCorp Vault
- AWS Secrets Manager
- GCP Secret Manager
They offer rotation, audit logs, and fine-grained access far beyond plain env vars.
Fetching Secrets at Runtime
Apps can pull secrets at startup from a manager instead of baking them in. This centralizes rotation.
def load_secret(name):
store = {'OPENAI_API_KEY': 'sk-demo'}
if name not in store:
raise KeyError('missing secret: ' + name)
return store[name]
print(load_secret('OPENAI_API_KEY')[:7])Validating Config at Startup
Fail fast: validate that all required config and secrets are present when the app boots, not when the first request arrives. A clear startup error beats a confusing 500 in production.
Avoiding Secret Leaks
Common leak vectors to guard against:
- Logging full request objects that include keys
- Echoing env vars in debug endpoints
- Committing .env files
- Exposing secrets in error stack traces
Rotation and Per-Environment Keys
Use separate keys per environment and rotate them on a schedule. With a secret manager, rotation updates one place and all instances pick it up without a redeploy.
Quick Check
Test your understanding of Kubernetes config.
Recap
You learned to externalize config from code and separate it from secrets. Use environment variables and ConfigMaps for settings, Secrets and dedicated managers for sensitive values, validate everything at startup, and rotate keys per environment without leaking them in logs.
用 AI 导师学习 LLM Apps in Production (RAG + Vector DB + Caching) — 免费
在浏览器中编写并运行真实代码,获得全天候 AI 导师的即时帮助,并在网页或应用中继续学习。
- 课程
- 12
- 课程
- 48
常见问题解答
「管理部署中的配置与秘密信息」课时是免费的吗?
是的 — 「管理部署中的配置与秘密信息」的完整文本可在网页上免费阅读。要进行交互式练习(内置代码编辑器和全天候 AI 导师)并解锁 LLM Apps in Production (RAG + Vector DB + Caching) 课程的其余内容,请升级到 CoddyKit PRO。 LLM Apps in Production (RAG + Vector DB + Caching) 课程共包含 4 节课。
「管理部署中的配置与秘密信息」这节课中我会学到什么?
学习如何将配置外置,并使用环境变量、配置映射和秘密管理器,将 API 密钥等秘密信息安全地注入已部署的 LLM 应用。 你通过在浏览器中直接运行的动手代码来练习 LLM Apps in Production (RAG + Vector DB + Caching),全天候 AI 导师会在你学习这节课的过程中回答你的问题。
学习 LLM Apps in Production (RAG + Vector DB + Caching) 需要有经验吗?
无需任何先前经验。CoddyKit 上的 LLM Apps in Production (RAG + Vector DB + Caching) 课程适合初学者到高级学习者,你可以从这里开始或从头开始,按照自己的节奏学习。 这是第 4 节课,共 4 节。
「管理部署中的配置与秘密信息」课时需要多长时间?
大多数 CoddyKit 课程大约需要 5–10 分钟。每节课都很精短且互动,所以你能稳步进步,并在网页和应用中从离开的地方继续。
我能在这节 LLM Apps in Production (RAG + Vector DB + Caching) 课中编写并运行代码吗?
能。每节 LLM Apps in Production (RAG + Vector DB + Caching) 课都包含内置代码编辑器,你可以在浏览器中直接编写并运行真实代码,并获得即时 AI 反馈 — 无需本地设置。