secrettoenv
is a Python command-line tool that converts Kubernetes secrets into .env
files for easier local development. It supports secret retrieval from both Kubernetes clusters and local files in JSON or YAML format.
- Converts Kubernetes secrets to
.env
files with key-value pairs. - Supports secret files in JSON or YAML format.
- Can fetch secrets directly from a Kubernetes namespace using your local
kubectl
configuration. - Customizable output file name and location for the generated
.env
file.
You can install the package directly from PyPI using pip
:
pip install secrettoenv
- Python version: 3.9 or higher
- Dependencies: The necessary dependencies (e.g.,
click
,kubernetes
) are automatically installed withpip
.
Once installed, you can use the secrettoenv
command to convert a Kubernetes secret or a local file to an .env
file.
secrettoenv --namespace <namespace> --secret-name <secret_name> --output-file <output_file>
secrettoenv --file <file_path> --output-file <output_file>
--namespace
: Specifies the Kubernetes namespace where the secret resides. Default isdefault
.--secret-name
: The name of the Kubernetes secret.--file
: The file containing Kubernetes secrets (supports JSON and YAML formats).--output-file
: The output.env
file name. Default isenv
.--kube-config
: The path to your Kubernetes configuration file. Default is~/.kube/config
.
secrettoenv --namespace my-namespace --secret-name my-secret --output-file my-secrets.env
secrettoenv --file my_secret.json --output-file my-secrets.env
This command will generate a file my-secrets.env
with secrets in key-value format from the specified Kubernetes secret.
If you want to contribute or modify the code, you can set up the project locally using Poetry.
-
Clone the repository.
-
Install dependencies with Poetry:
poetry install
-
Run the project using:
poetry run secrettoenv --namespace <namespace> --secret-name <secret_name> --output-file <output_file>
This project is licensed under the MIT License. See the LICENSE file for details.
- Add support for additional secret formats.
- Provide more advanced error handling and validation.