1. Generate the Secret YAML
Use the following command to create a generic Secret nameddatabase in the default namespace. The DB_PASSWORD key is set to password123.
| Option | Description | Example |
|---|---|---|
create secret generic <name> | Creates a generic Secret resource | kubectl create secret generic database |
-n <namespace> | Specifies the target namespace | -n default |
--from-literal=KEY=VALUE | Adds literal key-value pairs to the Secret | --from-literal=DB_PASSWORD=password123 |
--dry-run=client -o yaml | Outputs the manifest without applying it | --dry-run=client -o yaml |
Kubernetes Secrets store data as base64-encoded strings, not encrypted values. Always seal or encrypt sensitive data before committing to version control.
2. Inspecting the Generated YAML
Yoursecret.yaml will look like this:
3. Verifying the Base64 Encoding
To confirm the encoding, decode theDB_PASSWORD field:
4. Next Steps: Sealing the Secret
Now that you havesecret.yaml, pass it through kubeseal to produce a secure SealedSecret: