Skip to content
This repository has been archived by the owner on Jun 6, 2023. It is now read-only.

Commit

Permalink
KeyDB multimaster PoC
Browse files Browse the repository at this point in the history
  • Loading branch information
Antiarchitect committed Feb 27, 2020
0 parents commit 46fe581
Show file tree
Hide file tree
Showing 7 changed files with 240 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.deploy
23 changes: 23 additions & 0 deletions keydb/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*.orig
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/
23 changes: 23 additions & 0 deletions keydb/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
apiVersion: v2
name: keydb
description: A Helm chart for KeyDB multimaster setup
type: application
version: 0.1.0
keywords:
- keydb
- redis
- keyvalue
- database
- multimaster
- HA
- high-availability
home: https://keydb.dev
maintainers:
- email: [email protected]
name: Antiarchitect
url: https://github.com/Antiarchitect
sources:
- https://github.com/Enapter/charts
- https://github.com/JohnSully/KeyDB
icon: https://keydb.dev/assets/ico/keydb_logo_bwtxtw.png
appVersion: 5.3.0
63 changes: 63 additions & 0 deletions keydb/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{{/* vim: set filetype=mustache: */}}
{{/*
Expand the name of the chart.
*/}}
{{- define "keydb.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{/*
Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
If release name contains chart name it will be used as a full name.
*/}}
{{- define "keydb.fullname" -}}
{{- if .Values.fullnameOverride -}}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}}
{{- else -}}
{{- $name := default .Chart.Name .Values.nameOverride -}}
{{- if contains $name .Release.Name -}}
{{- .Release.Name | trunc 63 | trimSuffix "-" -}}
{{- else -}}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}}
{{- end -}}
{{- end -}}
{{- end -}}

{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "keydb.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{/*
Common labels
*/}}
{{- define "keydb.labels" -}}
helm.sh/chart: {{ include "keydb.chart" . }}
{{ include "keydb.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end -}}

{{/*
Selector labels
*/}}
{{- define "keydb.selectorLabels" -}}
app.kubernetes.io/name: {{ include "keydb.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end -}}

{{/*
Create the name of the service account to use
*/}}
{{- define "keydb.serviceAccountName" -}}
{{- if .Values.serviceAccount.create -}}
{{ default (include "keydb.fullname" .) .Values.serviceAccount.name }}
{{- else -}}
{{ default "default" .Values.serviceAccount.name }}
{{- end -}}
{{- end -}}
96 changes: 96 additions & 0 deletions keydb/templates/sts.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
{{- $context := . }}
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: {{ template "keydb.fullname" . }}
labels:
{{ include "keydb.labels" . | indent 4 }}
spec:
replicas: {{ .Values.nodes }}
serviceName: {{ template "keydb.fullname" . }}
selector:
matchLabels:
{{ include "keydb.selectorLabels" . | indent 6 }}
template:
metadata:
labels:
{{ include "keydb.labels" . | indent 8 }}
spec:
affinity:
podAntiAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- weight: 100
podAffinityTerm:
labelSelector:
matchExpressions:
- key: app.kubernetes.io/name
operator: In
values:
- {{ template "keydb.name" . }}
- key: app.kubernetes.io/instance
operator: In
values:
- {{ .Release.Name }}
topologyKey: "kubernetes.io/hostname"
containers:
- name: keydb
image: {{ .Values.image }}
imagePullPolicy: {{ .Values.imagePullPolicy }}
volumeMounts:
- name: keydb-data
mountPath: /data
ports:
- name: keydb
containerPort: 6379
protocol: TCP
livenessProbe:
tcpSocket:
port: keydb
readinessProbe:
tcpSocket:
port: keydb
command:
- keydb-server
args:
- /etc/keydb/redis.conf
- --active-replica yes
- --bind 0.0.0.0
- --multi-master yes
- --port 6379
- --protected-mode no
- --server-threads {{ .Values.threads | int }}
{{ range $node := until (.Values.nodes | int) }}
- --replicaof {{ template "keydb.fullname" $context }}-{{ $node }}.{{ template "keydb.fullname" $context }}.{{ $context.Release.Namespace }}.svc.cluster.local 6379
{{ end }}
{{ if .Values.password }}
- --masterauth {{ .Values.password }}
- --requirepass {{ .Values.password }}
{{ end }}
{{ if not .Values.persistentVolume.enabled }}
volumes:
- name: storage-volume
emptyDir: {}
{{ end }}
{{ if .Values.persistentVolume.enabled }}
volumeClaimTemplates:
- metadata:
name: keydb-data
annotations:
{{ if .Values.persistentVolume.annotations }}
{{ toYaml .Values.persistentVolume.annotations | indent 8 }}
{{ end }}
labels:
spec:
accessModes:
{{ toYaml .Values.persistentVolume.accessModes | indent 8 }}
resources:
requests:
storage: {{ .Values.persistentVolume.size }}
{{ if .Values.persistentVolume.storageClass }}
{{ if (eq "-" .Values.persistentVolume.storageClass) }}
storageClassName: ""
{{ else }}
storageClassName: {{ .Values.persistentVolume.storageClass }}
{{ end }}
{{ end }}
{{ end }}
15 changes: 15 additions & 0 deletions keydb/templates/svc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: v1
kind: Service
metadata:
name: {{ template "keydb.fullname" . }}
labels:
{{ include "keydb.labels" . | indent 4 }}
spec:
type: ClusterIP
ports:
- name: server
port: {{ .Values.port | int }}
protocol: TCP
targetPort: keydb
selector:
{{ include "keydb.selectorLabels" . | indent 4 }}
19 changes: 19 additions & 0 deletions keydb/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
nameOverride: ""
fullnameOverride: ""

image: eqalpha/keydb:x86_64_v5.3.0
imagePullPolicy: IfNotPresent

nodes: 3

password: ""

port: 6379

persistentVolume:
enabled: false
accessModes:
- ReadWriteOnce
size: 1Gi

threads: 2

0 comments on commit 46fe581

Please sign in to comment.