If the application requires config.yaml, application.yml or settings.json, keep its file format. Commit a sample and generate or mount the real file in the deployment environment.
When to use this guide
Use this approach when the application reads a fixed path or nested settings are difficult to represent as environment variables. The deployment needs a Kubernetes Secret volume, CSI driver, Vault Agent or another protected file delivery mechanism.
Recommended pattern
Keep only the configuration structure in config.yaml.example. Supply the real config.yaml at the runtime path and stop startup if the file or a required value is missing.
Recommended structure
config.yaml.example # Sample configuration only; can be committed to Git
config.yaml # Real production configuration; do not commit to Git
.gitignore # Includes config.yaml
/etc/app/config.yaml # Example path for a real file mounted or generated at runtime
Examples
Before
database:
host: prod-db.internal
user: app_user
password: super-secret-password
jwt:
secret: hardcoded-jwt-secret
Treat the secrets as exposed if a file like this is included in the repository.
After
Repository file: config.yaml.example
database:
host: prod-db.internal
user: app_user
password: "<runtime-provided>"
jwt:
secret: "<runtime-provided>"
Example runtime file path
/etc/app/config.yaml
A Kubernetes Secret volume, Vault Agent/CSI or the deployment system’s secure file delivery generates or mounts this file at runtime.
File permissions
Set the owner and group so that only the application account can read the file. The commands below apply to a writable file. For a read-only Kubernetes Secret volume, configure permissions and ownership in the volume settings.
chmod 600 /etc/app/config.yaml
chown appuser:appgroup /etc/app/config.yaml
Kubernetes example
- Store the file contents in a
Secretor an external secret integration resource. - Mount it into the Pod at
/etc/app/config.yamlusing a Secret volume. - Do not replace the Secret with a
ConfigMap.
Developer responsibilities
Read the runtime path and stop startup if the file or a required value is missing. Keep secret values out of configuration dumps, panic messages and debug logs. Document whether rotation requires a reload or restart.
Infrastructure and platform responsibilities
- Supply the real file through a Kubernetes Secret volume, CSI driver, Vault Agent or protected file delivery. Reserve manual placement for exceptions.
- Keep the production file out of Git, ConfigMaps and Docker images, including
COPYinstructions in theDockerfile. Define how the file and application receive updates after rotation.
Verification
- Check
.gitignoreand the repository. Production files should be excluded, and samples should contain no live values. - Verify ownership and read access on the deployed file. Test that startup stops when the file or a required value is missing.
- Check logs, panic messages, configuration dumps, Actuator and error responses for exposed values. After rotation, verify that a reload or restart applies the replacement.
If a secret was exposed
- Revoke or disable the exposed credential immediately and issue a replacement.
- Remove live values from the tracked file. Stop tracking
config.yamland add it to.gitignore. - Deliver a file containing the replacement to the runtime path. Reload or restart the application so it reads the new value.
Example instructions for the owner
Keep only the structure in
config.yaml.example. At deployment, mount the real file so only the application account can read it. Stop startup if a required value is missing.