简体   繁体   中英

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

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?

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM