<p>I am running a dotnet core app using Kubernetes with Docker.</p>

<p>The setup is as follows:</p>

<p><strong>APP</strong></p>

<p>In the dotnet core app, I have Kestrel server listening on port 8080 by setting the following in Program.cs:</p>

<pre><code>public static IWebHost BuildWebHost(string[] args) =&gt;
WebHost.CreateDefaultBuilder(args)
    .UseStartup&lt;Startup&gt;()
    .UseKestrel(options =&gt;
    {
        options.Listen(IPAddress.Loopback, 8080);
    })
    .Build();
</code></pre>

<p>I have tested the app build locally and the endpoint works as expected on <code>localhost:8080/api/test</code>.</p>

<p><strong>DOCKER IMAGE</strong></p>

<p>In the Dockerfile I have the following:</p>

<pre><code>EXPOSE 8080
</code></pre>

<p>I understand this to mean that the container gets built with an exposed 8080 port.</p>

<p>Question 1: ...does this necessarily mean that the container's 8080 is mapped to the app's 8080? If not, how do I map this?</p>

<p><strong>KUBERNETES (MINIKUBE)</strong></p>

<p>Within Kubernetes (running locally on Minikube), I then use a Replication Controller to create 3 pods that each contain 1 docker container with the app. My RC file looks like this:</p>

<pre><code>{
    "apiVersion": "v1",
    "kind": "ReplicationController",
    "spec": {
        "replicas": 3,
        "selector": {
            "app": "myApp"
        },
        "template": {
            "metadata": {
                "labels": {
                    "app": "myApp"
                }
            },
            "spec": {
                "containers": [
                    {
                        "name": "my-app",
                        "image": "myname/myapp:1.0",
                        "ports": [
                            {
                                "containerPort": 8080
                            }
                        ]
                    }
                ]
            }
        }
    }
}
</code></pre>

<p>Notice <code>"ports": [{ "containerPort": 8080 }]</code>. The way I understand it, this means that the container port I want to expose is 8080.</p>

<p>I then have a Kubernetes Service that exposes my 3 pods' 8080 ports through the endpoint <code>[minikubeIPAddress]:30001</code>:</p>

<pre><code>{
    "apiVersion": "v1",
    "kind": "Service",
    "spec": {
        "type": "NodePort",
        "ports": [
            {
                "port": 8080,
                "nodePort": 30001,
                "protocol": "TCP"
            }
        ],
        "selector": {
            "app": "myApp"
        }
    }
}
</code></pre>

<p>When I try to hit the endpoint <code>[minikubeIPAddress]:30001/api/test</code> I am getting a 'site can't be reached' error.</p>

<p><strong>I had it working this morning when I was using the default HTTP port 80.</strong> The only changes that have been made are to the port numbers.</p>

<p>Question 2: ...have I missed something here? Is there a connection along the line here that is still mapped to the default port of 80?</p>

<p>Any help would be much appreciated.</p>

<p>use "targetPort" to indicate what port your pod is listening on. Your yaml spec should be something like:</p>

<pre><code>---
apiVersion: v1
kind: Service
metadata:
  name: myApp
spec:
  selector:
    app: myApp
  ports:
  - name: http
    port: 8080
    targetPort: 8080
    nodePort: 30001
</code></pre>
