3

I am setting up Kubernetes cluster on Azure (using AKS) to host Elasticsearch, Kibana, custom api, UI, nginx, etc.

As I don't want separate public IP per service, I need a way to setup a common load balancer/Ingress and then just add the port numbers to there and setup routing.

I tried using the approach mentioned in this stackoverflow question - How to expose multiple port using a load balancer services in kubernetes but didn't work out.

As there are technology clients connecting to my cluster, I need to have service per technology.

Basically I need to expose 9200, 5601, 80 - all on same IP but on accessing the IP with port, user must be re-directed to appropriate technology service.

Below is sample configuration for what am looking for.

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: myingress
spec:
  rules:
  - host: myurl.domain.com
    http:
      paths:
      - path: /
        backend:
          serviceName: elasticsearch
          servicePort: 9200
      - path: /
        backend:
          serviceName: kibana
          servicePort: 5602

Any thoughts?

Sunil Agarwal
  • 4,097
  • 5
  • 44
  • 80
  • https://kubernetes.io/docs/concepts/services-networking/ingress/#simple-fanout – Sai Teja Pakalapati Apr 16 '19 at 04:49
  • am not looking for /url1 redirect to 5601 and /url2 redirect to 9200. What i need is, if url has port 5601, redirect to 5601 and same for 9200. Basically don't create public URL per service – Sunil Agarwal Apr 17 '19 at 19:09

3 Answers3

1

With your issue, the ingress is what you want. You can create all your services as you want. And expose the ports for your service. Then create the ingress with a public IP and create the ingress route that routes the access from the ingress to your backend services.

Take a look at the example in Create an ingress controller in Azure Kubernetes Service (AKS). It will show you what the steps need to be done. And if you have more questions please let me know.

Charles Xu
  • 29,862
  • 2
  • 22
  • 39
  • The answer is good, but the provided link is broken. Can you fix it? – dbourcet Apr 16 '19 at 14:51
  • 1
    @koudougou I'm sorry for that, fix it now. – Charles Xu Apr 17 '19 at 00:58
  • @CharlesXu: link you provided again talks about multiple domain/page redirect. What exactly i want is same url but redirect to service based on port provided. Do you have a sample for that or can you please redirect to some example. Also updated my question with sample of requirement – Sunil Agarwal Apr 17 '19 at 19:11
  • @SunilAgarwal What do you talk about? That's just one domain name exposed, and need a different backend. If not, how do you redirect to different services? – Charles Xu Apr 18 '19 at 00:59
  • I want a load balancer in front and then just redirect the external port to internal port (same way like docker swarm works). Why should i pay for multiple public IPs. Also think of hazzle developers/users will face to remember IP for each service. – Sunil Agarwal Apr 18 '19 at 14:36
  • @SunilAgarwal It seems you do not understand the ingress clearly. It just needs only one load balancer and public IP. See the path in the ingress, it routes the traffic to different services. – Charles Xu Apr 19 '19 at 01:22
  • Am new to Kubernetes. I know ingress will redirect to service. Can you please guide me to an example where it is doing routing traffic based on port & not on path. – Sunil Agarwal Apr 21 '19 at 05:46
  • @SunilAgarwal It's impossible to route the traffic just to one path with different ports. See the [issue](https://github.com/kubernetes/ingress-nginx/issues/1655) in GitHub. – Charles Xu Apr 22 '19 at 03:21
  • @SunilAgarwal Any more update? Still can not understand the ingress? – Charles Xu Apr 23 '19 at 02:44
  • I understand ingress but it's a BUG in Kubernetes for not having this simple feature. I thought K8 is better than Swarm but its not at least in this case. – Sunil Agarwal Apr 23 '19 at 20:01
  • An Ingress, without controller-specific extensions, seems to only work for HTTP-based services and are limited to listening on port 80 and 443... (Voyager (with a modified ingress schema), nginx-ingress (with a configmap with nginx config extracts) and ingress-nginx (with a configmap) supports it in non-standard ways) – Gert van den Berg Aug 26 '19 at 10:47
  • @GertvandenBerg, are nginx-ingress and ingress-nginx two different thing? and both of them have there own approach to support this (use port instead of url/path to direct the traffic to different backend service through ingress)? – Kangqiao Zhao Aug 14 '20 at 07:21
  • 1
    @KangqiaoZhao Yes. nginx-ingress has a comparison [here](https://github.com/nginxinc/kubernetes-ingress/blob/master/docs/nginx-ingress-controllers.md) (In most ways, ingress-nginx is superior to nginx-ingress, if you don't have a NGINX Plus license...) (nginx-ingress seems to have moved to custom resources for UDP / TCP, while ingrss-nginx uses a configmap (nginx-ingress used to use a different format configmap)) – Gert van den Berg Aug 15 '20 at 10:55
0

I just finished doing this on a mail server project using HAProxy ingress controller (https://github.com/helm/charts/tree/master/incubator/haproxy-ingress) in TCP mode. Works a treat. Working config can be found at https://github.com/funkypenguin/docker-mailserver/blob/fa9bd9c9ed9b66aa6ee1c36ca19a73c558682f24/helm-chart/docker-mailserver/values.yaml#L300

D

Funky Penguin
  • 179
  • 1
  • 6
0

Sorry i posted another similar question. Finally was able to solve with issue with simple tagging.

No extra tools/code required.

Please refer my post for answer : Kubernetes: Expose multiple services internally & externally

Sunil Agarwal
  • 4,097
  • 5
  • 44
  • 80