Skip to content
Docs

This guide creates an Amazon ElastiCache for Valkey instance from Kubernetes and mounts its connection details in a Pod. Valkey is compatible with Redis, so Redis clients such as redis-cli work with it.

You describe the cache with one manifest: ValkeyInstance. The platform creates the ElastiCache replication group in the elasticache subnets of your VPC, the security group and security group rules that let Pods reach it, and a Secret with the connection details in both Kubernetes and AWS Secrets Manager. A final snapshot on deletion is turned on for every instance, see EnvironmentConfig.

It is good practice to include the manifest in your application’s Helm chart, so the cache is deployed together with the application that uses it.

Valkey is enabled by default. Your Infralib configuration needs:

Module Flag Default What it does
platform-apis platform-apis.valkey.install true Installs the ValkeyInstance API.
platform-apis platform-apis.postgresql.install true Also renders the shared database EnvironmentConfig that Valkey uses. Keep it true.
crossplane-aws global.createObservers, global.createNamespacedObservers false Installs the ElastiCache and Secrets Manager providers and the elasticache subnet group lookup the instance needs. Set both to true.

For the base modules every platform API needs, see Infralib Requirements.

A ValkeyInstance works with an empty spec. Every field has a default:

apiVersion: database.entigo.com/v1alpha1
kind: ValkeyInstance
metadata:
name: example-valkey
spec: {}

Watch it until READY is True:

Terminal window
kubectl get valkey example-valkey -w
Field Default What it does
instanceType cache.t4g.small ElastiCache node type. Sets memory, compute and network capacity.
engineVersion unset Valkey version, for example '8.2'. ElastiCache uses the latest patch version.
numCacheClusters 2 Nodes in the replication group: one primary plus replicas, 2–6.
deletionProtection true Blocks deletion. Set to false before you delete the instance.
snapshotRetentionLimit 7 Days of automatic snapshots to keep, 0–35. 0 turns automatic backups off.
snapshotWindow 03:00-05:00 Daily snapshot time in UTC. Must not overlap with the maintenance window.
maintenanceWindow sun:05:00-sun:06:00 Weekly maintenance time in UTC, at least 60 minutes.
autoMinorVersionUpgrade true Applies minor engine upgrades in the maintenance window.
parameterGroupName engine default Uses an existing parameter group, for example 'default.valkey8'.
parameterGroupParameters unset Sets individual Valkey parameters, for example notify-keyspace-events: Ex.

For example, a larger instance with three nodes and custom windows:

apiVersion: database.entigo.com/v1alpha1
kind: ValkeyInstance
metadata:
name: example-valkey
spec:
engineVersion: '8.2'
instanceType: 'cache.t4g.small'
numCacheClusters: 3
maintenanceWindow: 'mon:00:00-mon:03:00'
snapshotWindow: '05:00-06:00'
snapshotRetentionLimit: 10
parameterGroupParameters:
notify-keyspace-events: Ex

For every field, see the ValkeyInstance API reference.

The connection details are stored in the Kubernetes Secret and AWS Secrets Manager secret <metadata.name>-credentials. The Secret has the keys PRIMARY_ENDPOINT, READER_ENDPOINT, AUTH_TOKEN, PORT, and credentials.json with all four in one JSON document.

For more information about Secrets in Kubernetes, see Kubernetes documentation.

The simplest way is to load every key as an environment variable:

apiVersion: v1
kind: Pod
metadata:
name: redis
spec:
containers:
- name: redis
image: redis:alpine
command: ['sleep', 'infinity']
envFrom:
- secretRef:
name: example-valkey-credentials

To pick individual keys, or to rename them, use secretKeyRef:

apiVersion: v1
kind: Pod
metadata:
name: redis
spec:
containers:
- name: redis
image: redis:alpine
command: ['sleep', 'infinity']
env:
- name: PRIMARY_ENDPOINT
valueFrom:
secretKeyRef:
name: example-valkey-credentials
key: PRIMARY_ENDPOINT
- name: READER_ENDPOINT
valueFrom:
secretKeyRef:
name: example-valkey-credentials
key: READER_ENDPOINT
- name: AUTH_TOKEN
valueFrom:
secretKeyRef:
name: example-valkey-credentials
key: AUTH_TOKEN
- name: PORT
valueFrom:
secretKeyRef:
name: example-valkey-credentials
key: PORT

If your application reads its configuration from a file, mount credentials.json:

apiVersion: v1
kind: Pod
metadata:
name: redis
spec:
containers:
- name: redis
image: redis:alpine
command: ['sleep', 'infinity']
volumeMounts:
- name: credentials
mountPath: /etc/credentials
readOnly: true
volumes:
- name: credentials
secret:
secretName: example-valkey-credentials
items:
- key: credentials.json
path: credentials.json

The ValkeyInstance shows SYNCED and READY as True:

Terminal window
$ kubectl get valkey
NAME SYNCED READY COMPOSITION AGE
example-valkey True True valkeyinstances.database.entigo.com 20m29s

The Valkey instance appears in the AWS Console:

Terminal window
$ kubectl get secret
NAME TYPE DATA AGE
example-valkey-credentials Opaque 5 22m
$ kubectl get secret example-valkey-credentials -o yaml
apiVersion: v1
kind: Secret
metadata:
annotations:
crossplane.io/composition-resource-name: credentials
name: example-valkey-credentials
namespace: <namespace>
type: Opaque
data:
PRIMARY_ENDPOINT: <base64-encoded-primary-endpoint>
READER_ENDPOINT: <base64-encoded-reader-endpoint>
AUTH_TOKEN: <base64-encoded-auth-token>
PORT: <base64-encoded-port>
credentials.json: <base64-encoded-credentials>

The same details are in AWS Secrets Manager:

With the environment variables mounted, connect over TLS:

Terminal window
$ kubectl get pod
NAME READY STATUS RESTARTS AGE
redis 1/1 Running 0 10m
$ kubectl exec -it redis -- sh
/ env
PRIMARY_ENDPOINT=master.example-valkey.abc123.eun1.cache.amazonaws.com
READER_ENDPOINT=replica.example-valkey.abc123.eun1.cache.amazonaws.com
AUTH_TOKEN=verysecretauthtoken
PORT=6379
/ export REDISCLI_AUTH="$AUTH_TOKEN"
/ redis-cli --tls -h "$PRIMARY_ENDPOINT" -p "$PORT" PING
PONG
/ redis-cli --tls -h "$PRIMARY_ENDPOINT" -p "$PORT" SET testkey "hello"
OK
/ redis-cli --tls -h "$PRIMARY_ENDPOINT" -p "$PORT" GET testkey
"hello"

With credentials.json mounted:

Terminal window
/ cat /etc/credentials/credentials.json
{"AUTH_TOKEN": "verysecretauthtoken", "PORT": "6379", "PRIMARY_ENDPOINT": "master.example-valkey.abc123.eun1.cache.amazonaws.com", "READER_ENDPOINT": "replica.example-valkey.abc123.eun1.cache.amazonaws.com"}
Symptom Cause / fix
no matches for kind "ValkeyInstance" The API is not installed. Check the Prerequisites.
SYNCED is False The platform could not create a cloud resource. kubectl describe valkey <name> shows the error under Conditions and Events.
The instance is not deleted deletionProtection is true by default. Set it to false, apply, then delete.

One Valkey default is not configured on the ValkeyInstance object. It is set once for the whole cluster in the platform-apis EnvironmentConfig, so every instance gets the same protection without developers having to think about it.

Setting Default What it does
valkeyBackupBeforeDeletion true Takes a final snapshot before an instance is deleted, so the data can still be recovered.
tags {} Cloud tags added to every Valkey resource. See Resource Tagging.

When enabled, deleting a ValkeyInstance takes one last snapshot before the instance disappears. That snapshot stays in AWS and can be used to bring the data back later.

Turning this off means a deleted instance is gone for good. Because Valkey is most often used as a cache that can simply be rebuilt, this is a reasonable setting to disable in environments where the contents are not worth keeping.

How many scheduled snapshots are kept, and when they are taken, is set per instance with spec.snapshotRetentionLimit and spec.snapshotWindow, see Optional settings. The cluster-wide backupRetentionPeriod setting applies to PostgreSQL and MariaDB only, not to Valkey.

steps:
...
- name: apps
type: argocd-apps
modules:
...
- name: platform-apis
source: platform-apis
inputs:
platform-apis:
database:
environmentConfig:
valkeyBackupBeforeDeletion: true