From 98fae37f5e9428bd87bd701310efc4f6aa7cfbed Mon Sep 17 00:00:00 2001 From: Shawn Sorichetti Date: Sat, 15 Mar 2025 19:01:17 -0400 Subject: [PATCH 1/3] feat(web): Add caddy proxy to front web application The caddy proxy will handle long lived connections, and provide metrics for requests and statuses. --- apps/web/base/configmap.yaml | 14 ++++++++++++++ apps/web/base/deployment.yaml | 22 ++++++++++++++++++++-- apps/web/base/kustomization.yaml | 1 + 3 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 apps/web/base/configmap.yaml diff --git a/apps/web/base/configmap.yaml b/apps/web/base/configmap.yaml new file mode 100644 index 0000000..c7afd80 --- /dev/null +++ b/apps/web/base/configmap.yaml @@ -0,0 +1,14 @@ +--- +apiVersion: v1 +kind: ConfigMap +metadata: + name: caddy-config +data: + Caddyfile: | + { + admin :2019 + metrics + } + :80 { + reverse_proxy localhost:5001 + } diff --git a/apps/web/base/deployment.yaml b/apps/web/base/deployment.yaml index a8eb90d..12fcc38 100644 --- a/apps/web/base/deployment.yaml +++ b/apps/web/base/deployment.yaml @@ -23,8 +23,8 @@ spec: - name: web image: metacpan/metacpan-web:latest imagePullPolicy: Always - command: [ "/uwsgi.sh" ] - args: [ "--http-socket", ":5001" ] + command: ["/uwsgi.sh"] + args: ["--http-socket", ":5001"] ports: - containerPort: 5001 resources: @@ -37,7 +37,25 @@ spec: - name: metacpan-web-local mountPath: /app/metacpan_web_local.conf subPath: metacpan_web_local.conf + - name: caddy + image: caddy:latest + ports: + - containerPort: 2019 + - containerPort: 80 + volumeMounts: + - name: caddy-config + mountPath: /etc/caddy + resources: + requests: + memory: "128Mi" + cpu: "100m" + limits: + memory: "256Mi" + cpu: "200m" volumes: - name: metacpan-web-local secret: secretName: metacpan-web-local + - name: caddy-config + configMap: + name: caddy-config diff --git a/apps/web/base/kustomization.yaml b/apps/web/base/kustomization.yaml index b9888d0..c78021e 100644 --- a/apps/web/base/kustomization.yaml +++ b/apps/web/base/kustomization.yaml @@ -4,3 +4,4 @@ kind: Kustomization resources: - ./deployment.yaml - ./service.yaml + - ./configmap.yaml From c041b1acaafd7c314e0f6e080b66f1b47d152c8e Mon Sep 17 00:00:00 2001 From: Shawn Sorichetti Date: Sat, 15 Mar 2025 20:48:44 -0400 Subject: [PATCH 2/3] feat(web): Add metrics gathering from proxy The caddy proxy allows for scraping of metrics, add in the configuration to enable that scraping by prometheus. --- apps/web/base/kustomization.yaml | 1 + apps/web/base/service.yaml | 18 ++++++++++++++++++ apps/web/base/servicemonitor.yaml | 17 +++++++++++++++++ 3 files changed, 36 insertions(+) create mode 100644 apps/web/base/servicemonitor.yaml diff --git a/apps/web/base/kustomization.yaml b/apps/web/base/kustomization.yaml index c78021e..7566977 100644 --- a/apps/web/base/kustomization.yaml +++ b/apps/web/base/kustomization.yaml @@ -5,3 +5,4 @@ resources: - ./deployment.yaml - ./service.yaml - ./configmap.yaml + - ./servicemonitor.yaml diff --git a/apps/web/base/service.yaml b/apps/web/base/service.yaml index c31e1c3..e021fc6 100644 --- a/apps/web/base/service.yaml +++ b/apps/web/base/service.yaml @@ -1,3 +1,4 @@ +--- apiVersion: v1 kind: Service metadata: @@ -8,3 +9,20 @@ spec: targetPort: 5001 selector: app: web +--- +apiVersion: v1 +kind: Service +metadata: + name: web-metrics + labels: + app.kubernetes.io/component: metrics + app.kubernetes.io/name: web-metrics + app.kubernetes.io/part-of: web +spec: + ports: + - name: metrics + port: 2019 + targetPort: 2019 + protocol: TCP + selector: + app: web diff --git a/apps/web/base/servicemonitor.yaml b/apps/web/base/servicemonitor.yaml new file mode 100644 index 0000000..e1db634 --- /dev/null +++ b/apps/web/base/servicemonitor.yaml @@ -0,0 +1,17 @@ +apiVersion: monitoring.coreos.com/v1 +kind: ServiceMonitor +metadata: + name: http-metrics + namespace: apps--web + labels: + app: web +spec: + selector: + matchLabels: + app.kubernetes.io/name: web-metrics + namespaceSelector: + matchNames: + - apps--web + endpoints: + - port: metrics + interval: 15s From 545b0ec42760b5ebb3ad69da49ba7c62df4050d0 Mon Sep 17 00:00:00 2001 From: Shawn Sorichetti Date: Sat, 15 Mar 2025 20:50:30 -0400 Subject: [PATCH 3/3] feat(web): enable proxy and reduce workers Switch the service port to the proxy sending all traffic through it before reaching the web containers. Reduce the number of workers for web as the connection handling is now handled by the proxy. --- apps/web/base/deployment.yaml | 2 +- apps/web/base/service.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/web/base/deployment.yaml b/apps/web/base/deployment.yaml index 12fcc38..b791e07 100644 --- a/apps/web/base/deployment.yaml +++ b/apps/web/base/deployment.yaml @@ -24,7 +24,7 @@ spec: image: metacpan/metacpan-web:latest imagePullPolicy: Always command: ["/uwsgi.sh"] - args: ["--http-socket", ":5001"] + args: ["--http-socket", ":5001", "--workers", "10"] ports: - containerPort: 5001 resources: diff --git a/apps/web/base/service.yaml b/apps/web/base/service.yaml index e021fc6..14feaa2 100644 --- a/apps/web/base/service.yaml +++ b/apps/web/base/service.yaml @@ -6,7 +6,7 @@ metadata: spec: ports: - port: 80 - targetPort: 5001 + targetPort: 80 selector: app: web ---