Refactor Kubernetes configuration to enable Traefik for gateway routing

This commit is contained in:
2024-07-25 19:33:00 +08:00
parent e44e9da832
commit 996c713510
2 changed files with 41 additions and 54 deletions
+8
View File
@@ -9,4 +9,12 @@ providers:
enabled: true enabled: true
# Allow the Gateway to expose HTTPRoute from all namespaces # Allow the Gateway to expose HTTPRoute from all namespaces
gateway: gateway:
enabled: true
namespacePolicy: All namespacePolicy: All
annotations:
cert-manager.io/issuer: selfsigned-issuer
listeners:
websecure:
hostname: whoami.docker.localhost
certificateRefs:
- name: whoami-tls
+32 -53
View File
@@ -1,11 +1,10 @@
# Application to expose ---
kind: Deployment
apiVersion: apps/v1 apiVersion: apps/v1
kind: Deployment
metadata: metadata:
name: whoami name: whoami
namespace: whoami
spec: spec:
replicas: 3 replicas: 2
selector: selector:
matchLabels: matchLabels:
app: whoami app: whoami
@@ -13,68 +12,48 @@ spec:
metadata: metadata:
labels: labels:
app: whoami app: whoami
spec: spec:
containers: containers:
- name: whoami - name: whoami
image: traefik/whoami image: traefik/whoami
--- ---
# Service to reach the application on the cluster
apiVersion: v1 apiVersion: v1
kind: Service kind: Service
metadata: metadata:
name: whoami name: whoami
namespace: whoami
labels:
app: whoami
spec: spec:
type: ClusterIP
ports:
- port: 80
name: whoami
selector: selector:
app: whoami app: whoami
ports:
- protocol: TCP
port: 80
--- ---
# HTTPRoute
apiVersion: gateway.networking.k8s.io/v1 apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute kind: HTTPRoute
metadata: metadata:
name: whoami-httproute name: whoami
namespace: whoami
spec: spec:
parentRefs: parentRefs:
- name: traefik-gateway - name: traefik-gateway
namespace: traefik
hostnames: hostnames:
- node03.local - whoami.docker.localhost
rules: rules:
- matches: - matches:
- path: - path:
type: PathPrefix type: Exact
value: / value: /
backendRefs:
- name: whoami backendRefs:
namespace: whoami - name: whoami
port: 80 port: 80
# filters: weight: 1
# # Core filter which adds a header
# - type: RequestHeaderModifier ---
# requestHeaderModifier: apiVersion: cert-manager.io/v1
# add: kind: Issuer
# - name: x-post-topic metadata:
# value: GatewayAPI name: selfsigned-issuer
# # ExtensionRef filter to use the Traefik Middleware AddPrefix spec:
# - type: ExtensionRef selfSigned: {}
# extensionRef:
# group: traefik.io
# kind: Middleware
# name: addprefix
# ---
# # Traefik Middleware AddPrefix
# apiVersion: traefik.io/v1alpha1
# kind: Middleware
# metadata:
# name: addprefix
# namespace: whoami
# spec:
# addPrefix:
# prefix: /gatewayapi