Kubernetes with Docker unable to change from default port of 80
use "targetPort" to indicate what port your pod is listening on. Your yaml spec should be something like:
---apiVersion: v1kind: Servicemetadata: name: myAppspec: selector: app: myApp ports: - name: http port: 8080 targetPort: 8080 nodePort: 30001
After much trial and error I found the solution.
In line with what @johnharris85 and @Yuankun said about the IP Address needing to be set to 'any' rather than on the localhost, I found this article: http://blog.scottlogic.com/2016/09/05/hosting-netcore-on-linux-with-docker.html
The dotnet core app defaults to using the localhost network, and while running locally on a test machine, this works fine. However, running a dotnet app inside a Docker container means that the localhost network is restricted to within the container.
To solve this, I initially changed
options.Listen(IPAddress.Loopback, 8080);
to
options.Listen(IPAddress.Any, 8080);
However, I tested this locally and could not get the app to respond. I took this to mean that this was not a valid solution. This may have been a valid solution if I had tested it with a containerized app.
I then came across the aforementioned article and decided to try the following:
public static IWebHost BuildWebHost(string[] args) => WebHost.CreateDefaultBuilder(args) .UseStartup<Startup>() .UseUrls("http://*:8080") .Build();
This solved my problem and now my app is accessible through the Kubernetes endpoint.
Thanks to everyone who gave advice.