Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/anyfin/dotenv-from-k8s

A commandline cli tool to fetch, merge and convert secrets and config maps in k8s to dot env property file. Useful for building frontend projects for k8s.
https://github.com/anyfin/dotenv-from-k8s

configmaps dotenv kubectl kubernetes openlibrary parser secrets

Last synced: 3 months ago
JSON representation

A commandline cli tool to fetch, merge and convert secrets and config maps in k8s to dot env property file. Useful for building frontend projects for k8s.

Awesome Lists containing this project

README

        

# dotenv-from-k8s

A commandline cli tool to fetch, merge and convert secrets and config maps in k8s to dot env property file.

In most frontend projects environment variables are built as part of docker build. This tool allows you to create a .env file from k8s secrets and config maps before doing a docker build. This way you can store your secrets in k8s secrets just like you would for a nodejs service.

This tool uses kubernetes apis via the official [kubernetes client for javascript](https://github.com/kubernetes-client/javascript) and
will use your currently configured kubectl to perform necessary api calls. So make sure you have configured your kubectl correctly before running this.

## Installation

```sh
npm install -g dotenv-from-k8s
```

## Usage

```s

dotenv-from-k8s 1.4.0 - A commandline cli tool to fetch, merge and convert secrets and config maps in k8s to dot env property file.

USAGE

dotenv-from-k8s

OPTIONS

-i, --input Input configuration file optional default: false
-o, --out Output env file name, defaults to stdout optional default: false
-s, --secret K8s from which you want to generate env file optional
-c, --configmap K8s from which you want to generate env file optional
-n, --namespace K8s from which you want to access the secrets and/or config maps optional
-x, --context K8s context from which you want to access the secrets and/or config maps optional

MORE INFO

Basic example:
---------------
dotenv-from-k8s -c api-config -o .env
or
dotenv-from-k8s -c api-config > .env

Advanced example:
----------------
dotenv-from-k8s -s api-secrets -s api-secrets2 -c api-config -c api-config2 -n default > .env

Config file example:
--------------------
cat > env-from.yaml < env-from.yaml < .env`

### Advanced example:

`dotenv-from-k8s -s api-secrets -s api-secrets2 -c api-config -c api-config2 -n default > .env`

### Config file example:

**env-from.yaml**

```
namespace: default
envFrom:
- secretRef:
name: app-secrets
- configMapRef:
name: app-config
overrides:
Hello: World
```

`dotenv-from-k8s -i env-from.yaml -o .env`

## Alternatives

If you do not want to use this tool for some reason you can try

PS: You will need [`jq`](https://github.com/stedolan/jq) version 1.6+ installed on your system.

```sh
kubectl get secrets/api-secrets -o json | \
jq -r '.data | map_values(@base64d) | to_entries[] | "\(.key)=\(.value)"' > .env

kubectl get configmaps/api-config -o json | \
jq -r '.data | to_entries[] | "\(.key)=\(.value)"' >> .env
```

## Ownership

Core Services Team

## Audit history

2024-08-08 by [Rumesh Hapuarachchi](https://github.com/rehrumesh)