Modern applications rely on configuration values and sensitive data such as API keys, database credentials, and certificates. Storing these directly in code or container images creates serious security risks.
OpenShift addresses this challenge with Secrets and ConfigMaps, enabling secure, dynamic, and scalable configuration management. These resources allow applications to consume data at runtime without exposing sensitive information.
๐ Secrets in OpenShift
Secrets are used to store sensitive information in a secure, encoded format.
๐น Key Features
- Stores credentials, tokens, and certificates
- Encoded using base64 (not encryption by default)
- Can be mounted as environment variables or files
๐ Example Secret
apiVersion: v1
kind: Secret
metadata:
name: db-credentials
type: Opaque
data:
username: cmNoX3VzZXI=
password: c2VjdXJlX3Bhc3M=
๐น Usage
Secrets can be injected into pods as:
- Environment variables
- Mounted volumes
๐ ConfigMaps in OpenShift
ConfigMaps store non-sensitive configuration data, separating configuration from application logic.
๐น Key Features
- Stores environment-specific settings
- Enables dynamic updates without rebuilding images
- Supports key-value pairs or full config files
๐ Example ConfigMap
apiVersion: v1
kind: ConfigMap
metadata:
name: app-config
data:
LOG_LEVEL: "debug"
FEATURE_FLAG: "true"
๐ง Using Secrets and ConfigMaps in Pods
You can inject both Secrets and ConfigMaps into containers using environment variables:
env:
- name: DB_USER
valueFrom:
secretKeyRef:
name: db-credentials
key: username
- name: LOG_LEVEL
valueFrom:
configMapKeyRef:
name: app-config
key: LOG_LEVEL
This approach keeps application code clean while securely managing configuration.
๐งช Troubleshooting Tips
- Use
oc get secretsandoc get configmapsto list resources -
Inspect environment variables:
oc exec <pod> -- env - Verify base64 encoding for Secret values
- Check RBAC permissions if access issues occur
โ Best Practices
โ Never hardcode credentials in application code
โ Use RBAC to restrict access to Secrets
โ Rotate secrets regularly
โ Separate sensitive (Secrets) and non-sensitive data (ConfigMaps)
โ Use external secret managers for production-grade security
๐ Conclusion
Secrets and ConfigMaps are fundamental to secure and scalable application deployment in Kubernetes environments like OpenShift. By separating configuration from code and securing sensitive data, organizations can improve security posture while maintaining operational flexibility.
FAQs (0)
Sign in to ask a question. You can read FAQs without logging in.