Search code examples
kubernetesnetwork-programmingkubernetes-ingressnginx-ingress

Ingress with IP address instead of host


I'm self-hosting a few applications on my NAS, like tt-rss. I normally run them with docker-compose. To access an app like this when I'm not on my local network, I point a port of my home router to the port of my NAS where the app is running, and then I can just access the app through htpp://public_ip_router_here:port_number/tt-rss.

I decided to move these apps to a k8s cluster. For "fun", but also because I can setup my ingress controller to do the TLS termination, and I would unlock https for all my apps.

The cluster is running (provisioned with microk8s). TLS works too, with some conditions:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: fanout-ingress
spec:
  ingressClassName: nginx
  rules:
  - host: fancy_domain.com
    http:
      paths:
      - backend:
          service:
            name: api
            port:
              number: 8080
        path: /
        pathType: ImplementationSpecific
  tls:
  - hosts:
    - fancy_domain.com
    secretName: tls-secret

If I modify my /etc/hosts file (I run Linux), and put this inside:

192.168.0.203 fancy_domain.com

I can access my service through https://fancy_domain.com. This works perfectly, but it's a bit annoying because it would force me to modify my /etc/hosts file on all the devices I use. Is there a way to use an IP address instead of hostname? Or any workaround really, as long as I can do the fanout and keep the TLS termination.

I tried something like this but weirdly, I'm getting a 404 error then:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: minimal-ingress
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /
spec:
  ingressClassName: nginx-example
  rules:
  - http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: api
            port:
              number: 8080
  tls:
  - hosts:
    - 192.168.0.203
    secretName: tls-secret

Solution

  • Well I can't use an IP in the ingress, but:

    • I created a self-signed certificate for a random domain name
    • I put the certificate into a secret
    • I built my ingress using the random domain name
    • I modified the /etc/hosts files of all the devices that had to access the domain name. On Android, "Virtual Hosts" works like a charm

    This works perfectly for a test setup.