You are looking at the documentation of a prior release. To read the documentation of the latest release, please
visit here.
We use cookies and other similar technology to collect data to improve your experience on our site, as described in our Privacy Policy.
Run Production-Grade Databases on Kubernetes
Backup and Recovery Solution for Kubernetes
Run Production-Grade Vault on Kubernetes
Secure HAProxy Ingress Controller for Kubernetes
Kubernetes Configuration Syncer
Kubernetes Authentication WebHook Server
KubeDB simplifies Provision, Upgrade, Scaling, Volume Expansion, Monitor, Backup, Restore for various Databases in Kubernetes on any Public & Private Cloud
A complete Kubernetes native disaster recovery solution for backup and restore your volumes and databases in Kubernetes on any public and private clouds.
KubeVault is a Git-Ops ready, production-grade solution for deploying and configuring Hashicorp's Vault on Kubernetes.
Secure HAProxy Ingress Controller for Kubernetes
Kubernetes Configuration Syncer
Kubernetes Authentication WebHook Server
New to KubeDB? Please start here.
This guide will show you how to use KubeDB
Enterprise operator to update the resources of a Redis cluster database.
At first, you need to have a Kubernetes cluster, and the kubectl
command-line tool must be configured to communicate with your cluster. If you do not already have a cluster, you can create one by using kind.
Install KubeDB
Community and Enterprise operator in your cluster following the steps here.
You should be familiar with the following KubeDB
concepts:
To keep everything isolated, we are going to use a separate namespace called demo
throughout this tutorial.
$ kubectl create ns demo
namespace/demo created
Note: YAML files used in this tutorial are stored in docs/examples/redis directory of kubedb/docs repository.
Here, we are going to deploy a Redis
cluster using a supported version by KubeDB
operator. Then we are going to apply vertical scaling on it.
Now, we are going to deploy a Redis
cluster database with version 5.0.3-v1
.
In this section, we are going to deploy a Redis cluster database. Then, in the next section we will update the resources of the database using RedisOpsRequest
CRD. Below is the YAML of the Redis
CR that we are going to create,
apiVersion: kubedb.com/v1alpha2
kind: Redis
metadata:
name: redis-cluster
namespace: demo
spec:
version: 7.0.5
mode: Cluster
cluster:
master: 3
replicas: 1
storageType: Durable
storage:
resources:
requests:
storage: "1Gi"
storageClassName: "standard"
accessModes:
- ReadWriteOnce
podTemplate:
spec:
resources:
requests:
cpu: "100m"
memory: "100Mi"
terminationPolicy: Halt
Let’s create the Redis
CR we have shown above,
$ kubectl create -f https://github.com/kubedb/docs/raw/v2023.10.9/docs/examples/redis/scaling/vertical-scaling/rd-cluster.yaml
redis.kubedb.com/redis-cluster created
Now, wait until rd-cluster
has status Ready
. i.e. ,
$ kubectl get redis -n demo
NAME VERSION STATUS AGE
redis-cluster 7.0.5 Ready 7m
Let’s check the Pod containers resources,
$ kubectl get pod -n demo redis-cluster-shard0-0 -o json | jq '.spec.containers[].resources'
{
"limits": {
"memory": "100Mi"
},
"requests": {
"cpu": "100m",
"memory": "100Mi"
}
}
$ kubectl get pod -n demo redis-cluster-shard1-1 -o json | jq '.spec.containers[].resources'
{
"limits": {
"memory": "100Mi"
},
"requests": {
"cpu": "100m",
"memory": "100Mi"
}
}
We can see from the above output that there are some default resources set by the operator for pods across all shards. And the scheduler will choose the best suitable node to place the container of the Pod.
We are now ready to apply the RedisOpsRequest
CR to update the resources of this database.
Here, we are going to update the resources of the cluster database to meet the desired resources after scaling.
In order to update the resources of the database, we have to create a RedisOpsRequest
CR with our desired resources. Below is the YAML of the RedisOpsRequest
CR that we are going to create,
apiVersion: ops.kubedb.com/v1alpha1
kind: RedisOpsRequest
metadata:
name: redisops-vertical
namespace: demo
spec:
type: VerticalScaling
databaseRef:
name: redis-cluster
verticalScaling:
redis:
requests:
memory: "300Mi"
cpu: "200m"
limits:
memory: "800Mi"
cpu: "500m"
Here,
spec.databaseRef.name
specifies that we are performing vertical scaling operation on redis-cluster
database.spec.type
specifies that we are performing VerticalScaling
on our database.spec.verticalScaling.redis
specifies the desired resources after scaling.Let’s create the RedisOpsRequest
CR we have shown above,
$ kubectl apply -f https://github.com/kubedb/docs/raw/v2023.10.9/docs/examples/redis/scaling/vertical-scaling/vertical-cluster.yaml
redisopsrequest.ops.kubedb.com/redisops-vertical created
If everything goes well, KubeDB
Enterprise operator will update the resources of Redis
object and related StatefulSets
and Pods
.
Let’s wait for RedisOpsRequest
to be Successful
. Run the following command to watch RedisOpsRequest
CR,
$ watch kubectl get redisopsrequest -n demo redisops-vertical
NAME TYPE STATUS AGE
redisops-vertical VerticalScaling Successful 6m11s
We can see from the above output that the RedisOpsRequest
has succeeded.
Now, we are going to verify from the Pod yaml whether the resources of the cluster database has updated to meet up the desired state, Let’s check,
$ kubectl get pod -n demo redis-cluster-shard0-0 -o json | jq '.spec.containers[].resources'
{
"limits": {
"cpu": "500m",
"memory": "800Mi"
},
"requests": {
"cpu": "200m",
"memory": "300Mi"
}
}
$ kubectl get pod -n demo redis-cluster-shard1-1 -o json | jq '.spec.containers[].resources'
{
"limits": {
"cpu": "500m",
"memory": "800Mi"
},
"requests": {
"cpu": "200m",
"memory": "300Mi"
}
}
The above output verifies that we have successfully scaled up the resources of the Redis cluster database.
To clean up the Kubernetes resources created by this turorial, run:
$ kubectl patch -n demo rd/redis-cluster -p '{"spec":{"terminationPolicy":"WipeOut"}}' --type="merge"
redis.kubedb.com/redis-cluster patched
$ kubectl delete -n demo redis redis-cluster
redis.kubedb.com "redis-cluster" deleted
$ kubectl delete -n demo redisopsrequest redisops-vertical
redisopsrequest.ops.kubedb.com "redisops-vertical " deleted