
Table of Contents
By Khimananda Oli | Last reviewed: August 2026
Mismanaged configuration is the leading cause of preventable outages and security breaches in container orchestration. Getting Kubernetes Secrets and ConfigMaps done right requires moving beyond basic YAML manifests to implement encryption at rest, strict RBAC, and external secret stores. This guide covers the production-grade patterns I use daily to keep clusters secure and compliant, building on the foundational deployment concepts covered in Kubernetes basics: deploy your first app to a k8s cluster.
What is the difference between Kubernetes Secrets and ConfigMaps?
While both resources store key-value pairs for pod consumption, they serve fundamentally different security domains. ConfigMaps are designed for non-sensitive configuration data such as feature flags, logging levels, or application properties that can safely exist in version control. Secrets are specifically intended for sensitive material like database passwords, TLS certificates, and API tokens.
A common mistake is treating Secrets as truly encrypted by default. In standard Kubernetes installations, Secrets are only base64-encoded, not encrypted. Anyone with read access to the etcd datastore or the API server can decode them instantly. True security requires enabling EncryptionConfiguration at the API server level or delegating storage to an external provider. For teams adopting GitOps with ArgoCD, this distinction is critical because ConfigMaps can be safely synced from Git repositories while Secrets must be injected separately.
How do you securely manage Kubernetes Secrets in production?
Production environments demand more than native Kubernetes primitives. The most reliable approach combines encryption at rest with external secret synchronization. Native Secrets should be treated as ephemeral cache rather than source of truth.
Enable encryption at rest
Before storing any credentials natively, configure the API server to encrypt Secret objects in etcd. Create an encryption configuration file:
apiVersion: apiserver.config.k8s.io/v1
kind: EncryptionConfiguration
resources:
- resources:
- secrets
providers:
- aescbc:
keys:
- name: key1
secret: <base64-encoded-32-byte-key>
- identity: {} The identity provider acts as a fallback for reading unencrypted data during migration. Always test decryption procedures before applying this to production clusters.
Use External Secrets Operator
For SOC 2 or ISO 27001 compliance, native Secrets rarely suffice. The External Secrets Operator synchronizes credentials from HashiCorp Vault, AWS Secrets Manager, or GCP Secret Manager into Kubernetes automatically. This pattern ensures credentials never touch disk in plaintext and supports automatic rotation without pod restarts. See secrets management with HashiCorp Vault for detailed integration patterns.
apiVersion: external-secrets.io/v1beta1
kind: ExternalSecret
metadata:
name: db-credentials
spec:
refreshInterval: 1h
secretStoreRef:
name: vault-backend
kind: ClusterSecretStore
target:
name: db-credentials-secret
data:
- secretKey: password
remoteRef:
key: secret/data/prod/db
property: password When should you use ConfigMaps versus environment variables?
Choosing the right injection method affects both security and operational flexibility. Environment variables are convenient but leak easily through logs, crash dumps, and child processes. Volume mounts are safer and support dynamic updates without container restarts.
| Criteria | Environment Variables | Volume Mounts |
|---|---|---|
| Security exposure | High (visible in /proc, logs) | Low (file permissions, tmpfs) |
| Dynamic updates | Requires pod restart | Auto-updated (subPath excepted) |
| Binary/config files | Not supported | Full file support |
| Audit trail | Difficult to track | File access logging possible |
| Best for | Simple flags, non-sensitive toggles | Credentials, configs, certificates |
In practice, I reserve environment variables exclusively for non-sensitive bootstrap parameters like POD_NAME or feature flags that genuinely need process-level visibility. Everything else gets mounted as a volume with restrictive file permissions (0400 for secrets, 0644 for configs).
How do you handle ConfigMap updates without downtime?
Applications react differently to configuration changes. Some watch files for modifications; others require explicit signals. Understanding your application's behavior determines the update strategy.
- Avoid subPath for mutable configs: Volumes mounted with
subPathdo not receive updates when the underlying ConfigMap changes. Use the full directory mount and adjust your application's config path accordingly. - Implement config reloading: Use sidecars like
stakater/reloaderor application-native watchers to detect file changes. For Nginx, sendSIGHUP; for Java apps, use Spring Cloud Kubernetes refresh endpoints. - Version your ConfigMaps: Append content hashes to ConfigMap names (e.g.,
app-config-a1b2c3). This triggers rolling deployments automatically when used in pod specs, ensuring zero-downtime transitions. - Validate before applying: Use admission controllers or OPA/Gatekeeper policies to reject malformed configurations before they reach the cluster. This prevents runtime failures caused by syntax errors or missing required keys.
For teams managing infrastructure declaratively, combining versioned ConfigMaps with infrastructure as code with Terraform ensures configuration drift is caught during plan stages rather than at runtime.
What are the best practices for auditing Kubernetes Secrets and ConfigMaps?
Compliance frameworks require proof that sensitive data access is logged, reviewed, and restricted. Native Kubernetes audit logs capture API calls but lack granularity for secret value access.
- Enable audit policy for secrets: Configure the API server audit policy to log
get,list, andwatchoperations on Secret resources at theMetadatalevel minimum. Never logRequestResponsefor secrets unless absolutely necessary for debugging. - Restrict RBAC aggressively: Apply least-privilege principles. Service accounts should only access specific named secrets, not wildcard permissions. Use
ResourceNamesin Role bindings to limit scope. - Integrate with SIEM: Forward audit logs to centralized logging systems. Alert on anomalous patterns like bulk secret listing or access from unexpected service accounts.
- Rotate credentials proactively: Set maximum TTLs for all secrets. Automate rotation via External Secrets Operator or Vault dynamic secrets. Test rotation procedures quarterly.
Next steps for secure configuration management
Getting Kubernetes Secrets and ConfigMaps done right is not a one-time setup but an ongoing discipline. Start by auditing your current cluster for plaintext secrets in Git history and overly permissive RBAC roles. Migrate sensitive workloads to External Secrets Operator, enable etcd encryption, and establish rotation schedules aligned with your compliance requirements. If your team needs help implementing these patterns or preparing for a security audit, reach out to discuss your infrastructure. Secure configuration is the foundation every resilient platform depends on.