npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

dotenv-from-k8s

v1.5.2

Published

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

Downloads

158

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 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

npm install -g dotenv-from-k8s

Usage

  
  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 <secret_name>        K8s <secret_name> from which you want to generate env file                                   optional
    -c, --configmap <config_map>      K8s <config_map> from which you want to generate env file                                    optional
    -n, --namespace <name_space>      K8s <name_space> from which you want to access the secrets and/or config maps                optional
    -x, --context <context_name>      K8s context <context_name> 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 <<EOL

    namespace: default
    envFrom:
      - secretRef:
          name: app-secrets
      - configMapRef:
          name: app-config

    EOL

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


    Config file example with overrides:
    -----------------------------------
    cat > env-from.yaml <<EOL

    namespace: default
    envFrom:
      - secretRef:
          name: app-secrets
      - configMapRef:
          name: app-config
    overrides:
        HELLO: WORLD
        ANOTHER_KEY: ANOTHER_VALUE

    EOL

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


  GLOBAL OPTIONS

    -h, --help         Display help
    -V, --version      Display version
    --no-color         Disable colors
    --quiet            Quiet mode - only displays warn and error messages
    -v, --verbose      Verbose mode - will also output debug messages

Example

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:

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 version 1.6+ installed on your system.

  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