feat(k8s): move Valkey to standalone StatefulSet
Previously Valkey ran as a sidecar container in the main deployment, causing it to restart every time the web app deployed. This resulted in connection errors and cache loss during deployments. Changes: - Created valkey-statefulset.yaml with StatefulSet resource (1 replica) - Created valkey-service.yaml with headless service - Removed Valkey sidecar container from deployment.yaml - Updated REDIS_HOST from 127.0.0.1 to valkey-0.valkey.towerops.svc.cluster.local - Added new resources to kustomization.yaml Benefits: - Valkey persists across web app deployments - No connection errors during rolling updates - Cache data preserved - Independent scaling and resource management
This commit is contained in:
parent
dcb875ea8c
commit
bac286ee1b
4 changed files with 83 additions and 43 deletions
|
|
@ -84,9 +84,9 @@ spec:
|
|||
secretKeyRef:
|
||||
name: towerops-secrets
|
||||
key: SECRET_KEY_BASE
|
||||
# Redis connection to Valkey sidecar container (localhost because same pod)
|
||||
# Redis connection to standalone Valkey StatefulSet
|
||||
- name: REDIS_HOST
|
||||
value: "127.0.0.1"
|
||||
value: "valkey-0.valkey.towerops.svc.cluster.local"
|
||||
- name: REDIS_PORT
|
||||
value: "6379"
|
||||
envFrom:
|
||||
|
|
@ -124,44 +124,3 @@ spec:
|
|||
timeoutSeconds: 2
|
||||
successThreshold: 1
|
||||
failureThreshold: 2
|
||||
- name: valkey
|
||||
image: valkey/valkey:8.0-alpine
|
||||
imagePullPolicy: IfNotPresent
|
||||
securityContext:
|
||||
allowPrivilegeEscalation: false
|
||||
runAsNonRoot: true
|
||||
runAsUser: 999
|
||||
capabilities:
|
||||
drop:
|
||||
- ALL
|
||||
seccompProfile:
|
||||
type: RuntimeDefault
|
||||
ports:
|
||||
- containerPort: 6379
|
||||
name: valkey
|
||||
resources:
|
||||
requests:
|
||||
memory: "128Mi"
|
||||
cpu: "50m"
|
||||
limits:
|
||||
memory: "256Mi"
|
||||
cpu: "200m"
|
||||
livenessProbe:
|
||||
exec:
|
||||
command:
|
||||
- valkey-cli
|
||||
- ping
|
||||
initialDelaySeconds: 10
|
||||
periodSeconds: 10
|
||||
timeoutSeconds: 2
|
||||
failureThreshold: 3
|
||||
readinessProbe:
|
||||
exec:
|
||||
command:
|
||||
- valkey-cli
|
||||
- ping
|
||||
initialDelaySeconds: 5
|
||||
periodSeconds: 5
|
||||
timeoutSeconds: 2
|
||||
successThreshold: 1
|
||||
failureThreshold: 2
|
||||
|
|
|
|||
|
|
@ -6,6 +6,8 @@ resources:
|
|||
- deployment.yaml
|
||||
- service.yaml
|
||||
- service-headless.yaml
|
||||
- valkey-statefulset.yaml
|
||||
- valkey-service.yaml
|
||||
- certificate.yaml
|
||||
- ingressroute.yaml
|
||||
- poddisruptionbudget.yaml
|
||||
|
|
|
|||
14
k8s/valkey-service.yaml
Normal file
14
k8s/valkey-service.yaml
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
---
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: valkey
|
||||
namespace: towerops
|
||||
spec:
|
||||
clusterIP: None # Headless service for StatefulSet
|
||||
selector:
|
||||
app: valkey
|
||||
ports:
|
||||
- port: 6379
|
||||
targetPort: 6379
|
||||
name: valkey
|
||||
65
k8s/valkey-statefulset.yaml
Normal file
65
k8s/valkey-statefulset.yaml
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
---
|
||||
apiVersion: apps/v1
|
||||
kind: StatefulSet
|
||||
metadata:
|
||||
name: valkey
|
||||
namespace: towerops
|
||||
spec:
|
||||
serviceName: valkey
|
||||
replicas: 1
|
||||
selector:
|
||||
matchLabels:
|
||||
app: valkey
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: valkey
|
||||
spec:
|
||||
securityContext:
|
||||
runAsNonRoot: true
|
||||
runAsUser: 999
|
||||
fsGroup: 999
|
||||
seccompProfile:
|
||||
type: RuntimeDefault
|
||||
containers:
|
||||
- name: valkey
|
||||
image: valkey/valkey:8.0-alpine
|
||||
imagePullPolicy: IfNotPresent
|
||||
securityContext:
|
||||
allowPrivilegeEscalation: false
|
||||
runAsNonRoot: true
|
||||
runAsUser: 999
|
||||
capabilities:
|
||||
drop:
|
||||
- ALL
|
||||
seccompProfile:
|
||||
type: RuntimeDefault
|
||||
ports:
|
||||
- containerPort: 6379
|
||||
name: valkey
|
||||
resources:
|
||||
requests:
|
||||
memory: "128Mi"
|
||||
cpu: "50m"
|
||||
limits:
|
||||
memory: "512Mi"
|
||||
cpu: "200m"
|
||||
livenessProbe:
|
||||
exec:
|
||||
command:
|
||||
- valkey-cli
|
||||
- ping
|
||||
initialDelaySeconds: 10
|
||||
periodSeconds: 10
|
||||
timeoutSeconds: 2
|
||||
failureThreshold: 3
|
||||
readinessProbe:
|
||||
exec:
|
||||
command:
|
||||
- valkey-cli
|
||||
- ping
|
||||
initialDelaySeconds: 5
|
||||
periodSeconds: 5
|
||||
timeoutSeconds: 2
|
||||
successThreshold: 1
|
||||
failureThreshold: 2
|
||||
Loading…
Add table
Reference in a new issue