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

keyvalue-kubernetes-configmap

v1.2.0

Published

key-value store backed by kubernetes configmaps

Downloads

14

Readme

Description

Key-value store backed by kubernetes configmaps. It exposes a create, read, update & delete API that transparently stores values in configmaps (IE: etcd).

Designed for in-cluster use; but it also supports authenticating from outside of a Kubernetes cluster.

Synopsis

const KeyValueK8s = require('keyvalue-kubernetes-configmap');

const keyvalueK8s = new KeyValueK8s();
const keyName = 'my_configmap_name';

await keyvalueK8s.createKey(keyName, {'answer': 43}); // creates the configmap

const value = await keyvalueK8s.readKey(keyName);

const updatedValue = {'answer': 42};
await keyvalueK8s.updateKey(keyName, updatedValue);

await keyvalueK8s.deleteKey(keyName); // deletes the configmap

Methods

Constructor

Returns a new instance of keyvalue-kubernetes-configmap.
Supports injecting an already instantiated kubernetes client.

const keyvalueK8s = new KeyValueK8s();

# Injecting a kubernetes client
const KubernetesClient = require('@kubernetes/client-node');
const kubernetesClient = [...];
const keyvalueK8s = new KeyValueK8s(kubernetesClient);
createKey

Creates a new configmap, stores the specified value in its content and returns it.

const keyvalueK8s = new KeyValueK8s();
const value = await keyvalueK8s.createKey(configmapName, value);
readKey

Reads and returns the content of the specified configmap.

const keyvalueK8s = new KeyValueK8s();
const value = await keyvalueK8s.readKey(configmapName);
updateKey

Updates the content of the specified configmap with the specified value.

const keyvalueK8s = new KeyValueK8s();
const value = {'answer': 42};
await keyvalueK8s.updateKey(configmapName, value);
deleteKey

Deletes the specified configmap.

const keyvalueK8s = new KeyValueK8s();
await keyvalueK8s.deleteKey(configmapName);

Authentication

In order to authenticate against the Kubernetes API of your cluster, 3 authentication methods are supported:
1. Via KUBECONFIG environment var.
2. In-cluster.
3. By injecting an already instantiated kubernetes client through the constructor.

1. Following convention, if the environment variable KUBECONFIG is set and it contains the path to a kubeconfig file, keyvalue-kubernetes-configmap will read its content and attempt to authenticate against the cluster with it.

2. When running inside of a cluster, keyvalue-kubernetes-configmap will authenticate as the service account that your application runs as in the cluster.
Take into account that if you did not specify a service account on your container spec, your application is very likely running as the default service account; and [by default] the default service account cannot manage configmaps. The recommended approach here is provisioning a service account and set it as the service account in your application containers spec. No worries, a full setup of service account + role + role binding + container spec is provided in the examples section :)

3. Lastly, an already instantiated kubernetes client can be injected through the constructor:

const KubernetesClient = require('@kubernetes/client-node');
const kubernetesClient = [...];

const KeyValueK8s = require('keyvalue-kubernetes-configmap');
const keyvalueK8s = new KeyValueK8s(kubernetesClient);

Setup

The recommended setup is:

  • Create a service account for your application.
  • Create a role that allows managing configmaps.
  • Attach the role to the service account via a role binding.
  • Have your application run as the created service account in your cluster.

A fully working example of these resources can be found in the infra folder of the examples.

Examples

A fully working example can be found in the examples folder.

# clone the repo
git clone [email protected]:ureesoriano/keyvalue-kubernetes-configmap.git
cd keyvalue-kubernetes-config

# deploy the serviceaccount + role + role binding in your cluster
cd examples/
kubectl apply -f infra/rbac.yaml

# deploy the example configmap in your cluster
kubectl apply -f infra/configmap.yaml

# to test the functionality outside of a kubernetes cluster (IE: locally), set up
# the KUBECONFIG environment variable to the path of a kubeconfig file that
# authenticates in the cluster *as the service account*
export KUBECONFIG=~/.kube/service_account_config

# run the example
node example.js

# to test the provided funcionality inside of a kubernetes cluster, assign the
# service account to a deployment/cronjob/job... as in the provided job example

Current Limitations

At this point, be aware of the following relevant limitations:

  • ~~createKey and deleteKey methods are not yet implemented.~~
  • Only namespace default is supported.
  • It is not possible yet to specify a kubernetes API version.

These are, in order, the next features on the roadmap (PRs are welcome :D).

Author

Oriol Soriano [email protected]

License

This code is distributed under the MIT license. The full text of the license can be found in the LICENSE file included with this module.

Keywords

keyvalue kubernetes configmap kv database