Skip to content

Commit

Permalink
default to kube-proxy health probes for Service type=LoadBalancer, ex…
Browse files Browse the repository at this point in the history
…ternalTrafficPolicy=Cluster
  • Loading branch information
damdo committed Jun 1, 2023
1 parent 77e154b commit 9cc0a8a
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 67 deletions.
8 changes: 5 additions & 3 deletions pkg/consts/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -451,8 +451,10 @@ const (
HealthProbeParamsProtocol HealthProbeParams = "protocol"

// HealthProbeParamsPort determines the probe port for the health probe params.
// It always takes priority over the NodePort of the spec.ports in a Service
HealthProbeParamsPort HealthProbeParams = "port"
// It always takes priority over the NodePort of the spec.ports in a Service.
// If not set, the kube-proxy health port (10256) will be configured by default.
HealthProbeParamsPort HealthProbeParams = "port"
HealthProbeDefaultRequestPort int32 = 10256

// HealthProbeParamsProbeInterval determines the probe interval of the load balancer health probe.
// The minimum probe interval is 5 seconds and the default value is 5. The total duration of all intervals cannot exceed 120 seconds.
Expand All @@ -468,7 +470,7 @@ const (
// This is only useful for the HTTP and HTTPS, and would be ignored when using TCP. If not set,
// `/healthz` would be configured by default.
HealthProbeParamsRequestPath HealthProbeParams = "request-path"
HealthProbeDefaultRequestPath string = "/"
HealthProbeDefaultRequestPath string = "/healthz"
)

type HealthProbeParams string
Expand Down
11 changes: 8 additions & 3 deletions pkg/provider/azure_loadbalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -2203,20 +2203,22 @@ func (az *Cloud) buildHealthProbeRulesForPort(serviceManifest *v1.Service, port
}
}

// 4. Finally, if protocol is still nil, default to TCP
// 4. Finally, if protocol is still nil, default to HTTP
if protocol == nil {
protocol = pointer.String(string(network.ProtocolTCP))
protocol = pointer.String(string(network.ProtocolHTTP))
}

*protocol = strings.TrimSpace(*protocol)
switch {
case strings.EqualFold(*protocol, string(network.ProtocolTCP)):
properties.Protocol = network.ProbeProtocolTCP
properties.Port = &port.NodePort
case strings.EqualFold(*protocol, string(network.ProtocolHTTPS)):
//HTTPS probe is only supported in standard loadbalancer
//For backward compatibility,when unsupported protocol is used, fall back to tcp protocol in basic lb mode instead
if !az.useStandardLoadBalancer() {
properties.Protocol = network.ProbeProtocolTCP
properties.Port = &port.NodePort
} else {
properties.Protocol = network.ProbeProtocolHTTPS
}
Expand All @@ -2225,10 +2227,13 @@ func (az *Cloud) buildHealthProbeRulesForPort(serviceManifest *v1.Service, port
default:
//For backward compatibility,when unsupported protocol is used, fall back to tcp protocol in basic lb mode instead
properties.Protocol = network.ProbeProtocolTCP
properties.Port = &port.NodePort
}

// Lookup or Override Health Probe Port
properties.Port = &port.NodePort
if properties.Port == nil {
properties.Port = pointer.Int32Ptr(consts.HealthProbeDefaultRequestPort)
}

probePort, err := consts.GetHealthProbeConfigOfPortFromK8sSvcAnnotation(serviceManifest.Annotations, port.Port, consts.HealthProbeParamsPort, func(s *string) error {
if s == nil {
Expand Down
Loading

0 comments on commit 9cc0a8a

Please sign in to comment.