Hardcoding sensitive data like database passwords in your application is insecure. Always store secrets in a dedicated secret store rather than plain text files or code.
1. Application Overview
Here’s the original Flask application with hardcoded credentials:2. Storing Non-sensitive Configuration
Use a ConfigMap for non-sensitive data such as hostnames and users:DB_Password here—this belongs in a Secret.
3. Creating Kubernetes Secrets
There are two ways to create Secrets in Kubernetes:3.1 Imperative Method
Generate a generic Secret directly:3.2 Declarative Method
-
Base64-encode each value:
-
Create
app-secret.yaml: -
Apply the manifest:
The
Learn more in the Kubernetes Secrets documentation.
type: Opaque is the default Secret type for arbitrary user-defined data.Learn more in the Kubernetes Secrets documentation.
4. Viewing Secrets
- List all Secrets:
- Describe a Secret (values are masked):
- View encoded data in YAML:
- Decode a specific value: