All Projects → rusenask → k8s-kv

rusenask / k8s-kv

Licence: Apache-2.0 License
Kubernetes config maps backed KV store for stateful apps

Programming Languages

go
31211 projects - #10 most used programming language

Projects that are alternatives of or similar to k8s-kv

Stencil Store
Store is a lightweight shared state library by the StencilJS core team. Implements a simple key/value map that efficiently re-renders components when necessary.
Stars: ✭ 107 (+268.97%)
Mutual labels:  key-value, state
SimpleStateMachineLibrary
📚 A simple library for realization state machines in C# code
Stars: ✭ 30 (+3.45%)
Mutual labels:  state
xstate-viz
Visualizer for XState machines
Stars: ✭ 274 (+844.83%)
Mutual labels:  state
elara
Elara DB is an easy to use, lightweight key-value database that can also be used as a fast in-memory cache. Manipulate data structures in-memory, encrypt database files and export data. 🎯
Stars: ✭ 93 (+220.69%)
Mutual labels:  key-value
closeable-map
Application state management made simple: a Clojure map that implements java.io.Closeable.
Stars: ✭ 42 (+44.83%)
Mutual labels:  state
stack-public
A key-value based writer.
Stars: ✭ 19 (-34.48%)
Mutual labels:  key-value
stoxy
Stoxy is a state management API for all modern Web Technologies
Stars: ✭ 73 (+151.72%)
Mutual labels:  state
bigtable
TypeScript Bigtable Client with 🔋🔋 included.
Stars: ✭ 13 (-55.17%)
Mutual labels:  key-value
Nanny-State
simple state management
Stars: ✭ 68 (+134.48%)
Mutual labels:  state
chapar
A framework for verification of causal consistency for distributed key-value stores and their clients in Coq [maintainer=@palmskog]
Stars: ✭ 29 (+0%)
Mutual labels:  key-value
Artifact
An in-memory distributed database
Stars: ✭ 63 (+117.24%)
Mutual labels:  key-value
graph-crdt
Commutative graphs made for real-time, offline-tolerant replication
Stars: ✭ 47 (+62.07%)
Mutual labels:  state
tempdb
Key-value store for temporary items 📝
Stars: ✭ 16 (-44.83%)
Mutual labels:  key-value
keva
Low-latency in-memory key-value store, Redis drop-in alternative
Stars: ✭ 76 (+162.07%)
Mutual labels:  key-value
state
Store a certain application state in the session or cache.
Stars: ✭ 17 (-41.38%)
Mutual labels:  state
statemachine-go
🚦 Declarative Finite-State Machines in Go
Stars: ✭ 47 (+62.07%)
Mutual labels:  state
react-wisteria
Managing the State with the Golden Path
Stars: ✭ 18 (-37.93%)
Mutual labels:  state
atomic-state
A decentralized state management library for React
Stars: ✭ 54 (+86.21%)
Mutual labels:  state
k-ramel
State manager for your components apps, the safe and easy way
Stars: ✭ 20 (-31.03%)
Mutual labels:  state
b52
b52 is a fast experimental Key/value database. With support for the memcache protocol.
Stars: ✭ 20 (-31.03%)
Mutual labels:  key-value

Kubernetes backed KV

GoDoc

Use Kubernetes config maps as key/value store! When to use k8s-kv:

  • You have a simple application that has a need to store some configuration and you can't be bothered to set up EBS like volumes or use some fancy external KV store.
  • You have a stateless application that suddenly got to store state and you are not into converting it into full stateless app that will use a proper database.

When not to use k8s-kv:

  • You have a read/write heavy multi-node application (k8s-kv doesn't have cross-app locking).
  • You want to store bigger values than 1MB. Even though k8s-kv uses compression for the data stored in bucket - it's wise to not try the limits. It's there because of the limit in Etcd. In this case use something else.

Basics

Package API:

// Pyt key/value pair into the store
Put(key string, value []byte) error
// Get value of the specified key
Get(key string) (value []byte, err error)
// Delete key/value pair from the store
Delete(key string) error
// List all key/value pairs under specified prefix
List(prefix string) (data map[string][]byte, err error)
// Delete config map (results in deleted data)
Teardown() error

Caveats

  • Don't be silly, you can't put a lot of stuff here.

Example

Usage example:

  1. Get minikube or your favourite k8s environment running.

  2. In your app you will probably want to use this: https://github.com/kubernetes/client-go/tree/master/examples/in-cluster-client-configuration

  3. Get ConfigMaps interface and supply it to this lib:

package main

import (
	"fmt"

	"github.com/rusenask/k8s-kv/kv"

	"k8s.io/client-go/kubernetes"
	core_v1 "k8s.io/client-go/kubernetes/typed/core/v1"
	"k8s.io/client-go/tools/clientcmd"
)

// get ConfigMapInterface to access config maps in "default" namespace
func getImplementer() (implementer core_v1.ConfigMapInterface) {
	cfg, err := clientcmd.BuildConfigFromFlags("", ".kubeconfig") // in your app you could replace it with in-cluster-config
	if err != nil {
		panic(err)
	}

	client, err := kubernetes.NewForConfig(cfg)
	if err != nil {
		panic(err)
	}

	return client.ConfigMaps("default")
}

func main() {
	impl := getImplementer()

	// getting acces to k8s-kv. "my-app" will become a label
	// for this config map, this way it's easier to manage configs 
	// "bucket1" will be config map's name and represent one entry in config maps list	
	kvdb, err := kv.New(impl, "my-app", "bucket1")
	if err != nil {
		panic(err)
	}

	// insert a key "foo" with value "hello kubernetes world"
	kvdb.Put("foo", []byte("hello kubernetes world"))

	// get value of key "foo"
	stored, _ := kvdb.Get("foo")

	fmt.Println(string(stored))
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].