Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Health checks return 404 code #2360

Closed
a13x5 opened this issue May 30, 2023 · 2 comments
Closed

Health checks return 404 code #2360

a13x5 opened this issue May 30, 2023 · 2 comments

Comments

@a13x5
Copy link

a13x5 commented May 30, 2023

All health checks are return 404 code by default.
In the docs it said that by default endpoints should be healthz and readyz

// Readiness probe endpoint name, defaults to "readyz"
ReadinessEndpointName string

// Liveness probe endpoint name, defaults to "healthz"
LivenessEndpointName string

But when checking it with curl -XGET http://127.0.0.1:8080/healthz it returns 404, since by default it's metrics endpoint (undocumented).
When configuring a separate health endpoint

	mgr, err := manager.New(
		config.GetConfigOrDie(),
		manager.Options{
			Scheme: initSheme(),
			HealthProbeBindAddress: "0.0.0.0:8081",
		},
	)

Heath probes still return 404

> curl -XGET http://127.0.0.1:8081/readyz
404 page not found
> curl -XGET http://127.0.0.1:8081/healthz
404 page not found

Is there a way to enable health checks with controller runtime?
controller-runtime version is v0.15.0

@iiiceoo
Copy link
Contributor

iiiceoo commented Jun 2, 2023

If you only set HealthProbeBindAddress, the default health check will listen on the TCP port:

func defaultHealthProbeListener(addr string) (net.Listener, error) {
if addr == "" || addr == "0" {
return nil, nil
}
ln, err := net.Listen("tcp", addr)
if err != nil {
return nil, fmt.Errorf("error listening on %s: %w", addr, err)
}
return ln, nil
}

Perhaps you should use nc to send a TCP packet for checking, rather than using curl to send a HTTP request:

$ nc -vz 127.0.0.1 8081
Connection to 127.0.0.1 8081 port [tcp/tproxy] succeeded!

Furthermore, if you need to customize your probe handel logic, you can add a healthz.Checker to mgr, then TCP server --> HTTP server and work according to the registered handler:

	mgr, err := ctrl.NewManager(
		ctrl.GetConfigOrDie(),
		ctrl.Options{
			Scheme:                 scheme,
			HealthProbeBindAddress: ":8081",
		},
	)
	if err != nil {
		os.Exit(1)
	}

	if err := mgr.AddHealthzCheck("healthz", healthz.Ping); err != nil {
		os.Exit(1)
	}
	if err := mgr.AddReadyzCheck("readyz", healthz.Ping); err != nil {
		os.Exit(1)
	}

Send a HTTP request:

$ curl -X GET -v http://127.0.0.1:8081/healthz
Note: Unnecessary use of -X or --request, GET is already inferred.
*   Trying 127.0.0.1:8081...
* TCP_NODELAY set
* Connected to 127.0.0.1 (127.0.0.1) port 8081 (#0)
> GET /healthz HTTP/1.1
> Host: 127.0.0.1:8081
> User-Agent: curl/7.68.0
> Accept: */*
> 
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< Content-Type: text/plain; charset=utf-8
< X-Content-Type-Options: nosniff
< Date: Fri, 02 Jun 2023 06:43:54 GMT
< Content-Length: 2
< 
* Connection #0 to host 127.0.0.1 left intact

@a13x5
Copy link
Author

a13x5 commented Jun 3, 2023

@iiiceoo Thank you very much it worked! I missed the fact that by default it TCP only.
Should I add this to the docs somewhere maybe? WDYT?
And btw I will close the issue, since it resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants