LLM Apps in Production (RAG + Vector DB + Caching) · Lezione

Gestire configurazione e segreti nel deployment

Imparate a esternalizzare la configurazione e a iniettare in sicurezza segreti come le chiavi API nelle applicazioni LLM distribuite, usando variabili d’ambiente, config map e secret manager.

Lezione 4 di 413 passaggi

Gestire configurazione e segreti nel deployment è una lezione LLM Apps in Production (RAG + Vector DB + Caching) gratuita su CoddyKit. Questa è la lezione 4 di 4. Puoi leggere la lezione completa qui gratuitamente — poi esercitati direttamente nel browser con un editor di codice integrato e un tutor IA disponibile 24/7. Fa parte del percorso di apprendimento LLM Apps in Production (RAG + Vector DB + Caching), e i tuoi progressi si sincronizzano tra il web e l'app CoddyKit. Il corso LLM Apps in Production (RAG + Vector DB + Caching) include 4 lezioni in totale.

Parti di questa lezione non sono ancora state tradotte e vengono mostrate in inglese.

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.

Gratis per iniziare

Impara LLM Apps in Production (RAG + Vector DB + Caching) con un tutor IA — gratis

Scrivi ed esegui vero codice nel tuo browser, ricevi aiuto istantaneo da un tutor IA disponibile 24/7, e riprendi da dove hai lasciato sul web o nell'app.

Corsi
12
Lezioni
48

Domande Frequenti

La lezione «Gestire configurazione e segreti nel deployment» è gratuita?

Sì — il testo completo di «Gestire configurazione e segreti nel deployment» è gratuito qui sul web. Per esercitarvi in modo interattivo (un editor di codice integrato e un tutor IA 24/7) e sbloccare il resto del corso LLM Apps in Production (RAG + Vector DB + Caching), passa a CoddyKit PRO. Il corso LLM Apps in Production (RAG + Vector DB + Caching) include 4 lezioni in totale.

Cosa imparerò in «Gestire configurazione e segreti nel deployment»?

Imparate a esternalizzare la configurazione e a iniettare in sicurezza segreti come le chiavi API nelle applicazioni LLM distribuite, usando variabili d’ambiente, config map e secret manager. Eserciti LLM Apps in Production (RAG + Vector DB + Caching) con codice pratico che esegui direttamente nel browser, e un tutor IA 24/7 risponde alle tue domande mentre lavori sulla lezione.

Ho bisogno di esperienza per iniziare LLM Apps in Production (RAG + Vector DB + Caching)?

Non è richiesta alcuna esperienza precedente. LLM Apps in Production (RAG + Vector DB + Caching) su CoddyKit è strutturato per principianti e studenti avanzati, quindi puoi iniziare da qui o dall'inizio e procedere al tuo ritmo. Questa è la lezione 4 di 4.

Quanto tempo richiede la lezione «Gestire configurazione e segreti nel deployment»?

La maggior parte delle lezioni CoddyKit richiede circa 5–10 minuti. Ogni lezione è breve e interattiva, quindi fai progressi costanti e riprendi esattamente da dove hai lasciato su web e app.

Posso scrivere ed eseguire codice in questa lezione LLM Apps in Production (RAG + Vector DB + Caching)?

Sì. Ogni lezione LLM Apps in Production (RAG + Vector DB + Caching) include un editor di codice integrato, quindi scrivi ed esegui codice reale direttamente nel tuo browser e ricevi feedback istantaneo dall'IA — nessuna configurazione locale necessaria.

Tutte le lezioni di questo corso

  1. Containerizzare applicazioni LLM con Docker
  2. Orchestrazione con Kubernetes per la scalabilità
  3. CI/CD per la distribuzione di applicazioni LLM
  4. Gestire configurazione e segreti nel deployment
← Torna a LLM Apps in Production (RAG + Vector DB + Caching)