When deploying an application to k8s cluster you often need to create a Secret
or ConfigMap object that contains environment variables for that application.
This is a tedious process:
- Create a
.yamlfile base64encode it- Add key/value pairs to the
.yamlfile
This tool will automate that process for you.
Use pipx to install this
package. The package will be installed in isolation and a k8secret command
will be added to your path.
pipx install k8secrets
k8secrets takes an object name and a list of variables as input and creates a
Secret Kubernetes object:
k8secrets mysecret -l KEY1=value1,KEY2=value2
or a ConfigMap:
k8secrets --config myconfig -l KEY1=value1,KEY2=value2
Variable list is a list of key/value pairs in any of the following formats:
KEY=valueexport KEY=value- found in.envfiles on LinuxKEY:valueKEY\tvalue(separated by a tab character)
If value is wrapped in '' or "", the quotes are ignored. Pairs can be
separated either by a newline character (Unix or Windows), , or ;.
k8secrets prints output to stdout. The output is valid yaml and contains
two sections. First is a complete k8s Secret or ConfigMap object:
---
apiVersion: v1
kind: Secret
metadata:
name: mysecret
type: Opaque
data:
KEY1: dmFsdWUx
KEY2: dmFsdWUyThe second is an envFrom section with a reference to the Secret or ConfigMap object that you
can use in your deployments or cronjobs:
---
envFrom:
- secretRef:
name: mysecretThe application is written in Python and uses Poetry to configure the package and manage it's dependencies.
Make sure you have Poetry CLI installed. Then you can run
$ poetry install
which will install the project dependencies (including dev dependencies) into a
Python virtual environment managed by Poetry (alternatively, you can activate
your own virtual environment beforehand and Poetry will use that).
$ poetry run pytest
or activate the poetry shell first
$ poetry shell
$ pytest