From c9df1812566e37347a4b29c5894aea7ea4d218a4 Mon Sep 17 00:00:00 2001
From: Remy Moll <me@moll.re>
Date: Thu, 1 Aug 2024 18:00:49 +0200
Subject: [PATCH] deployment incluing memcached

---
 README.md                    | 12 ++++++++++++
 deployment.yaml              |  5 +++++
 kustomization.yaml           |  4 +++-
 memcached/deployment.yaml    | 22 ++++++++++++++++++++++
 memcached/kustomization.yaml | 13 +++++++++++++
 memcached/service.yaml       | 11 +++++++++++
 6 files changed, 66 insertions(+), 1 deletion(-)
 create mode 100644 memcached/deployment.yaml
 create mode 100644 memcached/kustomization.yaml
 create mode 100644 memcached/service.yaml

diff --git a/README.md b/README.md
index 6fd5e57..efe3183 100644
--- a/README.md
+++ b/README.md
@@ -15,11 +15,23 @@ Before deploying the backend application, ensure that you have the following pre
 
 ## Deployment Steps
 
+### Initial deployment
 To deploy the backend application, follow these steps:
 
 1. Clone this repository: `git clone https://github.com/your-repo.git`
 1. Apply the kustomization: `kubectl apply -k .`
 
+### Rolling updates
+Since the deployment uses the `latest` tag for the backend application, we simply need to trigger a rolling update which will pull the latest image from the registry. To do this, run the following command:
+
+```bash
+kubectl -n anyway-backend rollout restart deployment/nav-backend
+```
+
+
 ## Configuration
 
 The kustomization allows for easy configuration of the backend application. To customize the deployment, modify the `kustomization.yaml` file.
+
+### Memcached
+The backend application requires a memcached instance. By default, the kustomization deploys this instance, as configured under `memcached/`. To disable this, comment out the `memcached` overlay in the `kustomization.yaml` file.
\ No newline at end of file
diff --git a/deployment.yaml b/deployment.yaml
index aabc6fa..acf5f66 100644
--- a/deployment.yaml
+++ b/deployment.yaml
@@ -14,7 +14,10 @@ spec:
     spec:
       containers:
       - name: worker
+        securityContext:
+          allowPrivilegeEscalation: false
         image: backend-image
+        imagePullPolicy: Always
         ports:
         - containerPort: 8000
         env:
@@ -22,6 +25,8 @@ spec:
           value: "3"
         - name: OSM_CACHE_DIR
           value: "/osm-cache"
+        - name: MEMCACHED_HOST_PATH
+          value: "memcached:11211"
         volumeMounts:
         - name: osm-cache
           mountPath: /osm-cache
diff --git a/kustomization.yaml b/kustomization.yaml
index 7707d1d..79981e9 100644
--- a/kustomization.yaml
+++ b/kustomization.yaml
@@ -9,8 +9,10 @@ resources:
   - deployment.yaml
   - service.yaml
   - ingress.yaml
+  - memcached/
+
 
 images:
   - name: backend-image
     newName: git.kluster.moll.re/anydev/anyway-backend
-    newTag: latest
\ No newline at end of file
+    newTag: latest
diff --git a/memcached/deployment.yaml b/memcached/deployment.yaml
new file mode 100644
index 0000000..a6d0690
--- /dev/null
+++ b/memcached/deployment.yaml
@@ -0,0 +1,22 @@
+apiVersion: apps/v1
+kind: Deployment
+metadata:
+  name: memcached
+spec:
+  replicas: 1
+  selector:
+    matchLabels:
+      app: memcached
+  template:
+    metadata:
+      labels:
+        app: memcached
+    spec:
+      containers:
+      - name: memcached
+        securityContext:
+          allowPrivilegeEscalation: false
+        image: memcached
+        imagePullPolicy: IfNotPresent
+        ports:
+        - containerPort: 11211
\ No newline at end of file
diff --git a/memcached/kustomization.yaml b/memcached/kustomization.yaml
new file mode 100644
index 0000000..afdfdb6
--- /dev/null
+++ b/memcached/kustomization.yaml
@@ -0,0 +1,13 @@
+apiVersion: kustomize.config.k8s.io/v1beta1
+kind: Kustomization
+
+
+resources:
+  - deployment.yaml
+  - service.yaml
+  
+
+images:
+  - name: memcached
+    newName: memcached
+    newTag: 1.6.29
diff --git a/memcached/service.yaml b/memcached/service.yaml
new file mode 100644
index 0000000..c876f2c
--- /dev/null
+++ b/memcached/service.yaml
@@ -0,0 +1,11 @@
+apiVersion: v1
+kind: Service
+metadata:
+  name: memcached
+spec:
+  selector:
+    app: memcached
+  ports:
+    - protocol: TCP
+      port: 11211
+      targetPort: 11211