apiVersion: v1 kind: ServiceAccount metadata: name: gateway-lab-controller --- apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRole metadata: name: jeannie-gateway-lab labels: homelab.dev/gateway-lab: "true" rules: - apiGroups: [""] resources: ["namespaces"] verbs: ["get", "list", "watch"] - apiGroups: ["gateway.networking.k8s.io"] resources: ["gatewayclasses"] verbs: ["get", "list", "watch"] - apiGroups: ["gateway.networking.k8s.io"] resources: ["gatewayclasses/status"] verbs: ["update", "patch"] --- apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRoleBinding metadata: name: jeannie-gateway-lab labels: homelab.dev/gateway-lab: "true" roleRef: apiGroup: rbac.authorization.k8s.io kind: ClusterRole name: jeannie-gateway-lab subjects: - kind: ServiceAccount name: gateway-lab-controller namespace: gateway-lab --- apiVersion: rbac.authorization.k8s.io/v1 kind: Role metadata: name: gateway-lab-controller rules: - apiGroups: [""] resources: ["services", "endpoints", "secrets", "configmaps"] verbs: ["get", "list", "watch"] - apiGroups: ["discovery.k8s.io"] resources: ["endpointslices"] verbs: ["get", "list", "watch"] - apiGroups: ["gateway.networking.k8s.io"] resources: ["gateways", "httproutes", "grpcroutes", "referencegrants", "backendtlspolicies", "tlsroutes", "listenersets"] verbs: ["get", "list", "watch"] - apiGroups: ["gateway.networking.k8s.io"] resources: ["gateways/status", "httproutes/status", "grpcroutes/status", "tlsroutes/status", "backendtlspolicies/status", "listenersets/status"] verbs: ["update", "patch"] --- apiVersion: rbac.authorization.k8s.io/v1 kind: RoleBinding metadata: name: gateway-lab-controller roleRef: apiGroup: rbac.authorization.k8s.io kind: Role name: gateway-lab-controller subjects: - kind: ServiceAccount name: gateway-lab-controller namespace: gateway-lab --- apiVersion: gateway.networking.k8s.io/v1 kind: GatewayClass metadata: name: jeannie-gateway-lab labels: homelab.dev/gateway-lab: "true" spec: controllerName: traefik.io/gateway-controller --- apiVersion: gateway.networking.k8s.io/v1 kind: Gateway metadata: name: gateway-lab labels: homelab.dev/gateway-lab: "true" spec: gatewayClassName: jeannie-gateway-lab listeners: - name: web port: 8000 protocol: HTTP hostname: gateway-lab.localhost allowedRoutes: namespaces: from: Same --- apiVersion: gateway.networking.k8s.io/v1 kind: HTTPRoute metadata: name: gateway-lab labels: homelab.dev/gateway-lab: "true" spec: parentRefs: - name: gateway-lab hostnames: [gateway-lab.localhost] rules: - matches: - path: type: PathPrefix value: / backendRefs: - name: gateway-lab-api port: 8080 --- apiVersion: v1 kind: Service metadata: name: gateway-lab-proxy spec: selector: app: gateway-lab-proxy ports: - name: web port: 8000 targetPort: web --- apiVersion: apps/v1 kind: Deployment metadata: name: gateway-lab-proxy spec: replicas: 1 selector: matchLabels: app: gateway-lab-proxy template: metadata: labels: app: gateway-lab-proxy spec: serviceAccountName: gateway-lab-controller containers: - name: traefik image: traefik:v3.7.1 args: - --providers.kubernetesgateway=true - --providers.kubernetesgateway.namespaces=gateway-lab - --providers.kubernetesgateway.labelselector=homelab.dev/gateway-lab=true - --entrypoints.web.address=:8000 - --entrypoints.traefik.address=:9000 - --ping=true ports: - name: web containerPort: 8000 - name: health containerPort: 9000 readinessProbe: httpGet: path: /ping port: health resources: requests: {cpu: 30m, memory: 64Mi} limits: {memory: 256Mi} securityContext: allowPrivilegeEscalation: false capabilities: {drop: [ALL]} runAsNonRoot: true runAsUser: 65532 --- apiVersion: v1 kind: Service metadata: name: gateway-lab-api spec: selector: app: gateway-lab-api ports: - port: 8080 targetPort: http --- apiVersion: apps/v1 kind: Deployment metadata: name: gateway-lab-api spec: replicas: 1 selector: matchLabels: app: gateway-lab-api template: metadata: labels: app: gateway-lab-api spec: automountServiceAccountToken: false securityContext: runAsNonRoot: true runAsUser: 65532 runAsGroup: 65532 fsGroup: 65532 initContainers: - name: dependencies image: python:3.12-alpine command: ["python", "-m", "pip", "install", "--no-cache-dir", "--target", "/deps", "-r", "/app/requirements.txt"] env: - {name: HOME, value: /tmp} volumeMounts: - {name: app, mountPath: /app, readOnly: true} - {name: deps, mountPath: /deps} resources: requests: {cpu: 50m, memory: 64Mi} limits: {memory: 256Mi} securityContext: allowPrivilegeEscalation: false capabilities: {drop: [ALL]} containers: - name: api image: python:3.12-alpine command: ["python", "-m", "uvicorn", "api:app", "--host", "0.0.0.0", "--port", "8080"] env: - {name: PYTHONPATH, value: "/deps:/app"} - {name: PYTHONDONTWRITEBYTECODE, value: "1"} ports: - {name: http, containerPort: 8080} readinessProbe: httpGet: {path: /health, port: http} livenessProbe: httpGet: {path: /health, port: http} initialDelaySeconds: 10 volumeMounts: - {name: app, mountPath: /app, readOnly: true} - {name: deps, mountPath: /deps, readOnly: true} resources: requests: {cpu: 30m, memory: 64Mi} limits: {memory: 256Mi} securityContext: readOnlyRootFilesystem: true allowPrivilegeEscalation: false capabilities: {drop: [ALL]} volumes: - name: app configMap: name: gateway-lab-api - name: deps emptyDir: {}