Microservices Mastery

K8s ConfigMaps & Secrets: Managing environment variables

1 Views Updated 5/4/2026

ConfigMaps & Secrets

According to the 12-Factor App methodology, configuration must be separate from code. In Kubernetes, we use ConfigMaps for non-sensitive data (like API URLs) and Secrets for sensitive data (like DB passwords or JWT keys).

1. ConfigMaps

ConfigMaps can be injected into your .NET container as **Environment Variables** or as **Mounted Files**. This allows you to change the "Logging Level" of your app without rebuilding the Docker image.

2. Secrets

Secrets are base64 encoded and stored securely. In a professional environment, you should integrate K8s Secrets with a hardware vault like **Azure Key Vault** or **HashiCorp Vault** for maximum security.

3. Zero-Restart Updates

If you mount a ConfigMap as a file, and you update the ConfigMap in K8s, the file inside your container updates automatically. Your .NET appsettings.json can be configured to "Reload on Change," allowing you to update config without restarting the server!

4. Interview Mastery

Q: "Why is base64 encoding in K8s Secrets NOT considered encryption?"

Architect Answer: "Base64 is just a formatting encoding; anyone can decode it instantly with a simple command. It is provided purely to handle binary data or characters not allowed in YAML. For true security, you must enable **At-Rest Encryption** in your Kubernetes cluster (ETCD encryption) and use strict Role-Based Access Control (RBAC) to limit who can view the secrets."

Microservices Mastery
1. Distributed Systems Fundamentals
Monolith vs Microservices: When to migrate? The 12-Factor App Methodology for Cloud-Native Apps Database Per Service: Handling distributed data consistency
2. Containerization & Orchestration
Docker Essentials: Building efficient .NET images Docker Compose: Orchestrating a multi-service environment Kubernetes Architecture: Pods, Services, and Deployments K8s ConfigMaps & Secrets: Managing environment variables Helm Charts: Packaging your microservices for K8s
3. Service Communication
Synchronous vs Asynchronous Communication: Pros and Cons REST APIs in a Microservices World: Best Practices Mastering gRPC: High-performance binary communication API Gateways: Implementing Ocelot for single-entry access BFF Pattern: Backend-for-Frontend (Mobile vs Web)
4. Event-Driven Architecture
Message Brokers: Introduction to RabbitMQ & Azure Service Bus Pub/Sub Pattern: Implementing MassTransit for .NET The Outbox Pattern: Ensuring 100% data consistency Dead Letter Queues: Handling message failure gracefully Distributed Transactions: The Saga Pattern (State Machines)
5. Resilience & Scalability
Distributed Caching with Redis: Optimizing global state Service Discovery: IdentityServer4 & Consul Load Balancing: Nginx vs Ingress Controllers The Sidecar Pattern: Offloading cross-cutting concerns
6. Observability & Security
Distributed Logging with Serilog & SEQ Distributed Tracing: OpenTelemetry & Jaeger Health Checks: Monitoring system vitals in real-time OAuth2 & OpenID Connect: Centralized Identity (AuthN/AuthZ) Rate Limiting & Throttling: Protecting your services
7. Advanced Cloud Topics
Infrastructure as Code (IaC): Introduction to Terraform CI/CD Pipelines for Microservices (GitHub Actions/Azure DevOps) C# Architect Interview: Microservices & System Design Focus