<p>On a local environment built with kubeadm. The cluster is made of Master and 2 worker nodes.</p>
<p><strong>What it is failing:</strong></p>
<p>Exposing Nginx-ingress Controller to external by Service type LoadBalancer, trying TLS termination to the Kubernetes cluster.</p>
<p>Here the exposed Service:</p>
<pre><code>NAME            TYPE           CLUSTER-IP      EXTERNAL-IP    PORT(S)                      
nginx-ingress   LoadBalancer   10.101.5.75     192.168.1.82   80:30745/TCP,443:30092/TCP   
web-service     ClusterIP      10.101.26.176   &lt;none&gt;         8080/TCP
</code></pre>
<p><strong>What it's working:</strong></p>
<p>Able to reach the web application with HTTP port 80 from external.</p>
<p>Here the pods in the cluster:</p>
<pre><code>NAME                              READY   STATUS    RESTARTS   AGE   IP          NODE    
nginx-ingress-7c5588544d-4mw9d    1/1     Running   0          38m   10.44.0.2   node1   
web-deployment-7d84778bc6-52pq7   1/1     Running   1          19h   10.44.0.1   node1   
web-deployment-7d84778bc6-9wwmn   1/1     Running   1          19h   10.36.0.2   node2   
</code></pre>
<p><strong>Test result for TLS termination</strong></p>
<p>Client side:</p>
<pre><code>curl -k https://example.com -v
* Rebuilt URL to https://example.com/
*   Trying 192.168.1.82...
* Connected to example.com (192.168.1.82) port 443 (#0)
* found 127 certificates in /etc/ssl/certs/ca-certificates.crt
* found 513 certificates in /etc/ssl/certs
* ALPN, offering http/1.1
* SSL connection using TLS1.2 / ECDHE_RSA_AES_128_GCM_SHA256
*    server certificate verification SKIPPED
*    server certificate status verification SKIPPED
*    common name: example.com (matched)
*    server certificate expiration date OK
*    server certificate activation date OK
*    certificate public key: RSA
*    certificate version: #1
*    subject: CN=example.com
*    start date: Thu, 22 Oct 2020 16:33:49 GMT
*    expire date: Fri, 22 Oct 2021 16:33:49 GMT
*    issuer: CN=My Cert Authority
*    compression: NULL
* ALPN, server accepted to use http/1.1
&gt; GET / HTTP/1.1
&gt; Host: example.com
&gt; User-Agent: curl/7.47.0
&gt; Accept: */*
&gt; 
&lt; HTTP/1.1 502 Bad Gateway
&lt; Server: nginx/1.19.3
</code></pre>
<p>Server side (logs from nginx-ingress pod):</p>
<pre><code>GET / HTTP/1.1
Connection: close
Host: example.com
X-Real-IP: 10.32.0.1
X-Forwarded-For: 10.32.0.1
X-Forwarded-Host: example.com
X-Forwarded-Port: 443
X-Forwarded-Proto: https
User-Agent: curl/7.47.0
Accept: */*

2020/10/22 18:38:59 [error] 23#23: *12 peer closed connection in SSL handshake while SSL handshaking  to upstream, client: 10.32.0.1, server: example.com, request: &quot;GET / HTTP/1.1&quot;, upstream: &quot;https://10.44.0.1:8081/&quot;, host: &quot;example.com&quot;

2020/10/22 18:38:59 [warn] 23#23: *12 upstream server temporarily disabled while SSL handshaking to upstream, client: 10.32.0.1, server: example.com, request: &quot;GET / HTTP/1.1&quot;, upstream: &quot;https://10.44.0.1:8081/&quot;, host: &quot;example.com&quot;

HTTP/1.1 502 Bad Gateway
Server: nginx/1.19.3
</code></pre>
<p><strong>What i checked</strong></p>
<p>Generated a CA and Server certificate following the link:
<a href="https://kubernetes.github.io/ingress-nginx/examples/PREREQUISITES/#tls-certificates" rel="nofollow noreferrer">https://kubernetes.github.io/ingress-nginx/examples/PREREQUISITES/#tls-certificates</a></p>
<p>Checked the server certificate and the server key under /etc/nginx/secrets/default of the nginx-ingress Pod and they look correct. Here the output of the resource VirtualServer:</p>
<pre><code>NAME         STATE   HOST          IP             PORTS      AGE
vs-example   Valid   example.com   192.168.1.82   [80,443]   121m
</code></pre>
<p><strong>VirtualServer:</strong></p>
<pre><code>apiVersion: k8s.nginx.org/v1
kind: VirtualServer
metadata:
  name: vs-example
  namespace: nginx-ingress
spec:
  host: example.com
  tls:
    secret: example-tls
  upstreams:
  - name: example
    service: web-service
    port: 8080
    tls:
      enable: true
  routes:
  - path: /v2
    action:
      pass: example
  routes:
  - path: /
    action:
      pass: example
</code></pre>
<p><strong>Secret</strong></p>
<pre><code>apiVersion: v1
kind: Secret
metadata:
  name: example-tls
  namespace: nginx-ingress
data:
  tls.crt: (..omitted..)
  tls.key: (..omitted..)
type: kubernetes.io/tls
</code></pre>
<p><strong>Nginx.conf</strong></p>
<p>Here an extract of the nginx.conf taken from the running Pod:</p>
<pre><code>server {
    # required to support the Websocket protocol in VirtualServer/VirtualServerRoutes
    set $default_connection_header &quot;&quot;;
    listen 80 default_server;
    listen 443 ssl default_server;
    ssl_certificate /etc/nginx/secrets/default;
    ssl_certificate_key /etc/nginx/secrets/default;
    server_name _;
    server_tokens &quot;on&quot;;
</code></pre>
<p>Cannot find what's in going on when trying to reach the web application with HTTPS.</p>

Marco_81
<p>several errors in the VirtualServer, edited with these changes solved the problem:</p>
<pre><code>apiVersion: k8s.nginx.org/v1
kind: VirtualServer
metadata:
  name: vs-example
  namespace: nginx-ingress
spec:
  host: example.com
  tls:
    secret: example-tls

  upstreams:
  - name: example
    service: web-service
    port: 8080
#    tls:            --&gt; this caused the SSL issue in the upstream
#      enable: true

  routes:
  - path: /
    action:
      pass: example
  - path: /v1
    action:
      pass: example
</code></pre>
<p>accessing web application with HTTPS now works</p>
