Kubernetes - Running load balancer in HA and using DNS to access application

9/11/2017

I am having load balancer (LB) running as pod on three hosts (node-A, node-B and node-C) in Kubernetes. The LB is being used by GitLab service which is running on port 80. GitLab is running on node-C and i'm able to access it using public IP of node-B. node-B is where i initially setup load balancer (HAProxy) using Replication Controller.

Snippet here:

[root@cent-gluster-workstation service-loadbalancer]# cat rc.yaml
apiVersion: v1
kind: ReplicationController
metadata:
  name: service-loadbalancer
  labels:
    app: service-loadbalancer
    version: v1
spec:
  replicas: 3
  selector:
    app: service-loadbalancer
    version: v1

Complete detail is present here

Here are the issues:
1) I cannot access GitLab using any other node's public IP. Is this expected? If LB is running on all three nodes, then shouldn't the GitLab app be accessible using any node's public IP on port 80?

2) I would like to configure the LBs in a way that i could access them using a 'single' DNS name, for example, gitlab.test.com. I am wondering how this can be done. Will the DNS be mapped to service somehow (and if yes, how?) or to the pods that the service manages?

I am using Google Cloud right now for testing but i am looking for a way which is not cloud-provider specific as the actual setup will be running in-house on VMs. Best would be if i could get my current HAProxy (or NGinx if HAProxy is not feasible) work.

Any help will really be appreciated.

-- Technext
haproxy
kubernetes
nginx

1 Answer

9/11/2017

Problem is that you are not using your haproxy cluster to reach your gitlab instance, but you are reaching gitlab directly.

Let's assume your haproxy is configured correctly, you need to expose it using a service of type Load balancer, exactly as you did with gitlab. You need then to turn the gitlab service into a NodePort because you don't need to expose it to the internet with a load balancer (haproxy will be exposed and proxy the request). Finally, please be aware that you need to use the loadbalancer IP address to reach your instance, not your node addresses. To get the IP simply run kubectl get svc.

As a sidenote, since I guess you want to have one instance of haproxy running in every node of your cluster, you could use a DaemonSet instead of a ReplicationController which is intended for this exact scope.

-- whites11
Source: StackOverflow