{
  "id": "db-controller",
  "title": "Manage Redis Enterprise databases for Kubernetes",
  "url": "https://redis.io/docs/latest/operate/kubernetes/7.8.4/re-databases/db-controller/",
  "summary": "This section describes how the database controller provides the ability to create, manage, and use databases via a database custom resource.",
  "content": "## Redis Enterprise database (REDB) lifecycle\n\nA Redis Enterprise database (REDB) is created with a custom resource file. The custom resource defines the size, name, and other specifications for the REDB. The database is created when you apply the custom resource file.\n\nThe database controller in Redis Enterprise for Kubernetes:\n\n- Discovers the custom resource\n- Makes sure the REDB is created in the same namespace as the Redis Enterprise cluster (REC)\n- Maintains consistency between the custom resource and the REDB\n\nThe database controller recognizes the new custom resource and validates the specification.\nIf valid, the controller combines the values specified in\nthe custom resource with default values to create a full specification. It then uses this full specification to create the\ndatabase on the specified Redis Enterprise cluster (REC).\n\nOnce the database is created, it is exposed with the same service mechanisms by the service rigger for the Redis Enterprise cluster.\nIf the database [custom resource is deleted](), the database and its services are deleted from the cluster.\n\n### Flexible deployment options\n\nDatabases in multiple namespaces can be managed by the same operator. To learn more, see [Manage databases in multiple namespaces]().\n\nTo learn more about designing a multi-namespace Redis Enterprise cluster, see [flexible deployment options]().\n\n## Create a database\n\nYour Redis Enterprise database custom resource must be of the `kind: RedisEnterpriseDatabase` and have values for `name` and `memorySize`. All other values are optional and will be defaults if not specified.\n\n1. Create a file (in this example mydb.yaml) that contains your database custom resource.\n\n    ```YAML\n    apiVersion: app.redislabs.com/v1alpha1\n    kind: RedisEnterpriseDatabase\n    metadata:\n      name: mydb\n    spec:\n      memorySize: 1GB\n    ```\n\n    To create a REDB in a different namespace from your REC, you need to specify the cluster with `redisEnterpriseCluster` in the `spec` section of your RedisEnterpriseDatabase custom resource.\n\n     ```YAML\n     redisEnterpriseCluster:\n       name: rec\n     ```\n\n1. Apply the file in the namespace you want your database to be in.\n\n    ```sh\n    kubectl apply -f mydb.yaml\n    ```\n\n1. Check the status of your database.\n\n    ```sh\n    kubectl get redb mydb -o jsonpath=\"{.status.status}\"\n    ```\n\n    When the status is `active`, the database is ready to use.\n\n## Modify a database\n\nThe custom resource defines the properties of the database.\nTo change the database, you can edit your original specification and apply the change or use `kubectl edit`.\n\nTo modify the database:\n\n1. Edit the definition:\n\n    ```sh\n    kubectl edit redb mydb\n    ```\n\n1. Change the specification (only properties in `spec` section) and save the changes.  \n    For more details, see [RedisEnterpriseDatabaseSpec](https://github.com/RedisLabs/redis-enterprise-k8s-docs/blob/master/redis_enterprise_database_api.md#redisenterprisedatabasespec) or [Options for Redis Enterprise databases](). \n\n1. Monitor the status to see when the changes take effect:\n\n    ```sh\n    kubectl get redb mydb -o jsonpath=\"{.status.status}\"\n    ```\n\n    When the status is `active`, the database is ready for use.\n\n## Delete a database\n\nThe database exists as long as the custom resource exists.\nIf you delete the custom resource, the database controller deletes the database.\nThe database controller removes the database and its services from the cluster.\n\nTo delete a database, run:\n\n```sh\nkubectl delete redb mydb\n```\n\n## Connect to a database\n\nAfter the database controller creates a database, the services for accessing the database are created in the same namespace. By default there are two services, one 'ClusterIP' service and one 'headless' service.  \nConnection information for the database is stored in a Kubernetes [secret](https://kubernetes.io/docs/concepts/configuration/secret/) maintained by the database controller. This secret contains:\n\n- The database port (`port`)\n- A comma separated list of service names (`service_names`)\n- The database password for authenticating (`password`)\n\nThe name of that secret is stored in the database custom resource.\n\n\nUse these steps to connect to your database from within your K8s cluster. To access your database from outside the K8s cluster, set up the [Ingress]() controller or use OpenShift routes.\n\n\n1. Retrieve the secret name.\n\n    ```sh\n    kubectl get redb mydb -o jsonpath=\"{.spec.databaseSecretName}\"\n    ```\n\n      The database secret name usually takes the form of `redb-\u003cdatabase_name\u003e`, so in our example it will be `redb-mydb`.\n\n1. Retrieve and decode the password.\n\n    ```sh\n    kubectl get secret redb-mydb -o jsonpath=\"{.data.password}\" | base64 --decode\n    ```\n\n1. Retrieve and decode the port number.\n\n    ```sh\n    kubectl get secret redb-mydb -o jsonpath=\"{.data.port}\" | base64 --decode\n    ```\n\n1. Retrieve and decode the service_names.\n\n    ```sh\n    kubectl get secret redb-mydb -o jsonpath=\"{.data.service_names}\" | base64 --decode\n    ```\n\n    You'll need to pick just one service listed here to use for connecting.\n\n1. From a pod within your cluster, use `redis-cli` to connect to your database.\n\n    ```sh\n    redis-cli -h \u003cservice_name\u003e -p \u003cport\u003e\n    ```\n\n1. Enter the password you retrieved from the secret.\n\n    ```sh\n    auth \u003cpassword\u003e\n    ```\n\n    You are now connected to your database!\n",
  "tags": ["docs","operate","kubernetes"],
  "last_updated": "2026-04-08T12:21:52-07:00"
}

