You are looking at the documentation of a prior release. To read the documentation of the latest release, please visit here.

New to KubeDB? Please start here.


What is Redis

Redis is a Kubernetes Custom Resource Definitions (CRD). It provides declarative configuration for Redis in a Kubernetes native way. You only need to describe the desired database configuration in a Redis object, and the KubeDB operator will create Kubernetes objects in the desired state for you.

Redis Spec

As with all other Kubernetes objects, a Redis needs apiVersion, kind, and metadata fields. It also needs a .spec section. Below is an example Redis object.

kind: Redis
  name: r1
  namespace: demo
  version: 4
  mode: Cluster
    master: 3
    replicas: 1
    storageClassName: "standard"
    - ReadWriteOnce
        storage: 1Gi
      namespace: demo
        app: kubedb
      interval: 10s
      name: rd-custom-config
      passMe: ToDatabasePod
        passMe: ToStatefulSet
      schedulerName: my-scheduler
        disktype: ssd
      - name: myregistrykey
      - "--loglevel verbose"
      - name: ENV_VARIABLE
        value: "value"
          memory: "64Mi"
          cpu: "250m"
          memory: "128Mi"
          cpu: "500m"
      passMe: ToService
      type: NodePort
      - name:  http
        port:  9200
        targetPort: http
  terminationPolicy: Pause
    type: RollingUpdate


spec.version is a required field specifying the name of the RedisVersion crd where the docker images are specified. Currently, when you install KubeDB, it creates the following RedisVersion crd,

  • 4.0.11, 4.0.6-v2, 4.0.6-v1, 4.0.6, 4.0-v2, 4.0-v1, 4.0, 4-v1, 4, 5.0.3-v1, 5.0.3, 5.0-v1, 5.0


spec.mode specifies the mode in which Redis server instance(s) will be deployed. The possible values are either "Standalone" or "Cluster". The default value is "Standalone".

  • Standalone: In this mode, the operator to starts a standalone Redis server.

  • Cluster: In this mode, the operator will deploy Redis cluster.


If spec.mode is set to "Cluster", users can optionally provide a cluster specification. Currently, the following two parameters can be configured:

  • spec.cluster.master: specifies the number of Redis master nodes. It must be greater or equal to 3. If not set, the operator set it to 3.
  • spec.cluster.replicas: specifies the number of replica nodes per master. It must be greater than 0. If not set, the operator set it to 1.

If spec.mode is set to "Cluster", then spec.replicas field is ignored.

Since 0.10.0-rc.0, If you set spec.storageType: to Durable, then is a required field that specifies the StorageClass of PVCs dynamically allocated to store data for the database. This storage spec will be passed to the StatefulSet created by KubeDB operator to run database pods. You can specify any StorageClass available in your cluster with appropriate resource requests.

  • is the name of the StorageClass used to provision PVCs. PVCs don’t necessarily have to request a class. A PVC with its storageClassName set equal to "" is always interpreted to be requesting a PV with no class, so it can only be bound to PVs with no class (no annotation or one set equal to “”). A PVC with no storageClassName is not quite the same and is treated differently by the cluster depending on whether the DefaultStorageClass admission plugin is turned on.
  • uses the same conventions as Kubernetes PVCs when requesting storage with specific access modes.
  • can be used to request specific quantities of storage. This follows the same resource model used by PVCs.

To learn how to configure, please visit the links below:


Redis managed by KubeDB can be monitored with builtin-Prometheus and CoreOS-Prometheus operator out-of-the-box. To learn more,


spec.configSource is an optional field that allows users to provide custom configuration for Redis. This field accepts a VolumeSource. So you can use any kubernetes supported volume source such as configMap, secret, azureDisk etc. To learn more about how to use a custom configuration file see here.


KubeDB allows providing a template for database pod through spec.podTemplate. KubeDB operator will pass the information provided in spec.podTemplate to the StatefulSet created for Redis server.

KubeDB accept following fields to set in spec.podTemplate:

  • metadata:
    • annotations (pod’s annotation)
  • controller:
    • annotations (statefulset’s annotation)
  • spec:
    • args
    • env
    • resources
    • initContainers
    • imagePullSecrets
    • nodeSelector
    • affinity
    • schedulerName
    • tolerations
    • priorityClassName
    • priority
    • securityContext
    • livenessProbe
    • readinessProbe
    • lifecycle

Uses of some field of spec.podTemplate is described below,


spec.podTemplate.spec.args is an optional field. This can be used to provide additional arguments to database installation.


spec.podTemplate.spec.env is an optional field that specifies the environment variables to pass to the Redis docker image.

Note that, KubeDB does not allow to update the environment variables. If you try to update environment variables, KubeDB operator will reject the request with following error,

Error from server (BadRequest): error when applying patch:
for: "./redis.yaml": admission webhook "" denied the request: precondition failed for:
At least one of the following was changed:


KubeDB provides the flexibility of deploying Redis server from a private Docker registry. To learn how to deploy Redis from a private registry, please visit here.


spec.podTemplate.spec.nodeSelector is an optional field that specifies a map of key-value pairs. For the pod to be eligible to run on a node, the node must have each of the indicated key-value pairs as labels (it can have additional labels as well). To learn more, see here .


spec.podTemplate.spec.resources is an optional field. This can be used to request compute resources required by the database pods. To learn more, visit here.


You can also provide a template for the services created by KubeDB operator for Redis server through spec.serviceTemplate. This will allow you to set the type and other properties of the services.

KubeDB allows following fields to set in spec.serviceTemplate:

  • metadata:
    • annotations
  • spec:
    • type
    • ports
    • clusterIP
    • externalIPs
    • loadBalancerIP
    • loadBalancerSourceRanges
    • externalTrafficPolicy
    • healthCheckNodePort


You can specify update strategy of StatefulSet created by KubeDB for Redis server thorough spec.updateStrategy field. The default value of this field is RollingUpdate. In future, we will use this field to determine how automatic migration from old KubeDB version to new one should behave.


terminationPolicy gives flexibility whether to nullify(reject) the delete operation of Redis crd or which resources KubeDB should keep or delete when you delete Redis crd. KubeDB provides following four termination policies:

  • DoNotTerminate
  • Pause (Default)
  • Delete
  • WipeOut

When, terminationPolicy is DoNotTerminate, KubeDB takes advantage of ValidationWebhook feature in Kubernetes 1.9.0 or later clusters to implement DoNotTerminate feature. If admission webhook is enabled, DoNotTerminate prevents users from deleting the database as long as the spec.terminationPolicy is set to DoNotTerminate.

Following table show what KubeDB does when you delete Redis crd for different termination policies,

1. Block Delete operation
2. Create Dormant Database
3. Delete StatefulSet
4. Delete Services
5. Delete PVCs
6. Delete Secrets

If you don’t specify spec.terminationPolicy KubeDB uses Pause termination policy by default.

Next Steps