Skip to content

Run Valkey (Redis)

This assumes you can already reach your cluster with kubectl (see the kubectl quickstart).

Valkey is an in-memory key/value store for caching, sessions, and queues. It’s the BSD-licensed, Linux Foundation fork of Redis and a drop-in replacement: the same wire protocol and the same clients (redis-py, ioredis, Jedis, go-redis, …) work unchanged. You’ll deploy a single instance in its own namespace, with persistence so its data survives pod restarts.

Create a dedicated namespace:

Terminal window
kubectl create namespace valkey

Deploy Valkey, its storage, and a Service into the namespace:

Terminal window
cat <<'EOF' | kubectl apply -f -
apiVersion: v1
kind: Secret
metadata:
name: valkey
namespace: valkey
stringData:
VALKEY_PASSWORD: change-me
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: valkey
namespace: valkey
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 5Gi
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: valkey
namespace: valkey
spec:
replicas: 1
strategy:
type: Recreate
selector:
matchLabels:
app: valkey
template:
metadata:
labels:
app: valkey
spec:
containers:
- name: valkey
image: valkey/valkey:8
command:
- sh
- -c
- exec valkey-server --requirepass "$VALKEY_PASSWORD" --appendonly yes
env:
- name: VALKEY_PASSWORD
valueFrom:
secretKeyRef:
name: valkey
key: VALKEY_PASSWORD
ports:
- containerPort: 6379
volumeMounts:
- name: data
mountPath: /data
volumes:
- name: data
persistentVolumeClaim:
claimName: valkey
---
apiVersion: v1
kind: Service
metadata:
name: valkey
namespace: valkey
spec:
selector:
app: valkey
ports:
- port: 6379
targetPort: 6379
EOF

This Service is ClusterIP, so the store is only reachable from inside the cluster. On a single-tenant skube cluster that’s the safe default: keep your app and Valkey in the cluster and connect over the Service.

If you need to reach it from outside the cluster:

  • For occasional access, prefer kubectl port-forward -n valkey service/valkey 6379:6379 over a public endpoint. It tunnels through the API server and exposes nothing.
  • Valkey speaks its own TCP protocol, not HTTP, so the Ingress and Gateway guides don’t apply. To expose it for real, enable Valkey’s own TLS.
  • Use a strong password, not change-me, and rotate the secret if it leaks.

Check it’s responding (use the password you set above):

Terminal window
kubectl exec -n valkey deploy/valkey -- valkey-cli -a change-me ping

A PONG response means it’s up. Open an interactive shell:

Terminal window
kubectl exec -n valkey -it deploy/valkey -- valkey-cli -a change-me

From there, the basics, store a value, read it back, and set one that expires:

SET greeting "hello from skube"
GET greeting
SET session:42 active EX 30 # expires in 30 seconds
TTL session:42 # seconds left
DBSIZE # number of keys
DEL greeting

Other workloads in the cluster connect with this URL (<password> is the value from the secret above):

redis://:<password>@valkey.valkey.svc.cluster.local:6379

Delete the namespace to remove everything at once:

Terminal window
kubectl delete namespace valkey

This destroys the stored data along with it.