LoadBalancer

This guide covers how to get service of type LoadBalancer working in a kind cluster using Cloud Provider KIND.

This guide complements Cloud Provider KIND installation docs.

Installing Cloud Provider KIND

Cloud Provider KIND can be installed using golang

  1. go install sigs.k8s.io/cloud-provider-kind@latest

or downloading one of the released binaries.

Cloud Provider KIND runs as a standalone binary in your host and connects to your KIND cluster and provisions new Load Balancer containers for your Services. It requires privileges to open ports on the system and to connect to the container runtime.

Using LoadBalancer

The following example creates a loadbalancer service that routes to two http-echo pods, one that outputs foo and the other outputs bar.

  1. kind: Pod
  2. apiVersion: v1
  3. metadata:
  4. name: foo-app
  5. labels:
  6. app: http-echo
  7. spec:
  8. containers:
  9. - name: foo-app
  10. image: hashicorp/http-echo:0.2.3
  11. args:
  12. - "-text=foo"
  13. ---
  14. kind: Pod
  15. apiVersion: v1
  16. metadata:
  17. name: bar-app
  18. labels:
  19. app: http-echo
  20. spec:
  21. containers:
  22. - name: bar-app
  23. image: hashicorp/http-echo:0.2.3
  24. args:
  25. - "-text=bar"
  26. ---
  27. kind: Service
  28. apiVersion: v1
  29. metadata:
  30. name: foo-service
  31. spec:
  32. type: LoadBalancer
  33. selector:
  34. app: http-echo
  35. ports:
  36. # Default port used by the image
  37. - port: 5678

Apply the contents

  1. kubectl apply -f https://kind.sigs.k8s.io/examples/loadbalancer/usage.yaml

Now verify that the loadbalancer works by sending traffic to it’s external IP and port.

  1. LB_IP=$(kubectl get svc/foo-service -o=jsonpath='{.status.loadBalancer.ingress[0].ip}')
  1. # should output foo and bar on separate lines
  2. for _ in {1..10}; do
  3. curl ${LB_IP}:5678
  4. done