redis

by groundhog2k

Helm chartv2.5.1App 8.10.3

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

KeyTypeDefaultDescription
fullnameOverridestring""Fully override the deployment name
nameOverridestring""Partially override the deployment name

Deployment parameters

KeyTypeDefaultDescription
image.pullPolicystring"IfNotPresent"Image pull policy
image.registrystring"docker.io"Image registry
image.repositorystring"redis"Image name
image.tagstring""Image tag
imagePullSecretslist[]Image pull secrets
extraInitContainerslist[]Extra init containers
extaContainerslist[]Extra containers for usage as sidecars
livenessProbeobjectsee values.yamlLiveness probe configuration
startupProbeobjectsee values.yamlStartup probe configuration
readinessProbeobjectsee values.yamlReadiness probe configuration
customLivenessProbeobject{}Custom liveness probe (overwrites default liveness probe configuration)
customStartupProbeobject{}Custom startup probe (overwrites default startup probe configuration)
customReadinessProbeobject{}Custom readiness probe (overwrites default readiness probe configuration)
initResourcesobject{}Resource limits and requests for the default init container
resourcesobject{}Resource limits and requests
sentinelResourcesobject{}Resource limits and requests (for Redis Sentinel - only when haMode is enabled)
priorityClassNamestring""Deployment priority class name
terminationGracePeriodSecondsintnilPod termination grace period in seconds (Kubernetes default 30 when not set)
lifecycleobject{}Lifecycle hooks for the Redis server container (f.e. preStop)
sentinelLifecycleobject{}Lifecycle hooks for the Valkey Sentinel container (only when haMode is enabled)
nodeSelectorobject{}Deployment node selector
customLabelsobject{}Additional labels for Deployment or StatefulSet
customAnnotationsobject{}Additional annotations for Deployment or StatefulSet
podAnnotationsobject{}Additional pod annotations
podLabelsobject{}Additional pod labels
podSecurityContextobjectsee values.yamlPod security context
securityContextobjectsee values.yamlContainer security context
envlist[]Additional container environmment variables (Redis server, Sentinel and Init container)
argslist[]Additional container command arguments (Redis server)
sentinelArgslist[]Arguments for the container entrypoint process (Sentinel)
serviceAccount.annotationsobject{}Additional service account annotations
serviceAccount.createboolfalseEnable service account creation
serviceAccount.namestring""Name of the service account
affinityobject{}Affinity for pod assignment
tolerationslist[]Tolerations for pod assignment
topologySpreadConstraintsobject{}Topology spread constraints for pods
podManagementPolicystring"OrderedReady"Pod management policy
updateStrategyTypestring"RollingUpdate"Pod update strategy
revisionHistoryLimitintnilMaximum number of revisions maintained in revision history
podDisruptionBudgetobject{}Pod disruption budget
podDisruptionBudget.minAvailableintnilMinimum number of pods that must be available after eviction
podDisruptionBudget.maxUnavailableintnilMaximum number of pods that can be unavailable after eviction

Metrics support parameters

KeyTypeDefaultDescription
metrics.enabledboolfalseEnable metrics support
metrics.exporter.image.pullPolicystring"IfNotPresent"Image pull policy
metrics.exporter.image.registrystring"docker.io"Image registry
metrics.exporter.image.repositorystring"oliver006/redis_exporter"Image name
metrics.exporter.image.tagstring"v1.84.0"Image tag
metrics.exporter.resourcesobject{}Resource limits and requests
metrics.exporter.livenessProbeobjectsee values.yamlLiveness probe configuration
metrics.exporter.startupProbeobjectsee values.yamlStartup probe configuration
metrics.exporter.readinessProbeobjectsee values.yamlReadiness probe configuration
metrics.exporter.customLivenessProbeobject{}Custom liveness probe (overwrites default liveness probe configuration)
metrics.exporter.customStartupProbeobject{}Custom startup probe (overwrites default startup probe configuration)
metrics.exporter.customReadinessProbeobject{}Custom readiness probe (overwrites default readiness probe configuration)
metrics.exporter.envlist[]Additional container environmment variables (Exporter only)
metrics.exporter.argslist[]Additional container command arguments (Exporter only)
metrics.exporter.extraExporterEnvSecretslist[]A list of existing secrets that will be mounted into the exporter container as environment variables
metrics.exporter.extraExporterSecretslist[]A list of additional existing secrets that will be mounted into the exporter container
metrics.exporter.extraExporterSecrets[].namestringnilName of the existing K8s secret
metrics.exporter.extraExporterSecrets[].defaultModeint0440Mount default access mode
metrics.exporter.extraExporterSecrets[].mountPathstringnilMount path where the secret should be mounted into the container (f.e. /mysecretfolder)
metrics.exporter.extraExporterConfigs[].namestringnilName of the existing K8s configMap
metrics.exporter.extraExporterConfigs[].defaultModeint0440Mount default access mode
metrics.exporter.extraExporterConfigs[].mountPathstringnilMount path where the configMap should be mounted into the container (f.e. /myconfigfolder)
metrics.service.typestring"ClusterIP"Service type (not available when haMode is enabled)
metrics.service.servicePortint9121Redis metrics exporter service port
metrics.service.containerPortint9121Redis metrics exporter container port
metrics.service.nodePortintnilThe node port (only relevant for type LoadBalancer or NodePort - not available when haMode is enabled)
metrics.service.clusterIPstringnilThe cluster ip address (only relevant for type LoadBalancer or NodePort)
metrics.service.loadBalancerIPstringnilThe load balancer ip address (only relevant for type LoadBalancer - not available when haMode is enabled)
metrics.service.loadBalancerSourceRangeslist[]The list of IP CIDR ranges that are allowed to access the load balancer (only relevent for type LoadBalancer)
metrics.service.annotationsobject{}Additional service annotations
metrics.service.lablesobject{}Additional service labels
metrics.serviceMonitor.additionalLabelsobject{}Additional labels for the service monitor object
metrics.serviceMonitor.annotationsobject{}Annotations for the service monitor object
metrics.serviceMonitor.intervalDurationnilScrape interval for prometheus
metrics.serviceMonitor.scrapeTimeoutDurationnilScrape timeout value
metrics.serviceMonitor.extraEndpointParametersobjectnilExtra parameters rendered to the service monitor endpoint
metrics.serviceMonitor.extraParametersobjectnilExtra parameters rendered to the service monitor object

Service parameters

KeyTypeDefaultDescription
service.typestring"ClusterIP"Service type (not available when haMode is enabled)
service.serverPortint6379Redis server service port
service.sentinelPortint26379Redis sentinel service port
service.nodePortintnilThe node port (only relevant for type LoadBalancer or NodePort - not available when haMode is enabled)
service.clusterIPstringnilThe cluster ip address (only relevant for type LoadBalancer or NodePort)
service.loadBalancerIPstringnilThe load balancer ip address (only relevant for type LoadBalancer - not available when haMode is enabled)
service.loadBalancerSourceRangeslist[]The list of IP CIDR ranges that are allowed to access the load balancer (only relevent for type LoadBalancer)
service.annotationsobject{}Additional service annotations
service.lablesobject{}Additional service labels

Storage parameters

KeyTypeDefaultDescription
storage.accessModes[0]string"ReadWriteOnce"Storage access mode
storage.persistentVolumeClaimNames

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.

  1. Pick a serverConnect Hetzner, OVHcloud or AWS. The builder starts on Hetzner, the cheapest sample rate.
  2. Place the chartredis is pinned at v2.5.1 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