4

I am using Traefik as Kubernetes Ingress and I would like to know if I can use an IP address instead of a domain name. Example:

http://ipaddress/service1
http://ipdadress/service2

My ingress configuration:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: service1
  namespace: staging
  annotations:
    kubernetes.io/ingress.class: traefik
    traefik.frontend.rule.type: PathPrefixStrip
spec:
  rules:
  - host: mydomain.dev
    http:
      paths:
      - path: /service1
        backend:
          serviceName: service1
          servicePort: 3000
Rico
  • 58,485
  • 12
  • 111
  • 141
cleitond
  • 43
  • 1
  • 4

2 Answers2

13

Since it is a Layer 7 Load Balancer you can't use IP address directly. But if you use nip.io and for example 192-168-1-1.nip.io as your hostname it would work and you can do all the things you can regularly do with normal hostnames such as redirect app1.192-168-1-1.nip.io to app1 and 192-168-1-1.nip.io/app2 to app2 etc.

Akin Ozer
  • 1,001
  • 6
  • 14
  • [sslip.io](https://sslip.io/) would allow for defining custom domains, i.e. when you own your own domain. Here you need to specify their nameservers for the sub-domain you want to use though. In case you use Cloudflare this feature is unfortunately locked behind a business account which you need to pay currently 200$/month. For a homelab i.e. this is unfortunately way to much – Roman Vottner Aug 19 '22 at 12:30
1

I have done this with kong but i believe it should also work with traefik, by simply removing the host. unfortunately now you can't access it with the domain name

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: service1
  namespace: staging
  annotations:
    kubernetes.io/ingress.class: traefik
    traefik.frontend.rule.type: PathPrefixStrip
spec:
  rules:
  # - host: mydomain.dev
   - http:
      paths:
      - path: /service1
        backend:
          serviceName: service1
          servicePort: 3000

Hope it helps!

odilo
  • 21
  • 3
  • This solved it for my use case. I just duplicated my rule and dropped the `host` from the second one so now it resolves by IP address as well. My use case was that I need to access smokeping but sometimes the DNS is out! So thanks for sharing this method. – Joe Still Oct 05 '22 at 18:26