From d3faa5e5a23a4d0357cdeac31f57d1bebbcab63b Mon Sep 17 00:00:00 2001 From: Alex Date: Fri, 29 Jul 2022 19:55:05 +0200 Subject: [PATCH] Add charts templates for k8s config Add in prod config libcluster: config :libcluster, topologies: [ default: [ strategy: Cluster.Strategy.Kubernetes, config: [ mode: :dns, kubernetes_node_basename: "claper", kubernetes_selector: "app=claper", kubernetes_namespace: "default", polling_interval: 10_000 ] ] ] --- charts/claper/Chart.yaml | 5 ++++ charts/claper/templates/_env.yaml | 31 ++++++++++++++++++++ charts/claper/templates/autoscaling.yaml | 18 ++++++++++++ charts/claper/templates/deployment.yaml | 37 ++++++++++++++++++++++++ charts/claper/templates/headless.yaml | 13 +++++++++ charts/claper/templates/ingress.yaml | 23 +++++++++++++++ charts/claper/templates/rbac.yaml | 29 +++++++++++++++++++ charts/claper/templates/service.yaml | 17 +++++++++++ 8 files changed, 173 insertions(+) create mode 100644 charts/claper/Chart.yaml create mode 100644 charts/claper/templates/_env.yaml create mode 100644 charts/claper/templates/autoscaling.yaml create mode 100644 charts/claper/templates/deployment.yaml create mode 100644 charts/claper/templates/headless.yaml create mode 100644 charts/claper/templates/ingress.yaml create mode 100644 charts/claper/templates/rbac.yaml create mode 100644 charts/claper/templates/service.yaml diff --git a/charts/claper/Chart.yaml b/charts/claper/Chart.yaml new file mode 100644 index 0000000..c5bfa34 --- /dev/null +++ b/charts/claper/Chart.yaml @@ -0,0 +1,5 @@ +apiVersion: v2 +appVersion: 1.0.0 +description: Claper app +name: claper +version: 1.0.0 diff --git a/charts/claper/templates/_env.yaml b/charts/claper/templates/_env.yaml new file mode 100644 index 0000000..8ac902c --- /dev/null +++ b/charts/claper/templates/_env.yaml @@ -0,0 +1,31 @@ +{{- define "env" -}} +- name: SECRET_KEY_BASE + valueFrom: + secretKeyRef: + name: claper-secret + key: secret-key-base +- name: POD_IP + valueFrom: + fieldRef: + fieldPath: status.podIP +- name: NAMESPACE + valueFrom: + fieldRef: + fieldPath: metadata.namespace +- name: ENDPOINT_HOST + value: claper.co +- name: DATABASE_URL + value: postgresql://claper:claper@10.0.0.6:6432/claper +- name: AWS_ACCESS_KEY_ID + value: XXX +- name: AWS_PRES_BUCKET + value: XXX +- name: POOL_SIZE + value: "20" +- name: AWS_REGION + value: eu-west-3 +- name: AWS_SECRET_ACCESS_KEY + value: XXX +- name: PRESENTATION_STORAGE + value: s3 +{{- end -}} diff --git a/charts/claper/templates/autoscaling.yaml b/charts/claper/templates/autoscaling.yaml new file mode 100644 index 0000000..c9e5cd1 --- /dev/null +++ b/charts/claper/templates/autoscaling.yaml @@ -0,0 +1,18 @@ +apiVersion: autoscaling/v2beta2 +kind: HorizontalPodAutoscaler +metadata: + name: claper-hpa +spec: + maxReplicas: 5 + minReplicas: 1 + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: claper-app + metrics: + - type: Resource + resource: + name: cpu + target: + type: Utilization + averageUtilization: 50 \ No newline at end of file diff --git a/charts/claper/templates/deployment.yaml b/charts/claper/templates/deployment.yaml new file mode 100644 index 0000000..256519a --- /dev/null +++ b/charts/claper/templates/deployment.yaml @@ -0,0 +1,37 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: claper-app + labels: + app: claper +spec: + replicas: 1 + selector: + matchLabels: + app: claper + template: + metadata: + labels: + app: claper + spec: + serviceAccountName: sa-claper + containers: + - name: claper + image: ghcr.io/claperco/claper:latest + imagePullPolicy: Always + resources: + requests: + cpu: "300m" + livenessProbe: + httpGet: + path: / + port: 4000 + initialDelaySeconds: 60 + periodSeconds: 20 + ports: + - containerPort: 4000 + - name: epmd + containerPort: 4369 + protocol: TCP + env: +{{ include "env" . | indent 10 }} diff --git a/charts/claper/templates/headless.yaml b/charts/claper/templates/headless.yaml new file mode 100644 index 0000000..36be1f5 --- /dev/null +++ b/charts/claper/templates/headless.yaml @@ -0,0 +1,13 @@ +apiVersion: v1 +kind: Service +metadata: + name: claper-svc-headless +spec: + ports: + - port: 4369 + targetPort: epmd + protocol: TCP + name: epmd + selector: + app: claper + clusterIP: None \ No newline at end of file diff --git a/charts/claper/templates/ingress.yaml b/charts/claper/templates/ingress.yaml new file mode 100644 index 0000000..04d2c72 --- /dev/null +++ b/charts/claper/templates/ingress.yaml @@ -0,0 +1,23 @@ +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: claper-ingress + annotations: + kubernetes.io/ingress.class: nginx + cert-manager.io/cluster-issuer: letsencrypt-prod +spec: + tls: + - hosts: + - claper.co + secretName: claper-tls + rules: + - host: claper.co + http: + paths: + - pathType: Prefix + path: "/" + backend: + service: + name: claper-svc + port: + number: 80 diff --git a/charts/claper/templates/rbac.yaml b/charts/claper/templates/rbac.yaml new file mode 100644 index 0000000..c74e378 --- /dev/null +++ b/charts/claper/templates/rbac.yaml @@ -0,0 +1,29 @@ +apiVersion: v1 +kind: ServiceAccount +metadata: + name: sa-claper +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: Role +metadata: + name: role-claper +rules: + - apiGroups: + - "" + resources: + - endpoints + verbs: + - list + - get +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: RoleBinding +metadata: + name: rb-claper +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: Role + name: role-claper +subjects: + - kind: ServiceAccount + name: sa-claper \ No newline at end of file diff --git a/charts/claper/templates/service.yaml b/charts/claper/templates/service.yaml new file mode 100644 index 0000000..a4afaa6 --- /dev/null +++ b/charts/claper/templates/service.yaml @@ -0,0 +1,17 @@ +apiVersion: v1 +kind: Service +metadata: + name: claper-svc + labels: + app: claper +spec: + type: ClusterIP + ports: + - name: cowboy + port: 80 + targetPort: 4000 + - port: 4369 + name: epmd + targetPort: 4369 + selector: + app: claper \ No newline at end of file