redis
by groundhog2k
A Helm chart for Redis on Kubernetes
About this chart
Redis
Changelog
see RELEASENOTES.md
A Helm chart for Redis on Kubernetes
TL;DR
helm repo add groundhog2k https://groundhog2k.github.io/helm-charts/
helm install my-release groundhog2k/redis
Basic setup without high availability
haMode.enabled: false
This will create one standalone Redis instance which can be reached based on the service: configuration (ClusterIP & Port 6379 by default)
+-------------------+
| Redis standalone |
+-------------------+
Advanced setup with high availability support
haMode.enabled: true
This will create 3 pods by default, with 1 Redis master (M1) and 2 Redis replications (R1/R2). Every pod has 2 containers, one for the Redis server and one for the Redis sentinel (S1/S2/S3).
The default quorom to decide for a new master is set to 2. Have a look at all configurable parameters in values section haMode:
A Sentinal instance can be reached based on the service: configuration (ClusterIP & Sentinel port 26379 by default).
+----+
| M1 |
| S1 |
+----+
|
+----+ | +----+
| R2 |----+----| R3 |
| S2 | | S3 |
+----+ +----+
Spreading the pods across failure domains
Each pod in HA mode runs a Redis server and a Sentinel. The chart does not set pod spread constraints by default, so Kubernetes may place multiple pods in the same failure domain. With the default three pods and haMode.quorum: 2, tolerating the loss of any one zone requires placing one pod in each of three independent zones.
Pod placement is cluster-specific. If zone-level spreading is appropriate for your cluster, a hard constraint can require three eligible zones for the default HA setup. For example:
topologySpreadConstraints:
- maxSkew: 1
minDomains: 3
topologyKey: topology.kubernetes.io/zone
whenUnsatisfiable: DoNotSchedule
labelSelector:
matchLabels:
app.kubernetes.io/name: redis
app.kubernetes.io/instance: my-release
This example assumes nodes have the topology.kubernetes.io/zone label and that the cluster supports minDomains. It leaves a pod Pending if three eligible zones are unavailable, which can prevent the release from becoming ready. Replace my-release with the Helm release name and redis with the nameOverride value if set. Adapt or omit the constraint to suit your cluster; fewer than three failure domains cannot provide the same single-zone failure tolerance with the default HA configuration.
Failover on shutdown
With haMode.failoverOnShutdown: true (default) the Redis server container gets a preStop hook. When the master pod is stopped (f.e. during a rolling update or node drain), the hook asks a sentinel of another pod for a failover and waits until another pod is master (max. haMode.failoverOnShutdownTimeout seconds) before the server is shut down. Clients therefore don't have to wait until the master is detected as down (haMode.downAfterMilliseconds). Replicas shut down without delay. The hook output is logged to the Valkey server container (preStop[<pod>]: ...).
Note: the first upgrade from a chart version without this feature triggers a rollout, but the existing pods do not yet have the preStop hook; that rollout can therefore still incur the normal Sentinel detection delay when the master stops. The hook applies only to pods created from the updated pod template. Changing haMode.failoverOnShutdown on an existing release likewise does not affect the rollout that applies the change. When disabling it, the hook script is removed from the scripts ConfigMap before the old pods are stopped. A custom lifecycle replaces the built-in hook.
Introduction
This chart uses the original Redis image from Docker Hub to deploy a stateful Redis instance in a Kubernetes cluster.
It fully supports deployment of the multi-architecture docker image.
Prerequisites
- Kubernetes 1.12+
- Helm 3.x
- PV provisioner support in the underlying infrastructure
Installing the Chart
To install the chart with the release name my-release:
helm install my-release groundhog2k/redis
Uninstalling the Chart
To uninstall/delete the my-release deployment:
helm uninstall my-release
Common parameters
| Key | Type | Default | Description |
|---|---|---|---|
| fullnameOverride | string | "" | Fully override the deployment name |
| nameOverride | string | "" | Partially override the deployment name |
Deployment parameters
| Key | Type | Default | Description |
|---|---|---|---|
| image.pullPolicy | string | "IfNotPresent" | Image pull policy |
| image.registry | string | "docker.io" | Image registry |
| image.repository | string | "redis" | Image name |
| image.tag | string | "" | Image tag |
| imagePullSecrets | list | [] | Image pull secrets |
| extraInitContainers | list | [] | Extra init containers |
| extaContainers | list | [] | Extra containers for usage as sidecars |
| livenessProbe | object | see values.yaml | Liveness probe configuration |
| startupProbe | object | see values.yaml | Startup probe configuration |
| readinessProbe | object | see values.yaml | Readiness probe configuration |
| customLivenessProbe | object | {} | Custom liveness probe (overwrites default liveness probe configuration) |
| customStartupProbe | object | {} | Custom startup probe (overwrites default startup probe configuration) |
| customReadinessProbe | object | {} | Custom readiness probe (overwrites default readiness probe configuration) |
| initResources | object | {} | Resource limits and requests for the default init container |
| resources | object | {} | Resource limits and requests |
| sentinelResources | object | {} | Resource limits and requests (for Redis Sentinel - only when haMode is enabled) |
| priorityClassName | string | "" | Deployment priority class name |
| terminationGracePeriodSeconds | int | nil | Pod termination grace period in seconds (Kubernetes default 30 when not set) |
| lifecycle | object | {} | Lifecycle hooks for the Redis server container (f.e. preStop) |
| sentinelLifecycle | object | {} | Lifecycle hooks for the Valkey Sentinel container (only when haMode is enabled) |
| nodeSelector | object | {} | Deployment node selector |
| customLabels | object | {} | Additional labels for Deployment or StatefulSet |
| customAnnotations | object | {} | Additional annotations for Deployment or StatefulSet |
| podAnnotations | object | {} | Additional pod annotations |
| podLabels | object | {} | Additional pod labels |
| podSecurityContext | object | see values.yaml | Pod security context |
| securityContext | object | see values.yaml | Container security context |
| env | list | [] | Additional container environmment variables (Redis server, Sentinel and Init container) |
| args | list | [] | Additional container command arguments (Redis server) |
| sentinelArgs | list | [] | Arguments for the container entrypoint process (Sentinel) |
| serviceAccount.annotations | object | {} | Additional service account annotations |
| serviceAccount.create | bool | false | Enable service account creation |
| serviceAccount.name | string | "" | Name of the service account |
| affinity | object | {} | Affinity for pod assignment |
| tolerations | list | [] | Tolerations for pod assignment |
| topologySpreadConstraints | object | {} | Topology spread constraints for pods |
| podManagementPolicy | string | "OrderedReady" | Pod management policy |
| updateStrategyType | string | "RollingUpdate" | Pod update strategy |
| revisionHistoryLimit | int | nil | Maximum number of revisions maintained in revision history |
| podDisruptionBudget | object | {} | Pod disruption budget |
| podDisruptionBudget.minAvailable | int | nil | Minimum number of pods that must be available after eviction |
| podDisruptionBudget.maxUnavailable | int | nil | Maximum number of pods that can be unavailable after eviction |
Metrics support parameters
| Key | Type | Default | Description |
|---|---|---|---|
| metrics.enabled | bool | false | Enable metrics support |
| metrics.exporter.image.pullPolicy | string | "IfNotPresent" | Image pull policy |
| metrics.exporter.image.registry | string | "docker.io" | Image registry |
| metrics.exporter.image.repository | string | "oliver006/redis_exporter" | Image name |
| metrics.exporter.image.tag | string | "v1.84.0" | Image tag |
| metrics.exporter.resources | object | {} | Resource limits and requests |
| metrics.exporter.livenessProbe | object | see values.yaml | Liveness probe configuration |
| metrics.exporter.startupProbe | object | see values.yaml | Startup probe configuration |
| metrics.exporter.readinessProbe | object | see values.yaml | Readiness probe configuration |
| metrics.exporter.customLivenessProbe | object | {} | Custom liveness probe (overwrites default liveness probe configuration) |
| metrics.exporter.customStartupProbe | object | {} | Custom startup probe (overwrites default startup probe configuration) |
| metrics.exporter.customReadinessProbe | object | {} | Custom readiness probe (overwrites default readiness probe configuration) |
| metrics.exporter.env | list | [] | Additional container environmment variables (Exporter only) |
| metrics.exporter.args | list | [] | Additional container command arguments (Exporter only) |
| metrics.exporter.extraExporterEnvSecrets | list | [] | A list of existing secrets that will be mounted into the exporter container as environment variables |
| metrics.exporter.extraExporterSecrets | list | [] | A list of additional existing secrets that will be mounted into the exporter container |
| metrics.exporter.extraExporterSecrets[].name | string | nil | Name of the existing K8s secret |
| metrics.exporter.extraExporterSecrets[].defaultMode | int | 0440 | Mount default access mode |
| metrics.exporter.extraExporterSecrets[].mountPath | string | nil | Mount path where the secret should be mounted into the container (f.e. /mysecretfolder) |
| metrics.exporter.extraExporterConfigs[].name | string | nil | Name of the existing K8s configMap |
| metrics.exporter.extraExporterConfigs[].defaultMode | int | 0440 | Mount default access mode |
| metrics.exporter.extraExporterConfigs[].mountPath | string | nil | Mount path where the configMap should be mounted into the container (f.e. /myconfigfolder) |
| metrics.service.type | string | "ClusterIP" | Service type (not available when haMode is enabled) |
| metrics.service.servicePort | int | 9121 | Redis metrics exporter service port |
| metrics.service.containerPort | int | 9121 | Redis metrics exporter container port |
| metrics.service.nodePort | int | nil | The node port (only relevant for type LoadBalancer or NodePort - not available when haMode is enabled) |
| metrics.service.clusterIP | string | nil | The cluster ip address (only relevant for type LoadBalancer or NodePort) |
| metrics.service.loadBalancerIP | string | nil | The load balancer ip address (only relevant for type LoadBalancer - not available when haMode is enabled) |
| metrics.service.loadBalancerSourceRanges | list | [] | The list of IP CIDR ranges that are allowed to access the load balancer (only relevent for type LoadBalancer) |
| metrics.service.annotations | object | {} | Additional service annotations |
| metrics.service.lables | object | {} | Additional service labels |
| metrics.serviceMonitor.additionalLabels | object | {} | Additional labels for the service monitor object |
| metrics.serviceMonitor.annotations | object | {} | Annotations for the service monitor object |
| metrics.serviceMonitor.interval | Duration | nil | Scrape interval for prometheus |
| metrics.serviceMonitor.scrapeTimeout | Duration | nil | Scrape timeout value |
| metrics.serviceMonitor.extraEndpointParameters | object | nil | Extra parameters rendered to the service monitor endpoint |
| metrics.serviceMonitor.extraParameters | object | nil | Extra parameters rendered to the service monitor object |
Service parameters
| Key | Type | Default | Description |
|---|---|---|---|
| service.type | string | "ClusterIP" | Service type (not available when haMode is enabled) |
| service.serverPort | int | 6379 | Redis server service port |
| service.sentinelPort | int | 26379 | Redis sentinel service port |
| service.nodePort | int | nil | The node port (only relevant for type LoadBalancer or NodePort - not available when haMode is enabled) |
| service.clusterIP | string | nil | The cluster ip address (only relevant for type LoadBalancer or NodePort) |
| service.loadBalancerIP | string | nil | The load balancer ip address (only relevant for type LoadBalancer - not available when haMode is enabled) |
| service.loadBalancerSourceRanges | list | [] | The list of IP CIDR ranges that are allowed to access the load balancer (only relevent for type LoadBalancer) |
| service.annotations | object | {} | Additional service annotations |
| service.lables | object | {} | Additional service labels |
Storage parameters
| Key | Type | Default | Description |
|---|---|---|---|
| storage.accessModes[0] | string | "ReadWriteOnce" | Storage access mode |
| storage.persistentVolumeClaimName | s |
Deploy redis with OpenTenant
Each tenant gets its own release of this chart, with its own namespace, secrets and domain. The builder below already has redis 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 is pinned at v2.5.1 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