Skip to main content

Generate Kubernetes Secrets from a list of environment variables

Project description

k8secrets

When deploying an application to k8s cluster you often need to create a secret object that contains environment variables for that application.

This is a tedious process:

  1. Create a .yaml file
  2. base64 encode it
  3. Add key/value pairs to the .yaml file
  4. Add variables with correspondint references to the env section in a deployment object

This tool will automate that process for you.

Installation

Use pip to install this package. You can install it in a virtualenv or globally (this package has no dependencies an should not break your environment).

pip install --user k8secrets

After this, you can run k8secrets command in your terminal or run the package like this:

python3 -m k8secrests

Usage

k8secrets takes a secret object name and a list of variables as input:

k8secrets mysecret KEY1=value1,KEY2=value2

It can also read the variables from stdin (you can pipe input into it):

echo KEY1=value1,KEY2=value2 | k8secrets mysecret

Variable list is a list of key/value pairs in any of the following formats:

  • KEY=value
  • export KEY=value - found in .env files on Linux
  • KEY:value
  • KEY\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 a ,.

Output

k8secrets prints output to stdout. The output is valid yaml and contains two sections. First is a complete k8s secret object:

---
apiVersion: v1
kind: Secret
metadata:
  name: mysecret
type: Opaque
data:
  key1: dmFsdWUx
  key2: dmFsdWUy

The second is an env section with references to the secret object that you can use in your deployments or cronjobs:

---
env:
  - name: KEY1
    valueFrom:
	secretKeyRef:
	    name: mysecret
	    key: key1
  - name: KEY2
    valueFrom:
	secretKeyRef:
	    name: mysecret
	    key: key2

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

k8secrets-0.1.tar.gz (3.9 kB view details)

Uploaded Source

Built Distribution

k8secrets-0.1-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

Details for the file k8secrets-0.1.tar.gz.

File metadata

  • Download URL: k8secrets-0.1.tar.gz
  • Upload date:
  • Size: 3.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.0.0 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.7.0

File hashes

Hashes for k8secrets-0.1.tar.gz
Algorithm Hash digest
SHA256 89b1efc9e5a22f99f959ceb4be6cf15793a8c3f15edd6e3a0c85ee9e90dc4b75
MD5 66bf2cc968c4b0a3c9e40c1dbcb70c06
BLAKE2b-256 5ba82b5c4407602db0e52dc3e51b5591bc496633c4e2bcbd7c3e45d106893463

See more details on using hashes here.

File details

Details for the file k8secrets-0.1-py3-none-any.whl.

File metadata

  • Download URL: k8secrets-0.1-py3-none-any.whl
  • Upload date:
  • Size: 5.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.0.0 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.7.0

File hashes

Hashes for k8secrets-0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 24f9dbef1b68041b5f53295a5767947eaf63ffc0143db39441bfc8efadddb012
MD5 5d3831d960d080c06b59e6dcb1b8a39b
BLAKE2b-256 aafd31d2ff155a177c7a882fcb68caa97c93cd02d0a3bc9f5ab1e1fb9bb8e663

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page