redis-ha

by alexvanderberkel

Helm chartv4.37.11App 8.10.3Verified publisher

This Helm chart provides a highly available Redis implementation with a master/slave configuration and uses Sentinel sidecars for failover management

About this chart

Redis

Redis is an advanced key-value cache and store. It is often referred to as a data structure server since keys can contain strings, hashes, lists, sets, sorted sets, bitmaps and hyperloglogs.

TL;DR

helm repo add alexvanderberkel https://charts.esseling.photos
helm install alexvanderberkel/redis-ha

By default this chart install 3 pods total:

  • one pod containing a redis master and sentinel container (optional prometheus metrics exporter sidecar available)
  • two pods each containing a redis slave and sentinel containers (optional prometheus metrics exporter sidecars available)

Introduction

This chart bootstraps a Redis highly available master/slave statefulset in a Kubernetes cluster using the Helm package manager.

Prerequisites

  • Kubernetes 1.8+ with Beta APIs enabled
  • PV provisioner support in the underlying infrastructure
  • Helm v3+

Upgrading the Chart

Please note that there have been a number of changes simplifying the redis management strategy (for better failover and elections) in the 3.x version of this chart. These changes allow the use of official redis images that do not require special RBAC or ServiceAccount roles. As a result when upgrading from version >=2.0.1 to >=3.0.0 of this chart, Role, RoleBinding, and ServiceAccount resources should be deleted manually.

Upgrading the chart from 3.x to 4.x

Starting from version 4.x HAProxy sidecar prometheus-exporter removed and replaced by the embedded HAProxy metrics endpoint, as a result when upgrading from version 3.x to 4.x section haproxy.exporter should be removed and the haproxy.metrics need to be configured for fit your needs.

Installing the Chart

To install the chart

helm repo add alexvanderberkel https://charts.esseling.photos
helm install alexvanderberkel/redis

The command deploys Redis on the Kubernetes cluster in the default configuration. By default this chart install one master pod containing redis master container and sentinel container along with 2 redis slave pods each containing their own sentinel sidecars. The configuration section lists the parameters that can be configured during installation.

Tip: List all releases using helm list

Uninstalling the Chart

To uninstall/delete the deployment:

helm delete <chart-name>

The command removes all the Kubernetes components associated with the chart and deletes the release.

Configuration

The following table lists the configurable parameters of the Redis chart and their default values.

General parameters

ParameterDescriptionTypeDefault
additionalAffinitiesAdditional affinities to add to the Redis server pods. # Ref: https://kubernetes.io/docs/concepts/configuration/assign-pod-node/#affinity-and-anti-affinityobject{}
affinityOverride all other affinity settings for the Redis server pods with a string.string""
authConfigures redis with AUTH (requirepass & masterauth conf params)boolfalse
authKeyDefines the key holding the redis password in existing secret.string"auth"
authSecretAnnotationsAnnotations for auth secretobject{}
configmap.labelsCustom labels for the redis configmapobject{}
configmapTest.imageImage for redis-ha-configmap-test hookobject{"repository":"koalaman/shellcheck","tag":"v0.10.0"}
configmapTest.image.repositoryRepository of the configmap shellcheck test image.string"koalaman/shellcheck"
configmapTest.image.tagTag of the configmap shellcheck test image.string"v0.10.0"
configmapTest.resourcesResources for the ConfigMap test podobject{}
containerSecurityContextSecurity context to be added to the Redis containers.object{"allowPrivilegeEscalation":false,"capabilities":{"drop":["ALL"]},"runAsNonRoot":true,"runAsUser":1000,"seccompProfile":{"type":"RuntimeDefault"}}
emptyDirConfiguration of emptyDir, used only if persistentVolume is disabled and no hostPath specifiedobject{}
existingSecretAn existing secret containing a key defined by authKey that configures requirepass and masterauth in the conf parameters (Requires auth: enabled, cannot be used in conjunction with .Values.redisPassword)stringnil
extraContainersExtra containers to include in StatefulSetlist[]
extraInitContainersExtra init containers to include in StatefulSetlist[]
extraLabelsLabels added here are applied to all created resourcesobject{}
extraVolumesExtra volumes to include in StatefulSetlist[]
fullnameOverrideFull name of the Redis HA Resourcesstring""
global.compatibilityOpenshift compatibility optionsobject{"openshift":{"adaptSecurityContext":"auto"}}
global.priorityClassNameDefault priority class for all componentsstring""
hardAntiAffinityWhether the Redis server pods should be forced to run on separate nodes. # This is accomplished by setting their AntiAffinity with requiredDuringSchedulingIgnoredDuringExecution as opposed to preferred. # Ref: https://kubernetes.io/docs/concepts/configuration/assign-pod-node/#inter-pod-affinity-and-anti-affinity-beta-featurebooltrue
hostPath.chownif chown is true, an init-container with root permissions is launched to change the owner of the hostPath folder to the user defined in the security contextbooltrue
hostPath.pathUse this path on the host for data storage. path is evaluated as template so placeholders are replacedstring""
image.pullPolicyRedis image pull policystring"IfNotPresent"
image.repositoryRedis image repositorystring"public.ecr.aws/docker/library/redis"
image.tagRedis image tagstring"8.2.1-alpine"
imagePullSecretsReference to one or more secrets to be used when pulling redis imageslist[]
init.resourcesExtra init resourcesobject{}
labelsCustom labels for the redis podobject{}
nameOverrideName override for Redis HA resourcesstring""
networkPolicy.annotationsAnnotations for NetworkPolicyobject{}
networkPolicy.egressRulesuser can define egress rules too, uses the same structure as ingressRuleslist[{"ports":[{"port":53,"protocol":"UDP"},{"port":53,"protocol":"TCP"}],"selectors":[{"namespaceSelector":{}},{"ipBlock":{"cidr":"169.254.0.0/16"}}]}]
networkPolicy.egressRules[0].selectors[0]Allow all destinations for DNS trafficobject{"namespaceSelector":{}}
networkPolicy.enabledwhether NetworkPolicy for Redis StatefulSets should be created. when enabled, inter-Redis connectivity is createdboolfalse
networkPolicy.ingressRulesUser defined ingress rules that Redis should permit into. Uses the format defined in https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/#label-selectorslist[]
networkPolicy.labelsLabels for NetworkPolicyobject{}
nodeSelectorNode labels for pod assignmentobject{}
persistentVolume.accessModesPersistent volume access modeslist["ReadWriteOnce"]
persistentVolume.annotationsAnnotations for the volumeobject{}
persistentVolume.enabledEnable persistent volumebooltrue
persistentVolume.labelsLabels for the volumeobject{}
persistentVolume.sizePersistent volume sizestring"10Gi"
persistentVolume.storageClassredis-ha data Persistent Volume Storage Classstringnil
podDisruptionBudgetPod Disruption Budget rulesobject{}
podManagementPolicyThe statefulset pod management policystring"OrderedReady"
priorityClassNameKubernetes priorityClass name for the redis-ha-server podstring""
rbac.createCreate and use RBAC resourcesbooltrue
redis.annotationsAnnotations for the redis statefulsetobject{}
redis.authClientsIt is possible to disable client side certificates authentication when "authClients" is set to "no"string""
redis.configAny valid redis config options in this section will be applied to each server, For multi-value configs use list instead of string (for example loadmodule) (see below)objectsee values.yaml
redis.config.maxmemoryMax memory to use for each redis instance. Default is unlimited.string"0"
redis.config.maxmemory-policyMax memory policy to use for each redis instance. Default is volatile-lru.string"volatile-lru"
redis.config.min-replicas-max-lagValue in secondsint5
redis.config.repl-diskless-syncWhen enabled, directly sends the RDB over the wire to slaves, without using the disk as intermediate storage. Default is false.string"yes"
redis.config.savePlease note that local (on-disk) RDBs will still be created when re-syncing with a new slave. The only way to prevent this is to enable diskless replication.string"900 1"
redis.customArgsAllows overriding the redis container argumentslist[]
redis.customCommandAllows overriding the redis container commandlist[]
redis.customConfigAllows for custom redis.conf files to be applied. If this is used then redis.config is ignoredstringnil
redis.disableCommandsArray with commands to disablelist["FLUSHDB","FLUSHALL"]
redis.envFromLoad environment variables from ConfigMap/Secretlist[]
redis.extraVolumeMountsadditional volumeMounts for Redis containerlist[]
redis.lifecycleContainer Lifecycle Hooks for redis container Ref: https://kubernetes.io/docs/concepts/containers/container-lifecycle-hooks/objectsee values.yaml
redis.livenessProbeLiveness probe parameters for redis containerobject{"enabled":true,"failureThreshold":5,"initialDelaySeconds":30,"periodSeconds":15,"successThreshold":1,"timeoutSeconds":15}
redis.livenessProbe.enabledEnable the Liveness Probebooltrue
redis.livenessProbe.failureThresholdFailure threshold for liveness probeint5
redis.livenessProbe.initialDelaySecondsInitial delay in seconds for liveness probeint30
redis.livenessProbe.periodSecondsPeriod in seconds after which liveness probe will be repeatedint15
redis.livenessProbe.successThresholdSuccess threshold for liveness probeint1
redis.livenessProbe.timeoutSecondsTimeout seconds for liveness probeint15
redis.masterGroupNameRedis convention for naming the cluster group: must match ^[\\w-\\.]+$ and can be templatedstring"mymaster"
redis.podAnnotationsAnnotations to be added to the redis statefulset podsobject{}
redis.portPort to access the redis serviceint6379
redis.readinessProbeReadiness probe parameters for redis containerobject{"enabled":true,"failureThreshold":5,"initialDelaySeconds":30,"periodSeconds":15,"successThreshold":1,"timeoutSeconds":15}
redis.readinessProbe.enabledEnable the Readiness Probebooltrue
redis.readinessProbe.failureThresholdFailure threshold for readiness probeint5
redis.readinessProbe.initialDelaySecondsInitial delay in seconds for readiness probeint30
redis.readinessProbe.periodSecondsPeriod in seconds after which readiness probe will be repeatedint15
redis.readinessProbe.successThresholdSuccess threshold for readiness probeint1
redis.readinessProbe.timeoutSecondsTimeout seconds for readiness probeint15
redis.resourcesCPU/Memory for master/slave nodes resource requests/limitsobject{}
redis.startupProbeStartup probe parameters for redis containerobject{"enabled":true,"failureThreshold":5,"initialDelaySeconds":30,"periodSeconds":15,"successThreshold":1,"timeoutSeconds":15}
redis.startupProbe.enabledEnable Startup Probebooltrue
redis.startupProbe.failureThresholdFailure threshold for startup probeint5
redis.startupProbe.initialDelaySecondsInitial delay in seconds for startup probeint30
redis.startupProbe.periodSecondsPeriod in seconds after which startup probe will be repeatedint15
redis.startupProbe.successThresholdSuccess threshold for startup probeint1
redis.startupProbe.timeoutSecondsTimeout seconds for startup probeint15
redis.terminationGracePeriodSecondsIncrease terminationGracePeriodSeconds to allow writing large RDB snapshots. (k8s default is 30s) ref: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/#pod-termination-forcedint60
redis.tlsPortTLS Port to access the redis serviceintnil
redis.tlsReplicationConfigures redis with tls-replication parameter, if true sets "tls-replication yes" in redis.confboolnil
redis.updateStrategyUpdate strategy for Redis StatefulSet # ref: https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/#update-strategiesobject{"type":"RollingUpdate"}
redisPasswordA password that configures a requirepass and masterauth in the conf parameters (Requires auth: enabled)stringnil
replicasNumber of redis master/slaveint3
restore.existingSecretSet existingSecret to true to use secret specified in existingSecret aboveboolfalse
restore.redis.source

Deploy redis-ha with OpenTenant

Each tenant gets its own release of this chart, with its own namespace, secrets and domain. The builder below already has redis-ha on a Hetzner server. Change the host, add apps from the marketplace, then copy the generated files. Providers and prices are samples, and nothing here is sent anywhere.

  1. Pick a serverConnect Hetzner, OVHcloud or AWS. The builder starts on Hetzner, the cheapest sample rate.
  2. Place the chartredis-ha is pinned at v4.37.11 in opentenant.yaml. Drag more apps from the marketplace onto a rack.
  3. ApplySave opentenant.yaml and main.tf from the console, then run the commands below.
# opentenant.yaml, main.tf and dns.tf come from the builder below
opentenant validate opentenant.yaml
terraform init && terraform apply