This repository has been archived by the owner on Oct 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 55
/
memcached-persistent.yaml
92 lines (92 loc) · 2.75 KB
/
memcached-persistent.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
apiVersion: v1
kind: Service
metadata:
name: pmem-memcached
namespace: default
spec:
ports:
- name: db
port: 11211
protocol: TCP
targetPort: db
selector:
app.kubernetes.io/kind: memcached
app.kubernetes.io/name: pmem-memcached
type: ClusterIP
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: pmem-memcached
namespace: default
spec:
replicas: 1
selector:
matchLabels:
app.kubernetes.io/kind: memcached
app.kubernetes.io/name: pmem-memcached
serviceName: pmem-memcached
template:
metadata:
labels:
app.kubernetes.io/kind: memcached
app.kubernetes.io/name: pmem-memcached
spec:
initContainers:
- name: data-volume-init
# This first creates a file that is as large as root can make it (larger
# than a normal user because of reserved blocks). Size is rounded down to
# MiB because that is what memcached expects and 50 MiB are substracted
# for filesystem overhead and the memcached state files.
#
# Then it changes the ownership of the data volume so that the memcached user
# can read and write files there. The exact UID varies between
# memcached image versions (therefore we cannot use Kubernetes to change
# the ownership for us as that relies on a numeric value), but the "memcache"
# name is the same, so by running in the same image as memcached we can set
# the owner by name.
command:
- sh
- -c
- |
fallocate --length=$(( $(stat --file-system --format='%b * %s / 1024 / 1024 - 50' /data) ))MiB /data/memcached-memory-file &&
chown -R memcache /data
image: memcached:1.5.22
securityContext:
privileged: true
runAsUser: 0
volumeMounts:
- mountPath: /data
name: memcached-data-volume
containers:
- name: memcached
image: memcached:1.5.22
command:
- sh
- -c
- |
set -x
memcached --memory-limit=$(( $(stat --format='%s / 1024 / 1024' /data/memcached-memory-file) )) --memory-file=/data/memcached-memory-file $(MEMCACHED_ARGS) &
pid=$$!
trap 'kill -USR1 $$pid; wait $$pid' TERM
wait $$pid
ports:
- containerPort: 11211
name: db
protocol: TCP
volumeMounts:
- mountPath: /data
name: memcached-data-volume
env:
- name: MEMCACHED_ARGS
value:
terminationGracePeriodSeconds: 30
volumeClaimTemplates:
- metadata:
name: memcached-data-volume
spec:
accessModes: [ "ReadWriteOnce" ]
storageClassName: pmem-csi-sc-ext4
resources:
requests:
storage: 200Mi