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

Add something like /status or /health to NGINX config #90

Closed
jmastr opened this issue Dec 1, 2016 · 6 comments
Closed

Add something like /status or /health to NGINX config #90

jmastr opened this issue Dec 1, 2016 · 6 comments

Comments

@jmastr
Copy link

jmastr commented Dec 1, 2016

Hi,

I have a setup, where an external LoadBalancer pointing to the NGINX Ingress Controller . The NGINX Ingress Controller serves multiple Kubernetes Namespaces. For the external LoadBalancer's health checker I need a location that is available in all NGINX config files.

ngx_http_stub_status_module comes to mind, which is already available in the shipped NGINX:

location /status {
    stub_status;
    allow all;
}

Something like this maybe? Is there a better way? How about a new annotation like nginx.org/status?

@pleshakov
Copy link
Contributor

@jmastr

For the external LoadBalancer's health checker I need a location that is available in all NGINX config files.

I assume that what you need is the following:

  • NGINX must respond to the requests with a special URI when it's heathy. Example: NGINX responds to the request http://<IP>:80/health with the 200 response code, meaning that it's healthy.
  • NGINX must always respond, regardless if any Ingress rules are present in the cluster.
  • the URI must be configurable.

I suggest we add the following annotation to the ConfigMap: nginx.org/health-status-uri with some default value like /nginx-health.

ngx_http_stub_status_module comes to mind, which is already available in the shipped NGINX

the health check location can be as easy as this:

location /nginx-health {
  return 200 "healthy\n";
}

This location should be added to the default server -- a server that responds to the requests with the host header not matching any Ingress hostnames. Currently, there is no default server deployed, so we need to add it.

When the user creates an Ingress rule without a hostname, for example:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: default-backend
  namespace: default
spec:
  backend:
    serviceName: default-backend
    servicePort: 80

this becomes a default server (#79). So we need to make sure that if the user deploys such an Ingress, we add the health location to it.

I suggest we add this feature after #77, which will handle cases when multiple Ingress rules with the same hostname exist in the cluster.

As a temporal solution you can add the following config to the image:

server {
    listen 80 default_server;

    location /nginx-health {
        access_log off;
        return 200 "healthy\n";
    }
}

@jmastr
Copy link
Author

jmastr commented Dec 1, 2016

Thanks for the feedback. Sounds great. Then I'll wait for #77.

@jmastr
Copy link
Author

jmastr commented Dec 12, 2016

It's been a while now. Any news? @pleshakov

@pleshakov
Copy link
Contributor

@jmastr
Ideally, this feature should be a part of a bigger feature (the default server) that solves this #52 The default server must handle requests with a host header that doesn't match any Ingress rules. Both for HTTP and HTTPs requests. The latter requires to have a certificate and a key for the default server. It must return 404s for all requests expect for the requests to the health-status location.

As the user can deploy Ingress resources without hostnames, #77 should help to handle merging of the health location and such Ingress resources to handle edge cases.

I'd still wait #77 to be completed before starting fully working on the default server.

For now, we can add the -health-status parameter to the controller. If it is present, the default server that listens only on port 80 with the specified health check location gets added to the main nginx conf file.

server {
    listen 80 default_server;

    location /nginx-health {
        access_log off;
        return 200 "healthy\n";
    }
}

Let me know what you think

jmastr pushed a commit to endocode/kubernetes-ingress that referenced this issue Dec 13, 2016
Ideally, this feature should be a part of a bigger feature (the default
server) that solves nginxinc#52.

For now, we add the "-health-status" parameter to the controller. If
it is present, the default server listening on port 80 with the health
check location "/nginx-health" gets added to the main nginx
configuration.

Closes nginxinc#90
jmastr pushed a commit to endocode/kubernetes-ingress that referenced this issue Dec 14, 2016
Ideally, this feature should be a part of a bigger feature (the default
server) that solves nginxinc#52.

For now, we add the "-health-status" parameter to the controller. If
it is present, the default server listening on port 80 with the health
check location "/nginx-health" gets added to the main nginx
configuration.

Closes nginxinc#90
jmastr pushed a commit to endocode/kubernetes-ingress that referenced this issue Dec 14, 2016
Ideally, this feature should be a part of a bigger feature (the default
server) that solves nginxinc#52.

For now, we add the "-health-status" parameter to the controller. If
it is present, the default server listening on port 80 with the health
check location "/nginx-health" gets added to the main nginx
configuration.

Closes nginxinc#90
@maticko maticko mentioned this issue Sep 19, 2017
@Alexandr-Pletnev
Copy link

Much better with default_type text/plain;

server {
    listen 80 default_server;

    location /nginx-health {
        access_log off;
        default_type text/plain;
        return 200 "healthy\n";
    }
}

@kapil26021994
Copy link

kapil26021994 commented Jan 25, 2024

hi @Alexandr-Pletnev @pleshakov i have 1 doubt in my case from CICD pipeline they add health check part like--/ui/health so from location section we add health check like below or need to change something can you please help me regarding this one:

location /ui/health {
access_log off;
default_type text/plain;
return 200 "healthy\n";
}

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

4 participants