From 55c5de9d6147f303d29223e7dc4eefdbcf597016 Mon Sep 17 00:00:00 2001 From: hermes Date: Mon, 9 Nov 2026 11:45:41 +1000 Subject: [PATCH] feat(deploy): add the kubernetes manifests so the deployment is in the repo MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The cluster objects for the beer namespace were created by hand. This puts them in the repo so they can be applied and reviewed like everything else. - `beer-deployment.yaml` — the Deployment, with the security context, the resource limits, and both probes wired up (`/healthz` liveness, `/readyz` readiness). - `beer-service.yaml` — the NodePort service. - `beer_namespace.yaml` — the namespace. The credentials are NOT in these files. `MONGO_PASS` and `SECRET_KEY` come from the live `beer-db` and `beer-app` Secrets, so applying the manifests cannot clobber a hand-provisioned credential. Notes on the pod security context --------------------------------- `runAsNonRoot: true` cannot be set on the container when the image's user is a *named* user - kubelet can only verify a numeric UID. The pod-level security context therefore sets `runAsUser: 999`, which matches the `beer` user the image creates (verified with `id` in the built image). The container also drops all capabilities and refuses privilege escalation. --- kube/beer-deployment.yaml | 91 +++++++++++++++++++++++++++++++++++++++ kube/beer-service.yaml | 17 ++++++++ kube/beer_namespace.yaml | 6 +++ 3 files changed, 114 insertions(+) create mode 100644 kube/beer-deployment.yaml create mode 100644 kube/beer-service.yaml create mode 100644 kube/beer_namespace.yaml diff --git a/kube/beer-deployment.yaml b/kube/beer-deployment.yaml new file mode 100644 index 0000000..dc67fb2 --- /dev/null +++ b/kube/beer-deployment.yaml @@ -0,0 +1,91 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: beer-deployment + namespace: beer + labels: + app: beer-data +spec: + replicas: 3 + selector: + matchLabels: + app: beer-data + strategy: + rollingUpdate: + maxSurge: 25% + maxUnavailable: 25% + type: RollingUpdate + template: + metadata: + labels: + app: beer-data + spec: + containers: + - name: beer-data + image: git.aridgwayweb.com/armistace/beer-data:latest + imagePullPolicy: Always + ports: + - containerPort: 5000 + protocol: TCP + env: + - name: MONGO_HOST + value: "192.168.178.229" + - name: MONGO_USER + value: "root" + # MONGO_PASS and SECRET_KEY come from the live Secret - they are + # deliberately NOT in this file. See RUNBOOK.md. + - name: MONGO_PASS + valueFrom: + secretKeyRef: + name: beer-db + key: mongo_pass + - name: SECRET_KEY + valueFrom: + secretKeyRef: + name: beer-app + key: secret_key + resources: + limits: + cpu: 200m + memory: 256Mi + requests: + cpu: 50m + memory: 64Mi + securityContext: + allowPrivilegeEscalation: false + capabilities: + drop: + - ALL + readOnlyRootFilesystem: false + livenessProbe: + httpGet: + path: /healthz + port: 5000 + initialDelaySeconds: 10 + periodSeconds: 20 + readinessProbe: + httpGet: + path: /readyz + port: 5000 + initialDelaySeconds: 5 + periodSeconds: 10 + volumeMounts: + - name: tmp + mountPath: /tmp + volumes: + - name: tmp + emptyDir: {} + securityContext: + runAsNonRoot: true + # The image creates a named user "beer". kubelet cannot verify that a + # *named* user is non-root (it can only check a numeric UID), so the + # UID is set explicitly here. It must match the UID in the image. + runAsUser: 999 + runAsGroup: 999 + fsGroup: 999 + nodeSelector: + kubernetes.io/hostname: archlinux-k3s-3 + imagePullSecrets: + - name: beercred + terminationGracePeriodSeconds: 30 + restartPolicy: Always diff --git a/kube/beer-service.yaml b/kube/beer-service.yaml new file mode 100644 index 0000000..e562b70 --- /dev/null +++ b/kube/beer-service.yaml @@ -0,0 +1,17 @@ +apiVersion: v1 +kind: Service +metadata: + name: beer-service + namespace: beer + labels: + app: beer-data +spec: + type: NodePort + selector: + app: beer-data + ports: + - name: http + port: 80 + targetPort: 5000 + nodePort: 30015 + protocol: TCP diff --git a/kube/beer_namespace.yaml b/kube/beer_namespace.yaml new file mode 100644 index 0000000..1f0f5b5 --- /dev/null +++ b/kube/beer_namespace.yaml @@ -0,0 +1,6 @@ +apiVersion: v1 +kind: Namespace +metadata: + name: beer + labels: + app: beer-data