How can I expose my kubernetes app in a nice domain name using ingress?

8/29/2018

I installed both the nginx-ingress and cassandra helm charts onto AWS. I created a Route53 record so I can reach the loadbalancer at a nice DNS name such as k8s.mydomain.me.

If I create an ingress record with the following spec:

spec:
  rules:
  - host: 
    http:
      paths:
      - path: /cassandra
        backend:
          serviceName: cassandra
          servicePort: 9042

k8s.mydomain.me/cassandra resolves, but what I'd really want is cassandra.k8s.mydomain.me:9042 to resolve instead. How would I get that to work?

-- Mike
kubernetes
kubernetes-ingress
nginx

2 Answers

8/30/2018

What you need is an ingress rule that is based on the HTTP Host header.

You'll need to create a CNAME record set on route 53 that point to your load balancer : cassandra.k8s.mydomain.me -> k8s.mydomain.me

Then create the ingress rule without specifying a path :

spec:
  rules:
  - host: 'cassandra.k8s.mydomain.me'
    http:
      paths:
        backend:
          serviceName: cassandra
          servicePort: 9042
-- Jean-Philippe Bond
Source: StackOverflow

8/30/2018

I believe by default Nginx Ingress uses port 80 and 443. So if you really want to use port 9042 externally, you will need to reconfigure your nginx-ingress

Personally I like the fact that my nginx-ingress uses port 80, so that I never have to specify the port.

Single-Domain

spec:
  rules:
  - host: 'cassandra.k8s.mydomain.me'
    http:
      paths:
      - path: /
        backend:
          serviceName: cassandra
          servicePort: 9042

Multi-Domain

spec:
  rules:
  - host: 'cassandra.k8s.mydomain.me'
    http: &cassandra_svc
      paths:
      - path: /
        backend:
          serviceName: cassandra
          servicePort: 9042
  - host: 'real.cassandra.k8s.mydomain.me'
    http: *cassandra_svc
-- yosefrow
Source: StackOverflow