semural
semural

Reputation: 4601

How to expose multiple application in kubernetes with same host via ingress

I have a two independent application which I deployed via helm and have different SCM repository.I would like to expose both of them via ingress using Openstack Loadbalancer DNS. my aim is to access both application such as hostname:8000 for application 1 and hostname:8080 for application2.

Is there any way to handle this via traefik or kubernetes?

Application 1

service:
  type: NodePort
  port: 8000

networkPolicy:
  enabled: true

ingress:
  enabled: true
  annotations:
    kubernetes.io/ingress.class: traefik
  hosts:
    - host: hostname -> just for example
      paths: [/]
  tls: []

Application 2

service:
  type: NodePort
  port: 8080

networkPolicy:
  enabled: true

ingress:
  enabled: true
  annotations:
    kubernetes.io/ingress.class: traefik
  hosts:
    - host: hostname -> just for example
      paths: [/]
  tls: []

Upvotes: 1

Views: 4315

Answers (2)

Arghya Sadhu
Arghya Sadhu

Reputation: 44549

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: samehostexample
  annotations:
    kubernetes.io/ingress.class: traefik
    traefik.frontend.rule.type: PathPrefixStrip
spec:
  rules:
  - host: hostname.com
    http:
      paths:
      - path: /service1path
        backend:
          serviceName: service1
          servicePort: 8000
      - path: /service2path
        backend:
          serviceName: service2
          servicePort: 8080

Upvotes: 4

Harsh Manvar
Harsh Manvar

Reputation: 30083

If you have single host

apiVersion: extensions/v1beta1
    kind: Ingress
    metadata:
      name: staging-ingress
      annotations:
        kubernetes.io/ingress.class: "nginx"
    spec:
      rules:
      - host: test.example.com
        http:
          paths:
          - path: /
            backend:service-1
              servicePort: 80
          - path: /api
            backend:
              serviceName: service-2
              servicePort: 80

Multiple hosts

spec:
  rules:
  - host: test-webapp-example.com
    http:
      paths:
        - path: /
          backend:
            serviceName: test-webapp-example
            servicePort: 80
  - host: test-another-example.com
    http:
      paths:
        - path: /
          backend:
            serviceName: test-webapp-somethingelse
            servicePort: 80

Upvotes: 4

Related Questions