app/toot: start implementing redis

This commit is contained in:
q3k 2019-04-04 16:53:53 +02:00
parent 242152f65e
commit 6916f7e244
2 changed files with 100 additions and 0 deletions

View file

@ -4,6 +4,7 @@
local kube = import "../../kube/kube.libsonnet";
local postgres = import "../../kube/postgres.libsonnet";
local redis = import "../../kube/redis.libsonnet";
{
local app = self,
@ -32,4 +33,11 @@ local postgres = import "../../kube/postgres.libsonnet";
password: { secretKeyRef: { name: "mastodon", key: "postgres_password" } },
},
},
redis: redis {
cfg+: {
namespace: cfg.namespace,
appName: "toot",
},
},
}

92
kube/redis.libsonnet Normal file
View file

@ -0,0 +1,92 @@
# Redis on Kubernetes.
# For now, single instance (no redis-sentinel or redis-cluster)
local kube = import "kube.libsonnet";
{
local redis = self,
local cfg = redis.cfg,
cfg:: {
namespace: error "namespace must be set",
appName: error "app name must be set",
storageClassName: "waw-hdd-redundant-1",
prefix: "", # if set, should be 'foo-'
image: "redis:5.0.4-alpine",
resources: {
requests: {
cpu: "50m",
memory: "64Mi",
},
limits: {
cpu: "500m",
memory: "256Mi",
},
},
},
makeName(suffix):: cfg.prefix + suffix,
metadata:: {
namespace: cfg.namespace,
labels: {
"app.kubernetes.io/name": cfg.appName,
"app.kubernetes.io/managed-by": "kubecfg",
"app.kubernetes.io/component": "redis",
},
},
volumeClaim: kube.PersistentVolumeClaim(redis.makeName("redis")) {
metadata+: redis.metadata,
spec+: {
storageClassName: cfg.storageClassName,
accessModes: [ "ReadWriteOnce" ],
resources: {
requests: {
storage: "5Gi",
},
},
},
},
deployment: kube.Deployment(redis.makeName("redis")) {
metadata+: redis.metadata,
spec+: {
replicas: 1,
template+: {
spec+: {
volumes_: {
data: kube.PersistentVolumeClaimVolume(redis.volumeClaim),
},
containers_: {
redis: kube.Container(redis.makeName("redis")) {
image: cfg.image,
args: [
"redis-server",
"--appendonly", "yes",
],
ports_: {
client: { containerPort: 6379 },
},
volumeMounts_: {
data: { mountPath: "/data" },
},
resources: cfg.resources,
},
},
},
},
},
},
svc: kube.Service(redis.makeName("redis")) {
metadata+: redis.metadata,
target_pod:: redis.deployment.spec.template,
spec+: {
ports: [
{ name: "client", port: 6379, targetPort: 6379, protocol: "TCP" },
],
type: "ClusterIP",
},
},
}