Skip to content

valkey-statefulset.yaml

Download valkey-statefulset.yaml as it is.

deploy/kubernetes/valkey-statefulset.yaml
# The Valkey the gateway pods share: their cache of what they keep of the devices, and the messages they send each other of a change.
# Nothing in it is kept (everything is rebuilt from Postgres), so it runs with no persistence: a restart is a cold cache and a
# resync, not a loss. One replica is the simple case. For a Valkey that survives the loss of a node, run Sentinel (or use your
# provider's managed Valkey) and give the Deployment its URL (redis-sentinel://, rediss://) in HOURADVANTAGE_CACHE_URL; then drop this
# file from kustomization.yaml. A pod with none refuses to start beside another, and one that cannot reach it reads from Postgres
# until it can.
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: houradvantage-valkey
labels:
app.kubernetes.io/name: houradvantage
app.kubernetes.io/component: valkey
spec:
serviceName: houradvantage-valkey
replicas: 1
selector:
matchLabels:
app.kubernetes.io/name: houradvantage
app.kubernetes.io/component: valkey
template:
metadata:
labels:
app.kubernetes.io/name: houradvantage
app.kubernetes.io/component: valkey
spec:
automountServiceAccountToken: false
securityContext:
runAsNonRoot: true
runAsUser: 999
runAsGroup: 1000
seccompProfile:
type: RuntimeDefault
containers:
- name: valkey
# Pinned by digest (the tag says which version it is).
image: valkey/valkey:8.1-alpine@sha256:2602ace2be6569bc2bbb06f873776516ab9089821525be34f4305c67eb9db02a
imagePullPolicy: IfNotPresent
args: ["valkey-server", "--save", "", "--appendonly", "no"]
ports:
- name: valkey
containerPort: 6379
securityContext:
allowPrivilegeEscalation: false
readOnlyRootFilesystem: true
capabilities: { drop: [ALL] }
resources:
requests: { cpu: 100m, memory: 256Mi }
limits: { memory: 1Gi }
readinessProbe:
exec: { command: ["valkey-cli", "ping"] }
periodSeconds: 5
timeoutSeconds: 3
livenessProbe:
exec: { command: ["valkey-cli", "ping"] }
periodSeconds: 10
timeoutSeconds: 3
failureThreshold: 6
volumeMounts:
- { name: data, mountPath: /data }
volumes:
- name: data
emptyDir: {}
---
# The pods reach it by this name (headless: the one pod's address).
apiVersion: v1
kind: Service
metadata:
name: houradvantage-valkey
labels:
app.kubernetes.io/name: houradvantage
app.kubernetes.io/component: valkey
spec:
clusterIP: None
selector:
app.kubernetes.io/name: houradvantage
app.kubernetes.io/component: valkey
ports:
- { name: valkey, port: 6379, targetPort: valkey }
---
# Only the gateway pods reach it.
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: houradvantage-valkey
labels:
app.kubernetes.io/component: valkey
spec:
podSelector:
matchLabels:
app.kubernetes.io/name: houradvantage
app.kubernetes.io/component: valkey
policyTypes: [Ingress, Egress]
ingress:
- from:
- podSelector:
matchLabels:
app.kubernetes.io/name: houradvantage
app.kubernetes.io/component: gateway
ports:
- { protocol: TCP, port: 6379 }
egress: []