Skip to content

Bits of .NET

Daily micro-tips for C#, SQL, performance, and scalable backend engineering.

  • Asp.Net Core
  • C#
  • SQL
  • JavaScript
  • CSS
  • About
  • ErcanOPAK.com
  • No Access
  • Privacy Policy
Kubernetes

Kubernetes: Use ConfigMap and Secrets for External Configuration

- 13.06.26 - ErcanOPAK

🔐 Never Hardcode Config in Container Images

Environment variables are okay. ConfigMap and Secrets are better. Separate config from code. Change without rebuild.

📝 ConfigMap

# configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: app-config
data:
  database.host: postgres-service
  database.port: "5432"
  app.properties: |
    app.name=myapp
    app.environment=production
    log.level=info

# Use as environment variables
apiVersion: v1
kind: Pod
spec:
  containers:
  - name: myapp
    env:
    - name: DB_HOST
      valueFrom:
        configMapKeyRef:
          name: app-config
          key: database.host

🔒 Secrets

# Create secret
kubectl create secret generic db-secret \
  --from-literal=username=postgres \
  --from-literal=password=supersecret

# secret.yaml (base64 encoded)
apiVersion: v1
kind: Secret
metadata:
  name: db-secret
type: Opaque
data:
  username: cG9zdGdyZXM=  # echo -n 'postgres' | base64
  password: c3VwZXJzZWNyZXQ=  # echo -n 'supersecret' | base64

# Use in pod
spec:
  containers:
  - name: myapp
    env:
    - name: DB_USER
      valueFrom:
        secretKeyRef:
          name: db-secret
          key: username

💡 Best Practices

  • Never commit secrets to Git
  • Use external secret management (Vault, SealedSecrets)
  • Mount ConfigMap as volume for config files
  • Secrets are base64 encoded, not encrypted (use encryption at rest)

“Changed database password. Updated secret, restarted pods. No image rebuild. ConfigMap and Secrets are essential for configuration management.”

— DevOps Engineer

Related posts:

Kubernetes Pods Restart with No CPU or Memory Spikes

Kubernetes: Use PodDisruptionBudget for High Availability

Kubernetes: Use Jobs for One-Time Tasks and CronJobs for Scheduled Tasks

Post Views: 2

Post navigation

WordPress: Add Custom Dashboard Widgets for Clients
Docker: Use Docker Events to Monitor Container Lifecycle

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

July 2026
M T W T F S S
 12345
6789101112
13141516171819
20212223242526
2728293031  
« Jun    

Most Viewed Posts

  • Get the User Name and Domain Name from an Email Address in SQL (960)
  • How to add default value for Entity Framework migrations for DateTime and Bool (898)
  • How to make theater mode the default for Youtube (858)
  • Get the First and Last Word from a String or Sentence in SQL (840)
  • How to select distinct rows in a datatable in C# (814)
  • How to enable, disable and check if Service Broker is enabled on a database in SQL Server (597)
  • Add Constraint to SQL Table to ensure email contains @ (582)
  • Average of all values in a column that are not zero in SQL (545)
  • How to use Map Mode for Vertical Scroll Mode in Visual Studio (512)
  • Find numbers with more than two decimal places in SQL (460)

Recent Posts

  • C#: Use Using Statements for Resource Management
  • C#: Use Lambda Expressions for Concise Code
  • SQL: Use GROUP BY for Data Aggregation
  • .NET Core: Master Routing for Clean URLs
  • Git: Use Reset to Undo Local Changes
  • Ajax: Use Axios for HTTP Requests
  • JavaScript: Understand Hoisting
  • HTML: Use Web Storage for Client-Side Data
  • CSS: Use Filter Effects for Visual Magic
  • Windows 11: Unlock God Mode for All Settings

Most Viewed Posts

  • Get the User Name and Domain Name from an Email Address in SQL (960)
  • How to add default value for Entity Framework migrations for DateTime and Bool (898)
  • How to make theater mode the default for Youtube (858)
  • Get the First and Last Word from a String or Sentence in SQL (840)
  • How to select distinct rows in a datatable in C# (814)

Recent Posts

  • C#: Use Using Statements for Resource Management
  • C#: Use Lambda Expressions for Concise Code
  • SQL: Use GROUP BY for Data Aggregation
  • .NET Core: Master Routing for Clean URLs
  • Git: Use Reset to Undo Local Changes

Social

  • ErcanOPAK.com
  • GoodReads
  • LetterBoxD
  • Linkedin
  • The Blog
  • Twitter
© 2026 Bits of .NET | Built with Xblog Plus free WordPress theme by wpthemespace.com