redis-ha
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 dandydev https://dandydeveloper.github.io/charts
helm install dandydev/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 dandydev https://dandydeveloper.github.io/charts
helm install dandydev/redis-ha
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
| Parameter | Description | Type | Default |
|---|---|---|---|
additionalAffinities | Additional affinities to add to the Redis server pods. # Ref: https://kubernetes.io/docs/concepts/configuration/assign-pod-node/#affinity-and-anti-affinity | object | {} |
affinity | Override all other affinity settings for the Redis server pods with a string. | string | "" |
auth | Configures redis with AUTH (requirepass & masterauth conf params) | bool | false |
authKey | Defines the key holding the redis password in existing secret. | string | "auth" |
authSecretAnnotations | Annotations for auth secret | object | {} |
configmap.labels | Custom labels for the redis configmap | object | {} |
configmapTest.image | Image for redis-ha-configmap-test hook | object | {"repository":"koalaman/shellcheck","tag":"v0.11.0"} |
configmapTest.image.repository | Repository of the configmap shellcheck test image. | string | "koalaman/shellcheck" |
configmapTest.image.tag | Tag of the configmap shellcheck test image. | string | "v0.11.0" |
configmapTest.resources | Resources for the ConfigMap test pod | object | {} |
containerSecurityContext | Security context to be added to the Redis containers. | object | {"allowPrivilegeEscalation":false,"capabilities":{"drop":["ALL"]},"runAsNonRoot":true,"runAsUser":1000,"seccompProfile":{"type":"RuntimeDefault"}} |
emptyDir | Configuration of emptyDir, used only if persistentVolume is disabled and no hostPath specified | object | {} |
existingSecret | An 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) | string | nil |
extraContainers | Extra containers to include in StatefulSet | list | [] |
extraInitContainers | Extra init containers to include in StatefulSet | list | [] |
extraLabels | Labels added here are applied to all created resources | object | {} |
extraVolumes | Extra volumes to include in StatefulSet | list | [] |
fullnameOverride | Full name of the Redis HA Resources | string | "" |
global.compatibility | Openshift compatibility options | object | {"openshift":{"adaptSecurityContext":"auto"}} |
global.priorityClassName | Default priority class for all components | string | "" |
hardAntiAffinity | Whether 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-feature | bool | true |
hostPath.chown | if 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 context | bool | true |
hostPath.path | Use this path on the host for data storage. path is evaluated as template so placeholders are replaced | string | "" |
image.pullPolicy | Redis image pull policy | string | "IfNotPresent" |
image.repository | Redis image repository | string | "public.ecr.aws/docker/library/redis" |
image.tag | Redis image tag | string | "8.8.0-alpine" |
imagePullSecrets | Reference to one or more secrets to be used when pulling redis images | list | [] |
init.resources | Extra init resources | object | {} |
labels | Custom labels for the redis pod | object | {} |
nameOverride | Name override for Redis HA resources | string | "" |
networkPolicy.annotations | Annotations for NetworkPolicy | object | {} |
networkPolicy.egressRules | user can define egress rules too, uses the same structure as ingressRules | list | [{"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 traffic | object | {"namespaceSelector":{}} |
networkPolicy.enabled | whether NetworkPolicy for Redis StatefulSets should be created. when enabled, inter-Redis connectivity is created | bool | false |
networkPolicy.ingressRules | User defined ingress rules that Redis should permit into. Uses the format defined in https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/#label-selectors | list | [] |
networkPolicy.labels | Labels for NetworkPolicy | object | {} |
nodeSelector | Node labels for pod assignment | object | {} |
persistentVolume.accessModes | Persistent volume access modes | list | ["ReadWriteOnce"] |
persistentVolume.annotations | Annotations for the volume | object | {} |
persistentVolume.enabled | Enable persistent volume | bool | true |
persistentVolume.labels | Labels for the volume | object | {} |
persistentVolume.size | Persistent volume size | string | "10Gi" |
persistentVolume.storageClass | redis-ha data Persistent Volume Storage Class | string | nil |
podDisruptionBudget | Pod Disruption Budget rules | object | {} |
podManagementPolicy | The statefulset pod management policy | string | "OrderedReady" |
priorityClassName | Kubernetes priorityClass name for the redis-ha-server pod | string | "" |
rbac.create | Create and use RBAC resources | bool | true |
redis.annotations | Annotations for the redis statefulset | object | {} |
redis.authClients | It is possible to disable client side certificates authentication when "authClients" is set to "no" | string | "" |
redis.config | Any 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) | object | see values.yaml |
redis.config.maxmemory | Max memory to use for each redis instance. Default is unlimited. | string | "0" |
redis.config.maxmemory-policy | Max memory policy to use for each redis instance. Default is volatile-lru. | string | "volatile-lru" |
redis.config.min-replicas-max-lag | Value in seconds | int | 5 |
redis.config.repl-diskless-sync | When enabled, directly sends the RDB over the wire to slaves, without using the disk as intermediate storage. Default is false. | string | "yes" |
redis.config.save | Please 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.customArgs | Allows overriding the redis container arguments | list | [] |
redis.customCommand | Allows overriding the redis container command | list | [] |
redis.customConfig | Allows for custom redis.conf files to be applied. If this is used then redis.config is ignored | string | nil |
redis.disableCommands | Array with commands to disable | list | ["FLUSHDB","FLUSHALL"] |
redis.envFrom | Load environment variables from ConfigMap/Secret | list | [] |
redis.extraVolumeMounts | additional volumeMounts for Redis container | list | [] |
redis.lifecycle | Container Lifecycle Hooks for redis container Ref: https://kubernetes.io/docs/concepts/containers/container-lifecycle-hooks/ | object | see values.yaml |
redis.livenessProbe | Liveness probe parameters for redis container | object | {"enabled":true,"failureThreshold":5,"initialDelaySeconds":30,"periodSeconds":15,"successThreshold":1,"timeoutSeconds":15} |
redis.livenessProbe.enabled | Enable the Liveness Probe | bool | true |
redis.livenessProbe.failureThreshold | Failure threshold for liveness probe | int | 5 |
redis.livenessProbe.initialDelaySeconds | Initial delay in seconds for liveness probe | int | 30 |
redis.livenessProbe.periodSeconds | Period in seconds after which liveness probe will be repeated | int | 15 |
redis.livenessProbe.successThreshold | Success threshold for liveness probe | int | 1 |
redis.livenessProbe.timeoutSeconds | Timeout seconds for liveness probe | int | 15 |
redis.masterGroupName | Redis convention for naming the cluster group: must match ^[\\w-\\.]+$ and can be templated | string | "mymaster" |
redis.minReadySeconds | Configure the 'minReadySeconds' parameter to StatefulSet ref: https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/#minreadyseconds | int | 0 |
redis.podAnnotations | Annotations to be added to the redis statefulset pods | object | {} |
redis.port | Port to access the redis service | int | 6379 |
redis.readinessProbe | Readiness probe parameters for redis container | object | {"enabled":true,"failureThreshold":5,"initialDelaySeconds":30,"periodSeconds":15,"successThreshold":1,"timeoutSeconds":15} |
redis.readinessProbe.enabled | Enable the Readiness Probe | bool | true |
redis.readinessProbe.failureThreshold | Failure threshold for readiness probe | int | 5 |
redis.readinessProbe.initialDelaySeconds | Initial delay in seconds for readiness probe | int | 30 |
redis.readinessProbe.periodSeconds | Period in seconds after which readiness probe will be repeated | int | 15 |
redis.readinessProbe.successThreshold | Success threshold for readiness probe | int | 1 |
redis.readinessProbe.timeoutSeconds | Timeout seconds for readiness probe | int | 15 |
redis.resources | CPU/Memory for master/slave nodes resource requests/limits | object | {} |
redis.startupProbe | Startup probe parameters for redis container | object | {"enabled":true,"failureThreshold":5,"initialDelaySeconds":30,"periodSeconds":15,"successThreshold":1,"timeoutSeconds":15} |
redis.startupProbe.enabled | Enable Startup Probe | bool | true |
redis.startupProbe.failureThreshold | Failure threshold for startup probe | int | 5 |
redis.startupProbe.initialDelaySeconds | Initial delay in seconds for startup probe | int | 30 |
redis.startupProbe.periodSeconds | Period in seconds after which startup probe will be repeated | int | 15 |
redis.startupProbe.successThreshold | Success threshold for startup probe | int | 1 |
redis.startupProbe.timeoutSeconds | Timeout seconds for startup probe | int | 15 |
redis.terminationGracePeriodSeconds | Increase terminationGracePeriodSeconds to allow writing large RDB snapshots. (k8s default is 30s) ref: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/#pod-termination-forced | int | 60 |
redis.tlsPort | TLS Port to access the redis service | int | nil |
redis.tlsReplication | Configures redis with tls-replication parameter, if true sets "tls-replication yes" in redis.conf | bool | nil |
redis.updateStrategy | Update strategy for Redis StatefulSet # ref: https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/#update-strategies | object | {"type":"RollingUpdate"} |
redisPassword | A password that configures a requirepass and masterauth in the conf parameters (Requires auth: enabled) | string | nil |
replicas | Number of |
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.
- Pick a serverConnect Hetzner, OVHcloud or AWS. The builder starts on Hetzner, the cheapest sample rate.
- Place the chartredis-ha is pinned at v4.39.0 in opentenant.yaml. Drag more apps from the marketplace onto a rack.
- 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