Skip to content

Commit

Permalink
Update k8s manifests to deploy the home app (#1037)
Browse files Browse the repository at this point in the history
Add some k8s manifests so that we can deploy the new home app.

I needed to add a second ingress file to handle rewriting the requests
the app receives - in essence, I'm using Nginx to rewrite requests for
`/mats-dev/` to `/`. There were some subtleties here with ingress
preferring to match requests to paths with longer lengths & the regex
capture groups Nginx rewrite-target needs artificially inflating the
char "length" of the path.

I've duplicated the changes to `gsl-dev` to the `local` setup as well.

PR stacked on top of #1032
  • Loading branch information
ian-noaa authored Sep 12, 2023
2 parents 2d007dc + c5e5d3b commit 2897a08
Show file tree
Hide file tree
Showing 13 changed files with 180 additions and 3 deletions.
27 changes: 27 additions & 0 deletions kubernetes/base/home/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: home
labels:
app.kubernetes.io/name: home
app.kubernetes.io/part-of: mats
app.kubernetes.io/component: frontend
app: home
spec:
replicas: 1
selector:
matchLabels:
app: home
template:
metadata:
labels:
app: home
spec:
containers:
- name: home
image: ghcr.io/noaa-gsl/mats/development/home:development
ports:
- containerPort: 8080
securityContext:
allowPrivilegeEscalation: false

3 changes: 3 additions & 0 deletions kubernetes/base/home/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
resources:
- deployment.yaml
- service.yaml
15 changes: 15 additions & 0 deletions kubernetes/base/home/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: v1
kind: Service
metadata:
name: home
labels:
app: home
spec:
selector:
app: home
ports:
- port: 80
targetPort: 8080
protocol: TCP
name: http
type: ClusterIP
28 changes: 28 additions & 0 deletions kubernetes/overlays/gsl-dev/home/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: home
spec:
template:
spec:
containers:
- name: home
resources:
requests:
memory: "1Gi"
cpu: "0.25"
limits:
memory: "8Gi"
cpu: "4"
volumeMounts:
- name: home-settings-file
mountPath: /app/settings.json
subPath: settings.json
readOnly: true
imagePullPolicy: Always # Since we track a long-lived tag
imagePullSecrets:
- name: mats-ghcr
volumes:
- name: home-settings-file
configMap:
name: home-config
14 changes: 14 additions & 0 deletions kubernetes/overlays/gsl-dev/home/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
resources:
- ../../../base/home

patchesStrategicMerge:
- deployment.yaml

images:
- name: ghcr.io/noaa-gsl/mats/development/home
newTag: development

configMapGenerator:
- name: home-config
files:
- settings.json # Should mirror the appropriate settings.json file in mats-settings
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ metadata:
annotations:
# Omit the rewrite-target annotation as it causes problems with Meteor's ROOT_URL
nginx.ingress.kubernetes.io/use-regex: "true"
name: mats
name: mats-apps
namespace: mats-dev
spec:
rules:
Expand Down
25 changes: 25 additions & 0 deletions kubernetes/overlays/gsl-dev/ingress-home.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
annotations:
# Use nginx's rewrite-target to strip the path prefix before sending the request to the home service
nginx.ingress.kubernetes.io/use-regex: "true"
nginx.ingress.kubernetes.io/rewrite-target: /$1
name: mats-home
namespace: mats-dev
spec:
rules:
- host: apps-dev.gsd.esrl.noaa.gov
http:
paths:
# Note - this rewrite rule can cause issues if the "path" with the regex capture group
# for the nginx rewrite-target gets longer than the paths in ingress-mats.yaml.
# This has happened before with the rule for `/mats-dev/ptype`. If multiple paths match,
# Kubernetes will prefer the longer path.
- path: /mats-dev/(.*)
pathType: Prefix
backend:
service:
name: home
port:
number: 80
4 changes: 3 additions & 1 deletion kubernetes/overlays/gsl-dev/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ resources:
- cb-ceiling
- ceil-vis
- ceil-vis15
- home
- landuse
- precipAccum
- precipGauge
Expand All @@ -14,6 +15,7 @@ resources:
- surfrad
- upperair
- mongo
- ingress.yaml
- ingress-apps.yaml
- ingress-home.yaml
commonLabels:
environment: dev
28 changes: 28 additions & 0 deletions kubernetes/overlays/local/home/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: home
spec:
template:
spec:
containers:
- name: home
resources:
requests:
memory: "1Gi"
cpu: "0.25"
limits:
memory: "8Gi"
cpu: "4"
volumeMounts:
- name: home-settings-file
mountPath: /app/settings.json
subPath: settings.json
readOnly: true
imagePullPolicy: Always # Since we track a long-lived tag
imagePullSecrets:
- name: mats-ghcr
volumes:
- name: home-settings-file
configMap:
name: home-config
14 changes: 14 additions & 0 deletions kubernetes/overlays/local/home/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
resources:
- ../../../base/home

patchesStrategicMerge:
- deployment.yaml

images:
- name: ghcr.io/noaa-gsl/mats/development/home
newTag: 1029-create-new-home-application

configMapGenerator:
- name: home-config
files:
- settings.json # Should mirror the appropriate settings.json file in mats-settings
File renamed without changes.
20 changes: 20 additions & 0 deletions kubernetes/overlays/local/ingress-home.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
annotations:
traefik.ingress.kubernetes.io/router.entrypoints: web

name: mats-home
namespace: mats-dev
spec:
rules:
- host: mats.127.0.0.1.nip.io
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: home
port:
number: 80
3 changes: 2 additions & 1 deletion kubernetes/overlays/local/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ resources:
- surfrad
- upperair
- mongo
- ingress.yaml
- ingress-apps.yaml
- ingress-home.yaml
commonLabels:
environment: local

0 comments on commit 2897a08

Please sign in to comment.