Expose a kubernetes deployment (frontend) using ingress controller

白昼怎懂夜的黑 提交于 2019-12-29 09:32:31

问题


I am deploying a number of docker containers of micro-services and angular frontend on Kubernetes. I have exposed the services using an ingress controller specifying each service using this, and specifying paths in backend.

apiVersion: extensions/v1beta1
kind: Ingress

For my frontend, I have created a service with type loadbalancer.

apiVersion: v1
kind: Service
metadata:
  annotations:
    service.beta.kubernetes.io/azure-load-balancer-resource-group: my-resource-group
  name: myapp-svc
  namespace: ui
spec:
  loadBalancerIP: SOME_IP_ADDRESS
  type: LoadBalancer
  ports:
  - port: 80
 selector:
   app: myapp

This works fine but now I have two IP addresses, one for the UI loadbalancer, and other of the ingress controller (for APIs).

Can I do this with just one IP address?

How can I expose the UI using ingress controller itself without creating external loadbalancer?


回答1:


Try this way -

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/rewrite-target: /$1
    nginx.ingress.kubernetes.io/service-upstream: "true"
  name: rule-name
  namespace: default
spec:
  rules:
  - host: hostname
    http:
      paths:
      - backend:
          serviceName: frontend-service
          servicePort: port-number
        path: /(.*)
      - backend:
          serviceName: backend-service
          servicePort: port-number
        path: /api/(.*)

You can use the above defined strategy where you can directly map front end at / and use rewrite-target to map anything like hostname/api to backend service.

You can keep frontend and backend services at clusterIP level only



来源:https://stackoverflow.com/questions/58604021/expose-a-kubernetes-deployment-frontend-using-ingress-controller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!