Skip to content

Commit 9e4cb32

Browse files
Refactor ingress configuration for Traefik and NGINX; add host for TLS support and remove deprecated middleware
1 parent 0486843 commit 9e4cb32

File tree

7 files changed

+78
-23
lines changed

7 files changed

+78
-23
lines changed

.github/workflows/helm-tests.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,11 +196,17 @@ jobs:
196196
kubectl get ingress --all-namespaces -o jsonpath='{range .items[0]}kubectl describe ingress {.metadata.name} -n {.metadata.namespace}{end}' | sh
197197
kubectl get middleware.traefik.io --all-namespaces -o custom-columns='NAMESPACE:.metadata.namespace,NAME:.metadata.name' --no-headers | while read -r namespace name; do kubectl describe middleware.traefik.io "$name" -n "$namespace"; done
198198
199-
PUBLICIP='http://'$(kubectl -n kube-system get svc traefik -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
199+
# Get the IP address of the Traefik service
200+
PUBLICIP_VALUE=$(kubectl -n kube-system get svc traefik -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
201+
PUBLICIP='http://'$PUBLICIP_VALUE
200202
export VECTOR_ENDPOINT=$PUBLICIP/vector
201203
export STAC_ENDPOINT=$PUBLICIP/stac
202204
export RASTER_ENDPOINT=$PUBLICIP/raster
203205
206+
# Add entry to /etc/hosts for eoapi.local
207+
echo "Adding eoapi.local to /etc/hosts with IP: $PUBLICIP_VALUE"
208+
echo "$PUBLICIP_VALUE eoapi.local" | sudo tee -a /etc/hosts
209+
204210
echo '#################################'
205211
echo $VECTOR_ENDPOINT
206212
echo $STAC_ENDPOINT

docs/unified-ingress.md

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,28 +49,44 @@ For NGINX, use the following configuration:
4949
ingress:
5050
enabled: true
5151
className: "nginx"
52-
pathType: "ImplementationSpecific"
53-
pathSuffix: "(/|$)(.*)" # Required for NGINX path rewriting
52+
pathType: "Prefix"
5453
annotations:
5554
nginx.ingress.kubernetes.io/use-regex: "true"
56-
nginx.ingress.kubernetes.io/rewrite-target: /$2
5755
nginx.ingress.kubernetes.io/enable-cors: "true"
5856
nginx.ingress.kubernetes.io/enable-access-log: "true"
5957
```
6058
6159
### Traefik Ingress Controller
6260
63-
For Traefik, use the following configuration:
61+
When using Traefik, the system automatically includes the Traefik middleware to strip prefixes (e.g., `/stac`, `/raster`) from requests before forwarding them to services. This is handled by the `traefik-middleware.yaml` template.
62+
63+
For basic Traefik configuration:
6464

6565
```yaml
6666
ingress:
6767
enabled: true
6868
className: "traefik"
6969
pathType: "Prefix"
70+
# When using TLS, setting host is required to avoid "No domain found" warnings
71+
host: "example.domain.com" # Required to work properly with TLS
7072
annotations:
7173
traefik.ingress.kubernetes.io/router.entrypoints: web
72-
traefik.ingress.kubernetes.io/router.pathtransform.regex: "^/([^/]+)(.*)"
73-
traefik.ingress.kubernetes.io/router.pathtransform.replacement: "/$1$2"
74+
```
75+
76+
For Traefik with TLS:
77+
78+
```yaml
79+
ingress:
80+
enabled: true
81+
className: "traefik"
82+
pathType: "Prefix"
83+
# Host is required when using TLS with Traefik
84+
host: "example.domain.com"
85+
annotations:
86+
traefik.ingress.kubernetes.io/router.entrypoints: websecure
87+
tls:
88+
enabled: true
89+
secretName: eoapi-tls
7490
```
7591

7692
## Migration
@@ -79,7 +95,7 @@ If you're migrating from a previous version, follow these guidelines:
7995

8096
1. Update your values to use the new unified configuration
8197
2. Ensure your ingress controller-specific annotations are set correctly
82-
3. Set the appropriate `pathType` and `pathSuffix` for your controller
98+
3. Set the appropriate `pathType` for your controller
8399
4. Test the configuration before deploying to production
84100

85101
## Note for Traefik Users

helm-chart/eoapi/templates/services/deployment.yaml

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,38 @@ spec:
3232
app: {{ $serviceName }}-{{ $.Release.Name }}
3333
spec:
3434
serviceAccountName: eoapi-sa-{{ $.Release.Name }}
35+
{{- if $.Values.pgstacBootstrap.enabled }}
3536
initContainers:
36-
{{- include "eoapi.pgstacInitContainer" $ | nindent 8 }}
37+
- name: wait-for-pgstac-jobs
38+
image: bitnami/kubectl:latest
39+
command:
40+
- /bin/sh
41+
- -c
42+
- |
43+
echo "Waiting for pgstac-migrate job to complete..."
44+
until kubectl get job pgstac-migrate -o jsonpath='{.status.conditions[?(@.type=="Complete")].status}' | grep -q "True"; do
45+
echo "pgstac-migrate job not complete yet, waiting..."
46+
sleep 5
47+
done
48+
echo "pgstac-migrate job completed successfully."
49+
50+
{{- if $.Values.pgstacBootstrap.settings.loadSamples }}
51+
echo "Waiting for pgstac-load-samples job to complete..."
52+
until kubectl get job pgstac-load-samples -o jsonpath='{.status.conditions[?(@.type=="Complete")].status}' | grep -q "True"; do
53+
echo "pgstac-load-samples job not complete yet, waiting..."
54+
sleep 5
55+
done
56+
echo "pgstac-load-samples job completed successfully."
57+
{{- end }}
58+
{{- end }}
3759
containers:
3860
- image: {{ index $v "image" "name" }}:{{ index $v "image" "tag" }}
3961
name: {{ $serviceName }}
4062
command:
4163
{{- toYaml (index $v "command") | nindent 10 }}
4264
{{- if (and ($.Values.ingress.className) (or (eq $.Values.ingress.className "nginx") (eq $.Values.ingress.className "traefik"))) }}
65+
- "--proxy-headers"
66+
- "--forwarded-allow-ips=*"
4367
- "--root-path=/{{ $serviceName }}"
4468
{{- end }}{{/* needed for proxies and path rewrites on NLB */}}
4569
livenessProbe:

helm-chart/eoapi/templates/services/ingress.yaml

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,11 @@ metadata:
1212
labels:
1313
app: sharedingress
1414
annotations:
15-
{{- if eq .Values.ingress.className "traefik" }}
16-
traefik.ingress.kubernetes.io/router.entrypoints: web
17-
traefik.ingress.kubernetes.io/router.middlewares: path-rewrite-middleware-{{ $.Release.Name }}@kubernetescrd
18-
{{- end }}
1915
{{- if .Values.ingress.annotations }}
2016
{{ toYaml .Values.ingress.annotations | indent 4 }}
17+
{{- end }}
18+
{{- if eq .Values.ingress.className "traefik" }}
19+
traefik.ingress.kubernetes.io/router.middlewares: {{ $.Release.Namespace }}-strip-prefix-middleware-{{ $.Release.Name }}@kubernetescrd
2120
{{- end }}
2221
{{- if and .Values.ingress.tls.enabled .Values.ingress.tls.certManager .Values.ingress.tls.certManagerIssuer }}
2322
cert-manager.io/issuer: {{ .Values.ingress.tls.certManagerIssuer }}
@@ -27,7 +26,10 @@ spec:
2726
ingressClassName: {{ .Values.ingress.className }}
2827
{{- end }}
2928
rules:
30-
- http:
29+
- {{- if .Values.ingress.host }}
30+
host: {{ .Values.ingress.host }}
31+
{{- end }}
32+
http:
3133
paths:
3234
{{- range $serviceName, $v := .Values }}
3335
{{- if has $serviceName $.Values.apiServices }}
@@ -51,9 +53,6 @@ spec:
5153
port:
5254
number: 80
5355
{{- end }}
54-
{{- if .Values.ingress.host }}
55-
host: {{ .Values.ingress.host }}
56-
{{- end }}
5756
{{- if and .Values.ingress.host .Values.ingress.tls.enabled }}
5857
tls:
5958
- hosts:

helm-chart/eoapi/templates/services/traefik-middleware.yaml

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,16 @@
22
apiVersion: traefik.io/v1alpha1
33
kind: Middleware
44
metadata:
5-
name: path-rewrite-middleware-{{ $.Release.Name }}
5+
name: strip-prefix-middleware-{{ $.Release.Name }}
66
namespace: {{ $.Release.Namespace }}
77
spec:
8-
replacePathRegex:
9-
regex: "^/(raster|vector|stac|multidim)(/|$)(.*)"
10-
replacement: "$1/$3"
8+
stripPrefix:
9+
prefixes:
10+
{{- range $serviceName, $v := .Values }}
11+
{{- if has $serviceName $.Values.apiServices }}
12+
{{- if (index $v "enabled") }}
13+
- /{{ $serviceName }}
14+
{{- end }}
15+
{{- end }}
16+
{{- end }}
1117
{{- end }}

helm-chart/eoapi/test-k3s-unittest-values.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ ingress:
44
enabled: true
55
className: "traefik"
66
pathType: "Prefix"
7+
host: "eoapi.local" # Adding a host value to avoid "No domain found" warnings with Traefik
78
pgstacBootstrap:
89
enabled: true
910
settings:

helm-chart/eoapi/tests/ingress_tests.yaml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ tests:
4040
set:
4141
ingress.className: "traefik"
4242
ingress.pathType: "Prefix"
43+
ingress.host: "eoapi.local"
4344
testing: true
4445
raster.enabled: false
4546
stac.enabled: true
@@ -58,21 +59,23 @@ tests:
5859
path: metadata.annotations
5960
value:
6061
traefik.ingress.kubernetes.io/router.entrypoints: web
61-
traefik.ingress.kubernetes.io/router.middlewares: path-rewrite-middleware-RELEASE-NAME@kubernetescrd
6262
- equal:
6363
path: spec.ingressClassName
6464
value: "traefik"
65+
- equal:
66+
path: spec.rules[0].host
67+
value: "eoapi.local"
6568

6669
- it: "multidim ingress in production (non-testing) with traefik controller"
6770
set:
6871
ingress.className: "traefik"
6972
ingress.pathType: "Prefix"
73+
ingress.host: "eoapi.local"
7074
testing: false
7175
raster.enabled: false
7276
stac.enabled: false
7377
vector.enabled: false
7478
multidim.enabled: true
75-
docServer.enabled: true
7679
asserts:
7780
- isKind:
7881
of: Ingress

0 commit comments

Comments
 (0)