如何通过入口在具有同一主机的 kubernetes 中公开多个应用程序
How to expose multiple application in kubernetes with same host via ingress
我有两个独立的应用程序,我通过 helm 部署并且有不同的 SCM repository.I 想使用 Openstack Loadbalancer DNS 通过入口公开它们。我的目标是访问两个应用程序,例如应用程序 1 的 hostname:8000 和应用程序 2 的 hostname:8080。
有没有办法通过 traefik 或 kubernetes 来处理这个问题?
应用程序 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: []
应用程序 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: []
如果你只有一个主机
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
多个主机
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
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
我有两个独立的应用程序,我通过 helm 部署并且有不同的 SCM repository.I 想使用 Openstack Loadbalancer DNS 通过入口公开它们。我的目标是访问两个应用程序,例如应用程序 1 的 hostname:8000 和应用程序 2 的 hostname:8080。
有没有办法通过 traefik 或 kubernetes 来处理这个问题?
应用程序 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: []
应用程序 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: []
如果你只有一个主机
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
多个主机
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
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