Set different listeners per protocol version
This commit is contained in:
parent
7c635a8c83
commit
25bb7e4311
3 changed files with 25 additions and 8 deletions
|
@ -72,6 +72,7 @@ func newNGINXController() ingress.Controller {
|
||||||
n := &NGINXController{
|
n := &NGINXController{
|
||||||
binary: ngx,
|
binary: ngx,
|
||||||
configmap: &api_v1.ConfigMap{},
|
configmap: &api_v1.ConfigMap{},
|
||||||
|
isIPV6Enabled: isIPv6Enabled(),
|
||||||
}
|
}
|
||||||
|
|
||||||
var onChange func()
|
var onChange func()
|
||||||
|
@ -121,6 +122,9 @@ type NGINXController struct {
|
||||||
|
|
||||||
stats *statsCollector
|
stats *statsCollector
|
||||||
statusModule statusModule
|
statusModule statusModule
|
||||||
|
|
||||||
|
// returns true if IPV6 is enabled in the pod
|
||||||
|
isIPV6Enabled bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start start a new NGINX master process running in foreground.
|
// Start start a new NGINX master process running in foreground.
|
||||||
|
@ -425,6 +429,7 @@ func (n *NGINXController) OnUpdate(ingressCfg ingress.Configuration) ([]byte, er
|
||||||
HealthzURI: ngxHealthPath,
|
HealthzURI: ngxHealthPath,
|
||||||
CustomErrors: len(cfg.CustomHTTPErrors) > 0,
|
CustomErrors: len(cfg.CustomHTTPErrors) > 0,
|
||||||
Cfg: cfg,
|
Cfg: cfg,
|
||||||
|
IsIPV6Enabled: n.isIPV6Enabled && !cfg.DisableIpv6,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -468,3 +473,8 @@ func nextPowerOf2(v int) int {
|
||||||
|
|
||||||
return v
|
return v
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func isIPv6Enabled() bool {
|
||||||
|
cmd := exec.Command("test", "-f", "/proc/net/if_inet6")
|
||||||
|
return cmd.Run() == nil
|
||||||
|
}
|
||||||
|
|
|
@ -347,4 +347,5 @@ type TemplateConfig struct {
|
||||||
HealthzURI string
|
HealthzURI string
|
||||||
CustomErrors bool
|
CustomErrors bool
|
||||||
Cfg Configuration
|
Cfg Configuration
|
||||||
|
IsIPV6Enabled bool
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
{{ $cfg := .Cfg }}
|
{{ $cfg := .Cfg }}
|
||||||
|
{{ $IsIPV6Enabled := .IsIPV6Enabled }}
|
||||||
{{ $healthzURI := .HealthzURI }}
|
{{ $healthzURI := .HealthzURI }}
|
||||||
{{ $backends := .Backends }}
|
{{ $backends := .Backends }}
|
||||||
{{ $proxyHeaders := .ProxySetHeaders }}
|
{{ $proxyHeaders := .ProxySetHeaders }}
|
||||||
|
@ -218,10 +219,13 @@ http {
|
||||||
{{ range $index, $server := .Servers }}
|
{{ range $index, $server := .Servers }}
|
||||||
server {
|
server {
|
||||||
server_name {{ $server.Hostname }};
|
server_name {{ $server.Hostname }};
|
||||||
listen {{ if not $cfg.DisableIpv6 }}[::]:{{ end }}80{{ if $cfg.UseProxyProtocol }} proxy_protocol{{ end }}{{ if eq $server.Hostname "_"}} default_server {{ if not $cfg.DisableIpv6 }}ipv6only=off{{end}} reuseport backlog={{ $backlogSize }}{{end}};
|
listen 80{{ if $cfg.UseProxyProtocol }} proxy_protocol{{ end }}{{ if eq $server.Hostname "_"}} default_server reuseport backlog={{ $backlogSize }}{{end}};
|
||||||
|
{{ if $IsIPV6Enabled }}listen [::]:80{{ if $cfg.UseProxyProtocol }} proxy_protocol{{ end }}{{ if eq $server.Hostname "_"}} default_server reuseport backlog={{ $backlogSize }}{{ end }};{{ end }}
|
||||||
|
|
||||||
{{/* Listen on 442 because port 443 is used in the stream section */}}
|
{{/* Listen on 442 because port 443 is used in the stream section */}}
|
||||||
{{/* This listen on port 442 cannot contains proxy_protocol directive because port 443 is in charge of decoding the protocol */}}
|
{{/* This listen on port 442 cannot contains proxy_protocol directive because port 443 is in charge of decoding the protocol */}}
|
||||||
{{ if not (empty $server.SSLCertificate) }}listen {{ if gt (len $passthroughBackends) 0 }}442{{ else }}{{ if not $cfg.DisableIpv6 }}[::]:{{ end }}443 {{ if $cfg.UseProxyProtocol }} proxy_protocol {{ end }}{{ end }} {{ if eq $server.Hostname "_"}} default_server {{ if not $cfg.DisableIpv6 }}ipv6only=off{{end}} reuseport backlog={{ $backlogSize }}{{end}} ssl {{ if $cfg.UseHTTP2 }}http2{{ end }};
|
{{ if not (empty $server.SSLCertificate) }}listen {{ if gt (len $passthroughBackends) 0 }}442{{ else }}443 {{ if $cfg.UseProxyProtocol }} proxy_protocol {{ end }}{{ end }} {{ if eq $server.Hostname "_"}} default_server reuseport backlog={{ $backlogSize }}{{end}} ssl {{ if $cfg.UseHTTP2 }}http2{{ end }};
|
||||||
|
{{ if $IsIPV6Enabled }}{{ if not (empty $server.SSLCertificate) }}listen {{ if gt (len $passthroughBackends) 0 }}[::]:442{{ else }}[::]:443 {{ end }}{{ if $cfg.UseProxyProtocol }} proxy_protocol {{ end }}{{ end }} {{ if eq $server.Hostname "_"}} default_server reuseport backlog={{ $backlogSize }}{{end}} ssl {{ if $cfg.UseHTTP2 }}http2{{ end }};{{ end }}
|
||||||
{{/* comment PEM sha is required to detect changes in the generated configuration and force a reload */}}
|
{{/* comment PEM sha is required to detect changes in the generated configuration and force a reload */}}
|
||||||
# PEM sha: {{ $server.SSLPemChecksum }}
|
# PEM sha: {{ $server.SSLPemChecksum }}
|
||||||
ssl_certificate {{ $server.SSLCertificate }};
|
ssl_certificate {{ $server.SSLCertificate }};
|
||||||
|
@ -396,7 +400,7 @@ http {
|
||||||
# with an external software (like sysdig)
|
# with an external software (like sysdig)
|
||||||
location /nginx_status {
|
location /nginx_status {
|
||||||
allow 127.0.0.1;
|
allow 127.0.0.1;
|
||||||
{{ if not $cfg.DisableIpv6 }}allow ::1;{{ end }}
|
{{ if $IsIPV6Enabled }}allow ::1;{{ end }}
|
||||||
deny all;
|
deny all;
|
||||||
|
|
||||||
access_log off;
|
access_log off;
|
||||||
|
@ -414,7 +418,8 @@ http {
|
||||||
# Use the port 18080 (random value just to avoid known ports) as default port for nginx.
|
# Use the port 18080 (random value just to avoid known ports) as default port for nginx.
|
||||||
# Changing this value requires a change in:
|
# Changing this value requires a change in:
|
||||||
# https://github.com/kubernetes/contrib/blob/master/ingress/controllers/nginx/nginx/command.go#L104
|
# https://github.com/kubernetes/contrib/blob/master/ingress/controllers/nginx/nginx/command.go#L104
|
||||||
listen {{ if not $cfg.DisableIpv6 }}[::]:{{ end }}18080 {{ if not $cfg.DisableIpv6 }}ipv6only=off{{end}} default_server reuseport backlog={{ .BacklogSize }};
|
listen 18080 default_server reuseport backlog={{ .BacklogSize }};
|
||||||
|
{{ if $IsIPV6Enabled }}listen [::]:18080 default_server reuseport backlog={{ .BacklogSize }};{{ end }}
|
||||||
|
|
||||||
location {{ $healthzURI }} {
|
location {{ $healthzURI }} {
|
||||||
access_log off;
|
access_log off;
|
||||||
|
@ -500,7 +505,8 @@ stream {
|
||||||
{{ buildSSLPassthroughUpstreams $backends .PassthroughBackends }}
|
{{ buildSSLPassthroughUpstreams $backends .PassthroughBackends }}
|
||||||
|
|
||||||
server {
|
server {
|
||||||
listen {{ if not $cfg.DisableIpv6 }}[::]:{{ end }}443 {{ if not $cfg.DisableIpv6 }}ipv6only=off{{ end }}{{ if $cfg.UseProxyProtocol }} proxy_protocol{{ end }};
|
listen 443 {{ if $cfg.UseProxyProtocol }} proxy_protocol{{ end }};
|
||||||
|
{{ if $IsIPV6Enabled }}listen [::]:443 {{ if $cfg.UseProxyProtocol }} proxy_protocol{{ end }};{{ end }}
|
||||||
proxy_pass $stream_upstream;
|
proxy_pass $stream_upstream;
|
||||||
ssl_preread on;
|
ssl_preread on;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue