Skip to main content

Redis

Redis is a powerful open-source tool for storing data structures, used as a database, cache, and message broker. Its high speed and performance, along with support for various data structures, make it the best choice for managing applications and caching frequently accessed data.

In the Arvancloud Cloud Container, you can set up a Redis cluster or a single Redis node using operators. This operator uses version 0.17.0 of the Opstree project.

Setting Up a Single-Node Redis​

Save the following file with a name of your choice, such as redis-standalone.yaml:

apiVersion: redis.redis.opstreelabs.in/v1beta2
kind: Redis
metadata:
name: redis
labels:
app.kubernetes.io/name: redis
spec:
kubernetesConfig:
image: "quay.io/opstree/redis:v7.0.12"
imagePullPolicy: "IfNotPresent"

redisExporter:
enabled: false
image: "quay.io/opstree/redis-exporter:v1.44.0"
imagePullPolicy: "IfNotPresent"
storage:
volumeClaimTemplate:
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
podSecurityContext:
fsGroup: 1000
runAsUser: 1000

Then run the following command to deploy it:

kubectl apply -f redis-standalone.yaml -n [namespace]

Replace [namespace] with your project's name in the Arvancloud Cloud Container.

Setting Up a Redis Cluster​

Save the following file with a name of your choice, such as redis-cluster.yaml:

apiVersion: redis.redis.opstreelabs.in/v1beta2
kind: RedisCluster
metadata:
name: redis-cluster
labels:
app.kubernetes.io/name: redis-cluster
spec:
clusterSize: 3
persistenceEnabled: true
clusterVersion: v7
redisLeader:
replicas: 3
redisFollower:
replicas: 3
redisExporter:
enabled: false
image: "quay.io/opstree/redis-exporter:v1.44.0"
imagePullPolicy: "IfNotPresent"
kubernetesConfig:
image: "quay.io/opstree/redis:v7.0.12"
imagePullPolicy: "IfNotPresent"
storage:
nodeConfVolume: true
nodeConfVolumeClaimTemplate:
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
volumeClaimTemplate:
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
podSecurityContext:
fsGroup: 1000
runAsUser: 1000

Then run the following command to deploy it:

kubectl apply -f redis-cluster.yaml -n [namespace]

Replace [namespace] with your project's name in the Arvancloud Cloud Container.

Setting Up a Multi-Zone Redis Cluster​

Save the following file with a name of your choice, such as redis-cluster.yaml:

apiVersion: redis.redis.opstreelabs.in/v1beta2
kind: RedisCluster
metadata:
name: redis-cluster
labels:
app.kubernetes.io/name: redis-cluster
spec:
clusterSize: 3
persistenceEnabled: true
clusterVersion: v7
redisLeader:
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: "topology.kubernetes.io/zone"
operator: In
values:
- "simin"
- "forough"
- "bamdad"
podAntiAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchLabels:
app: redis-cluster
topologyKey: "topology.kubernetes.io/zone"
replicas: 3
redisFollower:
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: "topology.kubernetes.io/zone"
operator: In
values:
- "simin"
- "forough"
- "bamdad"
podAntiAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchLabels:
app: redis-cluster
topologyKey: "topology.kubernetes.io/zone"
replicas: 3
redisExporter:
enabled: false
image: "quay.io/opstree/redis-exporter:v1.44.0"
imagePullPolicy: "IfNotPresent"
kubernetesConfig:
image: "quay.io/opstree/redis:v7.0.12"
imagePullPolicy: "IfNotPresent"
storage:
nodeConfVolume: true
nodeConfVolumeClaimTemplate:
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
volumeClaimTemplate:
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
podSecurityContext:
fsGroup: 1000
runAsUser: 1000

Then run the following command to deploy it:

kubectl apply -f redis-cluster.yaml -n [namespace]

Replace [namespace] with your project's name in the Arvancloud Cloud Container.

This part of the manifest is written to distribute the redisLeader nodes among 3 zones: Simin, Forough, and Bamdad:

redisLeader:
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: "topology.kubernetes.io/zone"
operator: In
values:
- "simin"
- "forough"
- "bamdad"

Also, in this part, podAntiAffinity keeps Pods from being placed in the same zone, so each node sits in one zone:

podAntiAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchLabels:
app: redis-cluster
topologyKey: "topology.kubernetes.io/zone"

This part of the manifest is written to distribute the redisFollower nodes among 3 zones: Simin, Forough, and Bamdad:

redisFollower:
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: "topology.kubernetes.io/zone"
operator: In
values:
- "simin"
- "forough"
- "bamdad"

Also, in this part, podAntiAffinity keeps follower Pods from being placed in the same zone, so each node sits in one zone:

podAntiAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchLabels:
app: redis-cluster
topologyKey: "topology.kubernetes.io/zone"

For more details and examples, see the Redis operator documentation.