Using a9s Redis
This chapter describes how to interact with a9s Redis using the Kubernetes API.
Pre-requisite
-
Data Service Custom Resources
Before using the a9s Redis service, ensure the necessary custom resources are present in your Kubernetes cluster. Use the following commands to verify their existence:
kubectl get redisinstances.anynines.com
kubectl get servicebindings.anynines.com
kubectl get backups.anynines.com
kubectl get restores.anynines.comIf you encounter the following error:
error: the server doesn't have a resource type "<resource-name>"This indicates that the corresponding resource is missing. To resolve this, you can follow the instructions here or reach out to a platform operator for assistance.
Create a Redis Service Instance
To provision a Redis Service Instance, simply create a Redis Kubernetes Object by applying a Service Instance Claim.
Replace the placeholder values denoted by < > in the provided yaml file. Kindly select one of the supported values for
spec.service and spec.plan. The supported values for service and plan can be found here.
Optional: To set up a clustered Redis with small specifications, apply the yaml manifest provided in the
Example tab below. Feel free to modify the fields in order to create a different type of Redis database tailored
to your requirements.
- Template
- Example
apiVersion: anynines.com/v1
kind: RedisInstance
metadata:
name: <name>
namespace: <namespace>
spec:
service: <service-name>
plan: <plan-name>
compositionRef:
name: a9s-redis
apiVersion: anynines.com/v1
kind: RedisInstance
metadata:
name: example-a9s-redis
namespace: default
spec:
service: a9s-redis7
plan: redis-cluster-small-ssl
compositionRef:
name: a9s-redis
Applying this Kubernetes yaml manifest is as straightforward as working with any default Kubernetes resource.
kubectl apply -f <filename.yaml>
After applying the manifest, please allow some time for the remote resources to be deployed. If you've deployed the provided example, you should observe an output similar to the following:
kubectl get redisinstances.anynines.com
NAME SYNCED READY CONNECTION-SECRET AGE
example-a9s-redis True True 9m
You can also obtain additional information about the status of Redis Objects using the following command:
kubectl describe redisinstances.anynines.com
Name: example-a9s-redis
Namespace: default
...
Status:
Conditions:
Last Transition Time: 2023-08-07T09:57:49Z
Reason: ReconcileSuccess
Status: True
Type: Synced
Last Transition Time: 2023-08-07T10:04:11Z
Reason: Available
Status: True
Type: Ready
Managed:
Conditions:
Last Transition Time: 2023-08-07T09:57:50Z
Reason: ReconcileSuccess
Status: True
Type: Synced
Last Transition Time: 2023-08-07T10:04:00Z
Reason: Available
Status: True
Type: Ready
Created At: 2023-08-07T09:57:50.556Z
Provisioned At: 2023-08-07T10:03:40.445Z
State: provisioned
Updated At: 2023-08-07T10:03:40.500Z
No Redis pod is running locally in the consumer cluster.
Behind the scenes the Custom Resources synced up to the a9s Data Service platform which ensures the database is provisioned and healthy. The status information reflecting the database status synced back to the tenant cluster to signify service readiness.
Bind an Application to a Redis Database
The ServiceBinding Custom Resource is all that you need to quickly start using the database. To target a specific
Redis instance, set the spec.instanceRef field.
Optional: If you've followed the example from the previous step, where we create a Redis Kubernetes Object, you can now proceed to apply the yaml manifest provided in the Example tab below. This will bind the previously created Redis instance.
- Template
- Example
apiVersion: anynines.com/v1
kind: ServiceBinding
metadata:
name: <name>
namespace: <namespace>
spec:
instanceRef: <redis-instance-name>
serviceInstanceType: redis
compositionRef:
name: a9s-servicebinding
apiVersion: anynines.com/v1
kind: ServiceBinding
metadata:
name: example-a9s-redis
namespace: default
spec:
instanceRef: example-a9s-redis
serviceInstanceType: redis
compositionRef:
name: a9s-servicebinding
After a few seconds, the ServiceBinding will be ready. You can then access the credentials and network details required
for database connectivity by describing the Secret that was automatically created. The Data Service automation generates
a Secret, named {service-binding-name}-creds, in the same namespace as the ServiceBinding.
For instance, if you have already applied the provided examples, upon the successful deployment of the ServiceBinding, you can access credentials and network details by describing the corresponding Kubernetes Secret using the following command:
kubectl get secret example-a9s-redis-creds -o yaml
apiVersion: v1
data:
cacrt: <base64 encoded value>
host: <base64 encoded value>
hosts: <base64 encoded value>
load_balanced_host: <base64 encoded value>
redis: <base64-encoded map with keys for "password," "port," and "username.">
...
Please note that the Kubernetes Secret described in the previous code block is for the provided example, which uses a9s Redis version 7. For earlier versions of a9s Redis, the produced Kubernetes Secret will have a different structure, as described in the following code block.
apiVersion: v1
data:
cacrt: <base64 encoded value>
host: <base64 encoded value>
hosts: <base64 encoded value>
load_balanced_host: <base64 encoded value>
password: <base64 encoded value>
port: <base64 encoded value>
sentinel_master_name: <base64 encoded value>
sentinel_port: <base64 encoded value>
...
Backup a Redis Database
The a9s platform provides an easy way to create backups and restore if needed. You can use the Kubernetes Custom
Resource Backup from the API group anynines.com to create backups of Data Service Instances. To do this, simply
target the specific Data Service Instance you want to back up, as shown in the following yaml manifest:
- Template
- Example
apiVersion: anynines.com/v1
kind: Backup
metadata:
name: <name>
namespace: <namespace>
spec:
instanceRef: <redis-instance-name>
serviceInstanceType: redis
compositionRef:
name: a9s-backup
apiVersion: anynines.com/v1
kind: Backup
metadata:
name: example-a9s-redis
namespace: default
spec:
instanceRef: example-a9s-redis
serviceInstanceType: redis
compositionRef:
name: a9s-backup
And then apply the yaml manifest:
kubectl apply -f <filename.yaml>
You can inspect the status of the backup to determine when it is complete, similar to how we did it for the Redis instance, using the following command:
kubectl get backup.anynines.com -o yaml
You can observe the status transition from queued to done as the backup process completes.
apiVersion: anynines.com/v1
kind: Backup
...
status:
...
managed:
...
status: queued
apiVersion: anynines.com/v1
kind: Backup
...
status:
...
managed:
...
size: 272
status: done
Restore a Redis Database Backup
To restore a backup, you must apply a Restore from the API group anynines.com, targeting an existing Redis Backup.
Below is the yaml file you can utilize for this purpose:
- Template
- Example
apiVersion: anynines.com/v1
kind: Restore
metadata:
name: <name>
namespace: <namespace>
spec:
backupRef: <backup-name>
serviceInstanceType: redis
compositionRef:
name: a9s-restore
apiVersion: anynines.com/v1
kind: Restore
metadata:
name: example-a9s-redis
namespace: default
spec:
backupRef: example-a9s-redis
serviceInstanceType: redis
compositionRef:
name: a9s-restore
And then apply the yaml manifest:
kubectl apply -f <filename.yaml>
You can observe the state transition from queued to running and done as the restore completes.
kubectl get restore.anynines.com -o yaml
apiVersion: v1
items:
- apiVersion: anynines.com/v1
kind: Restore
...
status:
...
managed:
...
state: queued
apiVersion: v1
items:
- apiVersion: anynines.com/v1
kind: Restore
...
status:
...
managed:
...
state: done
Delete a9s Kubernetes Custom Resources
Delete the Custom Resources using the kubectl delete command. Replace <resource-type> with the actual resource type
and <resource-name> with the name of the Custom Resource you want to delete.
kubectl delete <resource-type> <resource-name>
Alternatively, you can use the following command to delete Custom Resources by specifying the filename of the yaml manifest:
kubectl delete -f <filename.yaml>
Coming soon
a9s Redis offers a range of features that will soon be supported for a9s Redis through Kubernetes integration. See the following table for a summary of these upcoming features.
| Feature | Description |
|---|---|
| Metrics | Monitor, collect, and manage metrics for comprehensive insights into the service. |
| Logging | Stream log data to a third-party service for centralized log management and analysis. |
| Disk Usage Alerts | Create disk usage alerts to be notified when ephemeral or persistent disk usage exceeds a certain threshold. |
| Service Management | Easily view service listings and initiate Data Service restarts when necessary. |
| Redis Configuration | Customize your Redis service with options like eviction policies, TTL settings, Lua script limits, max clients, memory policies, and more. For a9s Redis 6+ with SSL, configure TLS for enhanced security. |
| RDB Persistence | Configure RDB (Redis DataBase) persistence to take scheduled snapshots of the Redis database and store them on disk. |
| Maxmemory Policy | Configure key eviction when maxmemory is reached. Options include removing least recently used keys with/without TTL, least frequently used keys with/without TTL, shortest TTL keys, or preventing eviction with an error at the memory limit. |
| HA Cluster with Redis Sentinel | Redis Sentinel ensures high availability with automatic failover and cluster monitoring. Key settings include min-slaves-max-lag, down-after-milliseconds, and failover-timeout for cluster behavior customization. |