From e995482bfda93ca69c4d5a0941990031e1f7dc60 Mon Sep 17 00:00:00 2001 From: "d.viti" Date: Thu, 9 Oct 2025 15:24:29 +0200 Subject: [PATCH] Enable Kubernetes Service Discovery for API7 Gateway upstreams MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Configured API7 Gateway to use Kubernetes Service Discovery instead of static upstream nodes. This enables dynamic discovery of backend Pods through the Kubernetes API. Benefits: - Automatic scaling: New Pods are automatically added to upstream pool - Health checks: Only healthy Pods receive traffic - Zero downtime: Automatic updates during deployments and rollouts - No manual upstream configuration needed Changes: - Updated configmap-adc.yaml to use discovery_type: kubernetes - Service discovery queries Kubernetes API for Pod endpoints - Falls back to static nodes if serviceDiscovery.enabled is false - Added documentation in values.yaml explaining the feature The RBAC permissions (services, endpoints watch) were already configured in rbac-adc.yaml, so no additional permissions are needed. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- .../templates/configmap-adc.yaml | 24 +++++++++++++++++++ helm/api7ee-demo-k8s/values.yaml | 5 ++++ 2 files changed, 29 insertions(+) diff --git a/helm/api7ee-demo-k8s/templates/configmap-adc.yaml b/helm/api7ee-demo-k8s/templates/configmap-adc.yaml index 0158877..80cac7a 100644 --- a/helm/api7ee-demo-k8s/templates/configmap-adc.yaml +++ b/helm/api7ee-demo-k8s/templates/configmap-adc.yaml @@ -17,10 +17,22 @@ data: name: {{ include "api7ee.fullname" . }}-web-upstream scheme: http type: roundrobin + {{- if .Values.api7.serviceDiscovery.enabled }} + # Use Kubernetes Service Discovery + discovery_type: kubernetes + service_name: {{ include "api7ee.fullname" . }}-web + {{- if .Values.api7.serviceDiscovery.namespace }} + namespace_id: {{ .Values.api7.serviceDiscovery.namespace }} + {{- else }} + namespace_id: {{ .Release.Namespace }} + {{- end }} + {{- else }} + # Static nodes configuration nodes: - host: {{ include "api7ee.fullname" . }}-web.{{ .Release.Namespace }}.svc.cluster.local port: {{ .Values.web.service.port }} weight: 100 + {{- end }} routes: # Route for web frontend (all paths except /api) - name: {{ include "api7ee.fullname" . }}-web-route @@ -54,10 +66,22 @@ data: name: {{ include "api7ee.fullname" . }}-api-upstream scheme: http type: roundrobin + {{- if .Values.api7.serviceDiscovery.enabled }} + # Use Kubernetes Service Discovery + discovery_type: kubernetes + service_name: {{ include "api7ee.fullname" . }}-api + {{- if .Values.api7.serviceDiscovery.namespace }} + namespace_id: {{ .Values.api7.serviceDiscovery.namespace }} + {{- else }} + namespace_id: {{ .Release.Namespace }} + {{- end }} + {{- else }} + # Static nodes configuration nodes: - host: {{ include "api7ee.fullname" . }}-api.{{ .Release.Namespace }}.svc.cluster.local port: {{ .Values.api.service.port }} weight: 100 + {{- end }} routes: # High priority route for LLM endpoints with AI rate limiting - name: {{ include "api7ee.fullname" . }}-api-llm-route diff --git a/helm/api7ee-demo-k8s/values.yaml b/helm/api7ee-demo-k8s/values.yaml index 135b553..8c5ecb7 100644 --- a/helm/api7ee-demo-k8s/values.yaml +++ b/helm/api7ee-demo-k8s/values.yaml @@ -258,6 +258,11 @@ api7: key: "" # Service Discovery + # When enabled, API7 Gateway dynamically discovers backend Pods through Kubernetes API + # instead of using static upstream nodes. This provides: + # - Automatic scaling: New Pods are automatically added to the upstream pool + # - Health checks: Only healthy Pods receive traffic + # - Zero downtime: Automatic updates during deployments and rollouts serviceDiscovery: enabled: true # Use Kubernetes service discovery namespace: "" # Leave empty to use release namespace