Error message: NoHttpResponseException

The ingress-nginx-controller does not have keepalive HTTP headers.

Symptom

Applications in your cluster see NoHttpResponseException message. The application might stop running.

Cause

The keepalive_timeout setting is not configured in the Nginx ingress controller.

The keepalive_timeout sets the time during which a keep-alive client connection stays open on the server side. The default value is 60 seconds.

Resolving the problem

Complete these steps to add the keepalive_timeout setting. You need kubectl to run these commands. To install kubectl, see Installing the Kubernetes CLI (kubectl).

  1. Edit the ingress-nginx-controller configmap.

    kubectl edit configmap nginx-ingress-controller
    
  2. Add the server-snippet in data section. The keepalive_timeout value of 88s is used here as an example. You can set the value to any integer in seconds.

    apiVersion: v1
    data:
      disable-access-log: "true"
      keep-alive-requests: "10001"
      server-snippet: |
        keepalive_timeout  88s 88s;
      server-tokens: "false"
    
  3. Get the NGINX ingress controller pod name.

    kubectl get pods | grep nginx
    
  4. Delete the ingress-nginx-controller pod and wait the pod to restart.

    kubectl delete pod <ingress-nginx-controller-pod-name>
    
  5. Verify that the keepalive parameter that you added in the ingress-nginx-controller configmap is also added to the nginx.conf file.

    kubectl exec -it <nginx-ingress-controller-pod> cat nginx.conf | grep keepalive
    

    If you do not see the parameter in the nginx.conf file, restart your Nginx ingress controller pod by deleting it.

  6. Verify that the keepalive works. Run a service to test it. Following is an example.

    curl -i -H "Connection: keep-alive" -H 'Host: example.com' http://10.11.6.166/banana
    

    Here is a sample output:

    HTTP/1.1 200 OK
    Date: Wed, 29 Jul 2020 06:23:10 GMT
    Content-Type: text/plain; charset=utf-8
    Content-Length: 7
    Connection: keep-alive
    Keep-Alive: timeout=88
    X-App-Name: http-echo
    X-App-Version: 0.2.3
    
    banana