デプロイ時の設定と秘密情報の管理
環境変数、ConfigMap、シークレットマネージャーを使い、設定を外部化してAPIキーなどの秘密情報をデプロイ済みLLMアプリケーションに安全に注入する方法を学びます。
「デプロイ時の設定と秘密情報の管理」はCoddyKit上の無料LLM Apps in Production (RAG + Vector DB + Caching)レッスンです。 これはレッスン4/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応の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.
よくある質問
「デプロイ時の設定と秘密情報の管理」レッスンは無料ですか?
はい。「デプロイ時の設定と秘密情報の管理」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、LLM Apps in Production (RAG + Vector DB + Caching)コースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 LLM Apps in Production (RAG + Vector DB + Caching)コースには全4レッスンが含まれています。
「デプロイ時の設定と秘密情報の管理」で何を学びますか?
環境変数、ConfigMap、シークレットマネージャーを使い、設定を外部化してAPIキーなどの秘密情報をデプロイ済みLLMアプリケーションに安全に注入する方法を学びます。 ブラウザで直接実行するハンズオンコードでLLM Apps in Production (RAG + Vector DB + Caching)を演習し、24時間対応の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フィードバックを取得できます。ローカル設定は不要です。