Disabling GKE load balancer in Kubernetes

August 22, 2016 by Maikel Hofman

For a project we run a kubernetes cluster using the Google Container Engine (GKE). GKE provides a lot functionality out of the box including automatic configuration of load balancer using the kubernetes ingress resources. When you configure an ingress resource in kubernetes it will automatically create an GLCB load balancer with an external IP adress and route traffice into the cluster according the rules you set in the ingress resource.

Now the problem in our system is that we use traefik as a load balancer inside our cluster to manage incoming HTTP traffic and don’t want to use the built in GCE load balancer. Traefik is then configured using the ingress resources. Doing it like this will lead to two load balancers in the system, the Google load balancer and the traefik one. To disable this behaviour there are 2 solutions.

Solution 1: Annotate ingress resources

It is possible to add the kubernetes.io/ingress.class annotation to specify which class load balancers should apply the rule. See the example below.

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: test-deployment
  annotations:
    kubernetes.io/ingress.class: "nginx"
spec:
  rules:
  - host: www.test.com
    http:
      paths:
      - backend:
          serviceName: wwww-service
          servicePort: 80

The above example will only create load balancer if the nginx addon is enabled. In our case this solution did not work and had to resort to solution 2 described below.

Solution 2: Disable Httploadbalancer addon in GKE

The second solution is to disable the load balancer addon in kubernetes. You can update a running cluster by using the following command. Beware that this will restart the master server.

gcloud container clusters update NAME HttpLoadBalancing=ENABLED|DISABLED

When creating the cluster it also possible to immediately disable the HttpLoadBalancing by using the –disable-addons flag as follows:

gcloud container clusters create NAME --disable-addons HttpLoadBalancing

References

© 2017 | Follow on Twitter | Hugo