@@ -74,6 +74,13 @@ type BackendTrafficPolicySpec struct {
7474 // UpstreamHost specifies the host of the Upstream request. Used only if
7575 // passHost is set to `rewrite`.
7676 Host Hostname `json:"upstreamHost,omitempty" yaml:"upstreamHost,omitempty"`
77+
78+ // HealthCheck defines active and passive health check configuration for
79+ // the upstream backends. When configured, APISIX will probe backends
80+ // (active) or monitor live traffic (passive) to detect and bypass
81+ // unhealthy nodes.
82+ // +optional
83+ HealthCheck * HealthCheck `json:"healthCheck,omitempty" yaml:"healthCheck,omitempty"`
7784}
7885
7986// LoadBalancer describes the load balancing parameters.
@@ -125,6 +132,139 @@ type BackendTrafficPolicyList struct {
125132 Items []BackendTrafficPolicy `json:"items"`
126133}
127134
135+ // HealthCheck defines the active and passive health check configuration for upstream nodes.
136+ type HealthCheck struct {
137+ // Active health checks proactively send requests to upstream nodes to determine their availability.
138+ // +kubebuilder:validation:Required
139+ Active * ActiveHealthCheck `json:"active" yaml:"active"`
140+ // Passive health checks evaluate upstream health based on observed traffic (timeouts, errors).
141+ // +kubebuilder:validation:Optional
142+ Passive * PassiveHealthCheck `json:"passive,omitempty" yaml:"passive,omitempty"`
143+ }
144+
145+ // ActiveHealthCheck defines the active upstream health check configuration.
146+ type ActiveHealthCheck struct {
147+ // Type is the health check type. Can be `http`, `https`, or `tcp`.
148+ // +kubebuilder:validation:Enum=http;https;tcp;
149+ // +kubebuilder:default=http
150+ // +optional
151+ Type string `json:"type,omitempty" yaml:"type,omitempty"`
152+
153+ // Timeout sets health check timeout.
154+ // +optional
155+ Timeout metav1.Duration `json:"timeout,omitempty" yaml:"timeout,omitempty"`
156+
157+ // Concurrency sets the number of targets to be checked at the same time.
158+ // +kubebuilder:validation:Minimum=0
159+ // +optional
160+ Concurrency int `json:"concurrency,omitempty" yaml:"concurrency,omitempty"`
161+
162+ // Host sets the upstream host used in the health check request.
163+ // +optional
164+ Host string `json:"host,omitempty" yaml:"host,omitempty"`
165+
166+ // Port sets the port on the upstream node to probe.
167+ // +kubebuilder:validation:Minimum=1
168+ // +kubebuilder:validation:Maximum=65535
169+ // +optional
170+ Port int32 `json:"port,omitempty" yaml:"port,omitempty"`
171+
172+ // HTTPPath sets the HTTP path for the probe request.
173+ // +optional
174+ HTTPPath string `json:"httpPath,omitempty" yaml:"httpPath,omitempty"`
175+
176+ // StrictTLS controls whether TLS certificate validation is enforced.
177+ // +optional
178+ StrictTLS * bool `json:"strictTLS,omitempty" yaml:"strictTLS,omitempty"`
179+
180+ // RequestHeaders sets additional HTTP request headers for the probe.
181+ // +optional
182+ RequestHeaders []string `json:"requestHeaders,omitempty" yaml:"requestHeaders,omitempty"`
183+
184+ // Healthy configures the thresholds for marking a node healthy.
185+ // +optional
186+ Healthy * ActiveHealthCheckHealthy `json:"healthy,omitempty" yaml:"healthy,omitempty"`
187+
188+ // Unhealthy configures the thresholds for marking a node unhealthy.
189+ // +optional
190+ Unhealthy * ActiveHealthCheckUnhealthy `json:"unhealthy,omitempty" yaml:"unhealthy,omitempty"`
191+ }
192+
193+ // PassiveHealthCheck defines passive health check configuration based on observed traffic.
194+ type PassiveHealthCheck struct {
195+ // Type is the passive health check type. Can be `http`, `https`, or `tcp`.
196+ // +kubebuilder:validation:Enum=http;https;tcp;
197+ // +kubebuilder:default=http
198+ // +optional
199+ Type string `json:"type,omitempty" yaml:"type,omitempty"`
200+
201+ // Healthy defines conditions under which a node is considered healthy.
202+ // +optional
203+ Healthy * PassiveHealthCheckHealthy `json:"healthy,omitempty" yaml:"healthy,omitempty"`
204+
205+ // Unhealthy defines conditions under which a node is considered unhealthy.
206+ // +optional
207+ Unhealthy * PassiveHealthCheckUnhealthy `json:"unhealthy,omitempty" yaml:"unhealthy,omitempty"`
208+ }
209+
210+ // ActiveHealthCheckHealthy defines thresholds for actively marking an upstream node healthy.
211+ type ActiveHealthCheckHealthy struct {
212+ PassiveHealthCheckHealthy `json:",inline" yaml:",inline"`
213+
214+ // Interval defines the time between health check probes.
215+ // Minimum is 1s.
216+ Interval metav1.Duration `json:"interval,omitempty" yaml:"interval,omitempty"`
217+ }
218+
219+ // ActiveHealthCheckUnhealthy defines thresholds for actively marking an upstream node unhealthy.
220+ type ActiveHealthCheckUnhealthy struct {
221+ PassiveHealthCheckUnhealthy `json:",inline" yaml:",inline"`
222+
223+ // Interval defines the time between health check probes.
224+ // Minimum is 1s.
225+ Interval metav1.Duration `json:"interval,omitempty" yaml:"interval,omitempty"`
226+ }
227+
228+ // PassiveHealthCheckHealthy defines conditions for passively marking a node healthy.
229+ type PassiveHealthCheckHealthy struct {
230+ // HTTPCodes is the list of HTTP status codes considered healthy.
231+ // +kubebuilder:validation:MinItems=1
232+ // +optional
233+ HTTPCodes []int `json:"httpCodes,omitempty" yaml:"httpCodes,omitempty"`
234+
235+ // Successes is the number of consecutive successful responses required to mark a node healthy.
236+ // +kubebuilder:validation:Minimum=0
237+ // +kubebuilder:validation:Maximum=254
238+ // +optional
239+ Successes int `json:"successes,omitempty" yaml:"successes,omitempty"`
240+ }
241+
242+ // PassiveHealthCheckUnhealthy defines conditions for passively marking a node unhealthy.
243+ type PassiveHealthCheckUnhealthy struct {
244+ // HTTPCodes is the list of HTTP status codes considered unhealthy.
245+ // +kubebuilder:validation:MinItems=1
246+ // +optional
247+ HTTPCodes []int `json:"httpCodes,omitempty" yaml:"httpCodes,omitempty"`
248+
249+ // HTTPFailures is the number of HTTP failures to mark a node unhealthy.
250+ // +kubebuilder:validation:Minimum=0
251+ // +kubebuilder:validation:Maximum=254
252+ // +optional
253+ HTTPFailures int `json:"httpFailures,omitempty" yaml:"httpFailures,omitempty"`
254+
255+ // TCPFailures is the number of TCP failures to mark a node unhealthy.
256+ // +kubebuilder:validation:Minimum=0
257+ // +kubebuilder:validation:Maximum=254
258+ // +optional
259+ TCPFailures int `json:"tcpFailures,omitempty" yaml:"tcpFailures,omitempty"`
260+
261+ // Timeouts is the number of timeouts to mark a node unhealthy.
262+ // +kubebuilder:validation:Minimum=1
263+ // +kubebuilder:validation:Maximum=254
264+ // +optional
265+ Timeouts int `json:"timeouts,omitempty" yaml:"timeouts,omitempty"`
266+ }
267+
128268func init () {
129269 SchemeBuilder .Register (& BackendTrafficPolicy {}, & BackendTrafficPolicyList {})
130270}
0 commit comments