<p>I can't connect to my app running with nginx ingress (Docker Desktop win 10).</p>

<p>The nginx-ingress controller pod is running, the app is healthy, and I have created an ingress. However, when I try to connect to my app on localhost, I get "connection refused".</p>

<p>I see this error in the log:</p>

<pre><code>[14:13:13.028][VpnKit            ][Info   ] vpnkit.exe: Connected Ethernet interface f6:16:36:bc:f9:c6

[14:13:13.028][VpnKit            ][Info   ] vpnkit.exe: UDP interface connected on 10.96.181.150

[14:13:22.320][GoBackendProcess  ][Info   ] Adding vpnkit-k8s-controller tcp forward from 0.0.0.0:80 to 10.96.47.183:80
[14:13:22.323][ApiProxy          ][Error  ] time="2019-12-09T14:13:22-05:00" msg="Port 443 for service ingress-nginx is already opened by another service"
</code></pre>

<p>I think port 443 is used by another app, possibly zscaler security or skype.
Excerpt from <code>netstat -a -b</code>:</p>

<pre><code> [svchost.exe]
  TCP    0.0.0.0:443            0.0.0.0:0              LISTENING       16012
 [com.docker.backend.exe]
  TCP    0.0.0.0:443            0.0.0.0:0              LISTENING       8220
</code></pre>

<p>I don't know how to make the ingress work. Please help!</p>

<p>My ingress:</p>

<pre><code>$ kubectl describe ing kbvalues-deployment-dev-ingress
Name:             kbvalues-deployment-dev-ingress
Namespace:        default
Address:          localhost
Default backend:  default-http-backend:80 (&lt;none&gt;)
Rules:
  Host       Path  Backends
  ----       ----  --------
  localhost
             /   kbvalues-deployment-dev-frontend:28000 (10.1.0.174:8080)
Annotations:
  kubernetes.io/ingress.class:                     nginx
  nginx.ingress.kubernetes.io/cors-allow-headers:  X-Forwarded-For, X-app123-XPTO
Events:
  Type    Reason  Age               From                      Message
  ----    ------  ----              ----                      -------
  Normal  CREATE  42m               nginx-ingress-controller  Ingress default/kbvalues-deployment-dev-ingress
  Normal  UPDATE  6s (x5 over 42m)  nginx-ingress-controller  Ingress default/kbvalues-deployment-dev-ingress
</code></pre>

<p>My service:</p>

<pre><code>$ kubectl describe svc kbvalues-deployment-dev-frontend
Name:              kbvalues-deployment-dev-frontend
Namespace:         default
Labels:            chart=tomcat-sidecar-war-1.0.4
                   environment=dev
                   name=kbvalues-frontend-dev
                   release=kbvalues-test
                   tier=frontend
Annotations:       &lt;none&gt;
Selector:          app=kbvalues-dev
Type:              ClusterIP
IP:                10.98.89.94
Port:              &lt;unset&gt;  28000/TCP
TargetPort:        8080/TCP
Endpoints:         10.1.0.174:8080
Session Affinity:  None
Events:            &lt;none&gt;
</code></pre>

<p>I am trying to access the app at: <code>http://localhost:28000/health</code>. I verified that the <code>/health</code> URL is accessible locally within the web server container.</p>

<p>I appreciate any help you can offer.</p>

<p><strong>Edit:</strong></p>

<p>I tried altering the ingress-nginx service to remove HTTPS, as suggested here:
<a href="https://stackoverflow.com/a/56303330/166850">https://stackoverflow.com/a/56303330/166850</a></p>

<p>This got rid of the 443 error in the logs, but didn't fix my setup (still getting connection refused).</p>

<p><strong>Edit 2:</strong> Here is the Ingress YAML definition (kubectl get -o yaml):</p>

<pre><code>$ kubectl get ing -o yaml
apiVersion: v1
items:
- apiVersion: extensions/v1beta1
  kind: Ingress
  metadata:
    annotations:
      kubernetes.io/ingress.class: nginx
    creationTimestamp: "2019-12-09T18:47:33Z"
    generation: 5
    name: kbvalues-deployment-dev-ingress
    namespace: default
    resourceVersion: "20414"
    selfLink: /apis/extensions/v1beta1/namespaces/default/ingresses/kbvalues-deployment-dev-ingress
    uid: 5c34bf7f-1ab4-11ea-80e4-00155d169409
  spec:
    rules:
    - host: localhost
      http:
        paths:
        - backend:
            serviceName: kbvalues-deployment-dev-frontend
            servicePort: 28000
          path: /
  status:
    loadBalancer:
      ingress:
      - hostname: localhost
kind: List
metadata:
  resourceVersion: ""
  selfLink: ""
</code></pre>

<p><strong>Edit 3:</strong> Output of <code>kubectl get svc -A</code> (ingress line only):</p>

<pre><code>ingress-nginx   ingress-nginx                      LoadBalancer   10.96.47.183     localhost     80:30470/TCP             21h
</code></pre>

<p><strong>Edit 4:</strong> I tried to get the VM's IP address from windows HyperV, but it seems like the VM doesn't have an IP?</p>

<pre><code>PS C:\&gt; (Get-VMNetworkAdapter -VMName DockerDesktopVM)

Name            IsManagementOs VMName          SwitchName MacAddress   Status IPAddresses
----            -------------- ------          ---------- ----------   ------ -----------
Network Adapter False          DockerDesktopVM DockerNAT  00155D169409 {Ok}   {}
</code></pre>

<p><strong>Edit 5:</strong></p>

<p>Output of <code>netstat -a -n -o -b</code> for port 80:</p>

<pre><code>  TCP    0.0.0.0:80             0.0.0.0:0              LISTENING       4
 Can not obtain ownership information
</code></pre>

<p>I have managed to create Ingress resource in Kubernetes on Docker in Windows.</p>
<p><strong>Steps to reproduce</strong>:</p>
<ul>
<li>Enable Hyper-V</li>
<li>Install Docker for Windows and enable Kubernetes</li>
<li>Connect kubectl</li>
<li>Enable Ingress</li>
<li>Create deployment</li>
<li>Create service</li>
<li>Create ingress resource</li>
<li>Add host into local hosts file</li>
<li>Test</li>
</ul>
<h3>Enable <a href="https://learn.microsoft.com/pl-pl/virtualization/hyper-v-on-windows/quick-start/enable-hyper-v" rel="noreferrer">Hyper-V</a></h3>
<p>From Powershell with administrator access run below command:</p>
<p><code>Enable-WindowsOptionalFeature -Online -FeatureName  Microsoft-Hyper-V -All</code></p>
<p>System could ask you to reboot your machine.</p>
<h3>Install Docker for Windows and enable Kubernetes</h3>
<p>Install Docker application with all the default options and enable Kubernetes</p>
<h3>Connect kubectl</h3>
<p>Install <a href="https://kubernetes.io/docs/tasks/tools/install-kubectl/#install-kubectl-on-windows" rel="noreferrer">kubectl </a>.</p>
<h3>Enable Ingress</h3>
<p>Run this commands:</p>
<pre><code>kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/static/mandatory.yaml
</code></pre>
<pre><code>kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/static/provider/cloud-generic.yaml
</code></pre>
<h3><strong>Edit:</strong> Make sure no other service is using port 80</h3>
<p>Restart your machine. From a <code>cmd</code> prompt running as admin, do:
<code>net stop http</code>
Stop the listed services using <code>services.msc</code></p>
<p>Use: <code>netstat -a -n -o -b</code> and check for other processes listening on port 80.</p>
<h3>Create deployment</h3>
<p>Below is simple deployment with pods that will reply to requests:</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: hello
spec:
  selector:
    matchLabels:
      app: hello
      version: 2.0.0
  replicas: 3
  template:
    metadata:
      labels:
        app: hello
        version: 2.0.0
    spec:
      containers:
      - name: hello
        image: &quot;gcr.io/google-samples/hello-app:2.0&quot;
        env:
        - name: &quot;PORT&quot;
          value: &quot;50001&quot;
</code></pre>
<p>Apply it by running command:</p>
<p><code>$ kubectl apply -f file_name.yaml</code></p>
<h3>Create service</h3>
<p>For pods to be able for you to communicate with them you need to create a service.</p>
<p>Example below:</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: v1
kind: Service
metadata:
  name: hello-service
spec:
  type: NodePort
  selector:
    app: hello
    version: 2.0.0
  ports:
  - name: http
    protocol: TCP
    port: 80
    targetPort: 50001
</code></pre>
<p>Apply this service definition by running command:</p>
<p><code>$ kubectl apply -f file_name.yaml</code></p>
<h3>Create Ingress resource</h3>
<p>Below is simple Ingress resource using service created above:</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: hello-ingress 
spec:
  rules:
  - host: hello-test.internal
    http:
      paths:
      - path: /
        backend:
          serviceName: hello-service 
          servicePort: http
</code></pre>
<p>Take a look at:</p>
<pre class="lang-yaml prettyprint-override"><code>spec:
  rules:
  - host: hello-test.internal 
</code></pre>
<p><code>hello-test.internal </code> will be used as the <code>hostname</code> to connect to your pods.</p>
<p>Apply your Ingress resource by invoking command:</p>
<p><code>$ kubectl apply -f file_name.yaml</code></p>
<h3>Add host into local hosts file</h3>
<p>I found this <a href="https://github.com/docker/for-win/issues/1901" rel="noreferrer">Github link </a> that will allow you to connect to your Ingress resource by <code>hostname</code>.</p>
<p>To achieve that add a line <code>127.0.0.1 hello-test.internal</code> to your <code>C:\Windows\System32\drivers\etc\hosts</code> file and save it.
You will need Administrator privileges to do that.</p>
<p><strong>Edit:</strong> The newest version of Docker Desktop for Windows already adds a hosts file entry:
<code>127.0.0.1 kubernetes.docker.internal</code></p>
<h3>Test</h3>
<p>Display the information about Ingress resources by invoking command:
<code>kubectl get ingress</code></p>
<p>It should show:</p>
<pre><code>NAME            HOSTS                 ADDRESS     PORTS   AGE
hello-ingress   hello-test.internal   localhost   80      6m2s
</code></pre>
<p>Now you can access your Ingress resource by opening your web browser and typing</p>
<p><code>http://kubernetes.docker.internal/</code></p>
<p>The browser should output:</p>
<pre><code>Hello, world!
Version: 2.0.0
Hostname: hello-84d554cbdf-2lr76
</code></pre>
<p><code>Hostname: hello-84d554cbdf-2lr76</code> is the name of the pod that replied.</p>
<p>If this solution is not working please check connections with the command:
<code>netstat -a -n -o </code>
(<strong>with Administrator privileges</strong>) if something is not using port 80.</p>
