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

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.

kind: Pod
apiVersion: v1
metadata:
  name: foo-app
  labels:
    app: http-echo
spec:
  containers:
  - command:
    - /agnhost
    - serve-hostname
    - --http=true
    - --port=8080
    image: registry.k8s.io/e2e-test-images/agnhost:2.39
    name: foo-app
---
kind: Pod
apiVersion: v1
metadata:
  name: bar-app
  labels:
    app: http-echo
spec:
  containers:
  - command:
    - /agnhost
    - serve-hostname
    - --http=true
    - --port=8080
    image: registry.k8s.io/e2e-test-images/agnhost:2.39
    name: bar-app
---
kind: Service
apiVersion: v1
metadata:
  name: foo-service
spec:
  type: LoadBalancer
  selector:
    app: http-echo
  ports:
  - port: 5678
    targetPort: 8080

Apply the contents

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.

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