项目作者: ealebed

项目描述 :
k8s controller to insert data in redis-server pods on startup
高级语言: Go
项目地址: git://github.com/ealebed/redins.git
创建时间: 2020-11-26T10:30:02Z
项目社区:https://github.com/ealebed/redins

开源协议:

下载


REDis INSert data controller

This repository implements a simple controller for watching new created redis pod and inserting data to it.

Details

The sample controller uses client-go library extensively.

Running

Prerequisite: Since the controller uses apps/v1 deployments, the Kubernetes cluster version should be greater than 1.9.

  1. # assumes you have a working kubeconfig, not required if operating in-cluster
  2. go build ./
  3. # for run on development
  4. export IN_CLUSTER=false
  5. # run with default kubeconfig path
  6. ./redins
  7. # or provide path to kubeconfig manually
  8. ./redins -kubeconfig=$HOME/.kube/config
  1. # run controller in cluster
  2. kubectl apply -f deployment/deployment.yaml

What happens under the hood?

Controller connects to a Kubernetes cluster, sets up an informer for Pods in default namespace and with label selector "app=ads-redis-statistic", and then starts the Informer run loop. When pods with matched criteria (and the initial warmup of pods when the Store syncs) are added to the cluster, controller initialize redis client, connect to provided redis-server, set key/value in database, get and print key/value from DB, and finally close connection to redis-server.