looks like you've fallen into the manually configure kubernetes rabbits hole. One of the biggest issues with Kubernetes is there are millions of ways to get to the same outcome.
You're on the right track however it might be quicker for you to just get helm to drive everything for you.
TLDR answer
do we really need the ingressClassName or is that only needed if you
have multiple ingress controllers. Examples of defining a default
ingress class dont seem to reference nginx so no idea if they are
correct for what im doing (an example would be great)
I'm sure there are other ways to configure it where you don't but the method I would use would define the ingressClassName as nginx.
does the backend.service.port refer to the incoming port number or the
port the service is running on? I would ideally forward anything on
port 80 or 443 to the service which is on port 8080
The backend service is the port that the docker container runs on. You don't really need to worry about this as kubernetes can deal with all that for you.
Longer winded answer
If you install using helm, you'll have an option to use a values.yaml file during install. This file is where all the knobs you're after live. The values.yaml file will vary based on which helm repo you choose to install. It looks like you're using the NGINX official repo, you can find the official values.yaml here.
First thing to do is download a local copy of that file and edit it to suit your purposes. I suggest trying to use it with as few edits as possible first - I have just pulled that version and applied it to my dev cluster and applications like podinfo worked immediately.
Now for the non-obvious bit - there are a couple of ways to publish a service:
- URL route ie. test.com/myapp
- DNS named application ie. myapp.test.com
My personal preference is to use DNS names but it depends on your use case.
Lets use podinfo to demonstrate how to configure an application to use ingress-nginx as its ingress.
URL Route
- Download podinfo's values.yaml and save it locally.
- Edit the values.yaml file and find the
ingress: section. This is going to be a common section amongst most/all helm charts you install.
- Add a host to your ingress as follows, making sure to add the path you wish to have ingress-nginx serve the application from.
ingress:
enabled: true
className: "nginx"
annotations:
kubernetes.io/ingress.class: nginx
hosts:
- host: test.com
paths:
- path: /podinfo
pathType: ImplementationSpecific
- Once you've added this to your podinfo values.yaml you need to install the podinfo helm chart as follows:
helm upgrade --install --wait podinfo --namespace podinfo --values values.yaml oci://ghcr.io/stefanprodan/charts/podinfo
- After a short while you should see an ingress appear in the podinfo namespace:
root@dev:~# kubectl get ingress -n podinfo -o yaml
apiVersion: v1
kind: List
items:
- apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
annotations:
kubernetes.io/ingress.class: nginx
meta.helm.sh/release-name: podinfo
meta.helm.sh/release-namespace: podinfo
labels:
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: podinfo
app.kubernetes.io/version: 6.3.5
helm.sh/chart: podinfo-6.3.5
name: podinfo
namespace: podinfo
spec:
ingressClassName: nginx
rules:
- host: test.com
http:
paths:
- backend:
service:
name: podinfo
port:
number: 9898
path: /podinfo
pathType: ImplementationSpecific
status:
loadBalancer:
ingress:
- ip: 10.20.20.100
Note that the output shows the path and host value correctly and that up in the annotations the ingress.class is set to nginx which is what tells nginx to serve up this content.
DNS Route
This method is almost exactly the same as the method above except that in the values.yaml file you leave the path as a / and the host is the dns name you wish to use for the application like this:
ingress:
enabled: true
className: "nginx"
annotations:
kubernetes.io/ingress.class: nginx
hosts:
- host: podinfo.test.com
paths:
- path: /
pathType: ImplementationSpecific
Once you've applied this values.yaml you should see the following:
root@dev:~# kubectl get ingress -n podinfo -o yaml
apiVersion: v1
kind: List
items:
- apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
annotations:
kubernetes.io/ingress.class: nginx
meta.helm.sh/release-name: podinfo
meta.helm.sh/release-namespace: podinfo
labels:
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: podinfo
app.kubernetes.io/version: 6.3.5
helm.sh/chart: podinfo-6.3.5
name: podinfo
namespace: podinfo
spec:
ingressClassName: nginx
rules:
- host: podinfo.test.com
http:
paths:
- backend:
service:
name: podinfo
port:
number: 9898
path: /
pathType: ImplementationSpecific
status:
loadBalancer:
ingress:
- ip: 10.20.20.100
I hope this helps. One of my favourite how to websites for Kubernetes is The Geek Cookbook by David Young. His site has some very well documented examples showing useful applications to have on your K8S stack and most importantly how to configure them.