Operations
Backup And Restores
Custom Secret
Monitoring
tpl
Redis Replication Cluster Lifecycle Management
This guide demonstrates how to manage a Redis Replication Cluster's operational state in KubeBlocks, including:
- Stopping the cluster to conserve resources
- Starting a stopped cluster
- Restarting cluster components
These operations help optimize resource usage and reduce operational costs in Kubernetes environments.
Lifecycle management operations in KubeBlocks:
Operation | Effect | Use Case |
---|---|---|
Stop | Suspends cluster, retains storage | Cost savings, maintenance |
Start | Resumes cluster operation | Restore service after pause |
Restart | Recreates pods for component | Configuration changes, troubleshooting |
Prerequisites
Before proceeding, ensure the following:
- Environment Setup:
- A Kubernetes cluster is up and running.
- The kubectl CLI tool is configured to communicate with your cluster.
- KubeBlocks CLI and KubeBlocks Operator are installed. Follow the installation instructions here.
- Namespace Preparation: To keep resources isolated, create a dedicated namespace for this tutorial:
kubectl create ns demo
namespace/demo created
Deploy a Redis Replication Cluster
KubeBlocks uses a declarative approach for managing Redis Replication Clusters. Below is an example configuration for deploying a Redis Replication Cluster with two components, redis and redis sentinel.
Apply the following YAML configuration to deploy the cluster:
apiVersion: apps.kubeblocks.io/v1
kind: Cluster
metadata:
name: redis-replication
namespace: demo
spec:
terminationPolicy: Delete
clusterDef: redis
topology: replication
componentSpecs:
- name: redis
serviceVersion: "7.2.4"
disableExporter: false
replicas: 2
resources:
limits:
cpu: '0.5'
memory: 0.5Gi
requests:
cpu: '0.5'
memory: 0.5Gi
volumeClaimTemplates:
- name: data
spec:
storageClassName: ""
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 20Gi
- name: redis-sentinel
replicas: 3
resources:
limits:
cpu: '0.5'
memory: 0.5Gi
requests:
cpu: '0.5'
memory: 0.5Gi
volumeClaimTemplates:
- name: data
spec:
storageClassName: ""
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 20Gi
Verifying the Deployment
Monitor the cluster status until it transitions to the Running state:
kubectl get cluster redis-replication -n demo -w
Expected Output:
NAME CLUSTER-DEFINITION TERMINATION-POLICY STATUS AGE
redis-replication redis Delete Running 3m49s
Check the pod status and roles:
kubectl get pods -l app.kubernetes.io/instance=redis-replication -L kubeblocks.io/role -n demo
Expected Output:
NAME READY STATUS RESTARTS AGE ROLE
redis-replication-redis-0 3/3 Running 0 3m38s primary
redis-replication-redis-1 3/3 Running 0 3m16s secondary
redis-replication-redis-sentinel-0 2/2 Running 0 4m35s
redis-replication-redis-sentinel-1 2/2 Running 0 4m17s
redis-replication-redis-sentinel-2 2/2 Running 0 3m59s
Once the cluster status becomes Running, your Redis cluster is ready for use.
If you are creating the cluster for the very first time, it may take some time to pull images before running.
Cluster Lifecycle Operations
Stopping the Cluster
Stopping a Redis Replication Cluster in KubeBlocks will:
- Terminates all running pods
- Retains persistent storage (PVCs)
- Maintains cluster configuration
This operation is ideal for:
- Temporary cost savings
- Maintenance windows
- Development environment pauses
Option 1: OpsRequest API
Create a Stop operation request:
apiVersion: operations.kubeblocks.io/v1alpha1
kind: OpsRequest
metadata:
name: redis-replication-stop-ops
namespace: demo
spec:
clusterName: redis-replication
type: Stop
Option 2: Cluster API Patch
Modify the cluster spec directly by patching the stop field:
kubectl patch cluster redis-replication -n demo --type='json' -p='[
{
"op": "add",
"path": "/spec/componentSpecs/0/stop",
"value": true
},
{
"op": "add",
"path": "/spec/componentSpecs/1/stop",
"value": true
}
]'
Verifying Cluster Stop
To confirm a successful stop operation:
-
Check cluster status transition:
kubectl get cluster redis-replication -n demo -w
Example Output:
NAME CLUSTER-DEFINITION TERMINATION-POLICY STATUS AGE redis-replication redis Delete Stopping 6m3s redis-replication redis Delete Stopped 6m55s
-
Verify no running pods:
kubectl get pods -n demo
Example Output:
No resources found in demo namespace.
-
Confirm persistent volumes remain:
kubectl get pvc -n demo
Example Output:
NAME STATUS VOLUME CAPACITY ACCESS MODES data-redis-replication-redis-0 Bound pvc-uuid 20Gi RWO data-redis-replication-redis-1 Bound pvc-uuid 20Gi RWO data-redis-replication-redis-sentinel-0 Bound pvc-uuid 20Gi RWO data-redis-replication-redis-sentinel-1 Bound pvc-uuid 20Gi RWO data-redis-replication-redis-sentinel-2 Bound pvc-uuid 20Gi RWO
Starting the Cluster
Starting a stopped Redis Replication Cluster:
- Recreates all pods
- Reattaches persistent storage
- Restores service endpoints
Expected behavior:
- Cluster returns to previous state
- No data loss occurs
- Services resume automatically
Initiate a Start operation request:
apiVersion: operations.kubeblocks.io/v1alpha1
kind: OpsRequest
metadata:
name: redis-replication-start-ops
namespace: demo
spec:
# Specifies the name of the Cluster resource that this operation is targeting.
clusterName: redis-replication
type: Start
Modify the cluster spec to resume operation:
-
Set stop: false, or
-
Remove the stop field entirely
kubectl patch cluster redis-replication -n demo --type='json' -p='[ { "op": "remove", "path": "/spec/componentSpecs/0/stop" }, { "op": "remove", "path": "/spec/componentSpecs/1/stop" } ]'
Verifying Cluster Start
To confirm a successful start operation:
-
Check cluster status transition:
kubectl get cluster redis-replication -n demo -w
Example Output:
NAME CLUSTER-DEFINITION TERMINATION-POLICY STATUS AGE redis-replication redis Delete Updating 22m redis-replication redis Delete Running 22m
-
Verify pod recreation:
kubectl get pods -n demo -l app.kubernetes.io/instance=redis-replication
Example Output:
NAME READY STATUS RESTARTS AGE redis-replication-redis-0 1/1 Running 0 2m redis-replication-redis-1 1/1 Running 0 1m
-
Check service endpoints:
kubectl get endpoints redis-replication-redis-redis -n demo
Restarting Cluster
Restart operations provide:
- Pod recreation without full cluster stop
- Component-level granularity
- Minimal service disruption
Use cases:
- Configuration changes requiring restart
- Resource refresh
- Troubleshooting
Using OpsRequest API
Target specific components redis
and redis-sentinel
for restart:
apiVersion: operations.kubeblocks.io/v1alpha1
kind: OpsRequest
metadata:
name: redis-replication-restart-ops
namespace: demo
spec:
clusterName: redis-replication
type: Restart
restart:
- componentName: redis
- componentName: redis-sentinel
Verifying Restart Completion
To verify a successful component restart:
-
Track OpsRequest progress:
kubectl get opsrequest redis-replication-restart-ops -n demo -w
Example Output:
NAME TYPE CLUSTER STATUS PROGRESS AGE redis-replication-restart-ops Restart redis-replication Running 0/2 10s redis-replication-restart-ops Restart redis-replication Running 1/2 65s redis-replication-restart-ops Restart redis-replication Running 2/2 2m5s redis-replication-restart-ops Restart redis-replication Succeed 2/2 2m5s
-
Check pod status:
kubectl get pods -n demo -l app.kubernetes.io/instance=redis-replication
Note: Pods will show new creation timestamps after restart
-
Verify component health:
kbcli cluster describe redis-replication -n demo
Once the operation is complete, the cluster will return to the Running state.
To restart pods for Redis Component only, you can use:
apiVersion: operations.kubeblocks.io/v1alpha1
kind: OpsRequest
metadata:
name: redis-replication-restart-redis
namespace: demo
spec:
clusterName: redis-replication
type: Restart
restart:
- componentName: redis
Summary
In this guide, you learned how to:
- Stop a Redis Replication Cluster to suspend operations while retaining persistent storage.
- Start a stopped cluster to bring it back online.
- Restart specific cluster components to recreate their Pods without stopping the entire cluster.
By managing the lifecycle of your Redis Replication Cluster, you can optimize resource utilization, reduce costs, and maintain flexibility in your Kubernetes environment. KubeBlocks provides a seamless way to perform these operations, ensuring high availability and minimal disruption.