Add a flag to specify address to bind the healthz server (#7541)

* Add a flag to specify address to bind the healthz server

Signed-off-by: m.nabokikh <maksim.nabokikh@flant.com>

* Add healthz host to the helm chart

Signed-off-by: m.nabokikh <maksim.nabokikh@flant.com>

* Apply suggestions from code review

Co-authored-by: Ricardo Katz <rikatz@users.noreply.github.com>

Co-authored-by: Ricardo Katz <rikatz@users.noreply.github.com>
This commit is contained in:
Maksim Nabokikh 2021-08-26 16:13:23 +04:00 committed by GitHub
parent 66c2a716da
commit 4c4013904a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 19 additions and 4 deletions

View file

@ -162,6 +162,7 @@ Requires the update-status parameter.`)
sslProxyPort = flags.Int("ssl-passthrough-proxy-port", 442, `Port to use internally for SSL Passthrough.`)
defServerPort = flags.Int("default-server-port", 8181, `Port to use for exposing the default server (catch-all).`)
healthzPort = flags.Int("healthz-port", 10254, "Port to use for the healthz endpoint.")
healthzHost = flags.String("healthz-host", "", "Address to bind the healthz endpoint.")
disableCatchAll = flags.Bool("disable-catch-all", false,
`Disable support for catch-all Ingresses`)
@ -286,6 +287,7 @@ https://blog.maxmind.com/2019/12/18/significant-changes-to-accessing-and-using-g
ShutdownGracePeriod: *shutdownGracePeriod,
UseNodeInternalIP: *useNodeInternalIP,
SyncRateLimit: *syncRateLimit,
HealthCheckHost: *healthzHost,
ListenPorts: &ngx_config.ListenPorts{
Default: *defServerPort,
Health: *healthzPort,

View file

@ -150,7 +150,7 @@ func main() {
registerHealthz(nginx.HealthPath, ngx, mux)
registerMetrics(reg, mux)
go startHTTPServer(conf.ListenPorts.Health, mux)
go startHTTPServer(conf.HealthCheckHost, conf.ListenPorts.Health, mux)
go ngx.Start()
handleSigterm(ngx, func(code int) {
@ -324,9 +324,9 @@ func registerProfiler() {
klog.Fatal(server.ListenAndServe())
}
func startHTTPServer(port int, mux *http.ServeMux) {
func startHTTPServer(host string, port int, mux *http.ServeMux) {
server := &http.Server{
Addr: fmt.Sprintf(":%v", port),
Addr: fmt.Sprintf("%s:%v", host, port),
Handler: mux,
ReadTimeout: 10 * time.Second,
ReadHeaderTimeout: 10 * time.Second,