This repo holds instructions and code to demonstrate a gRPC service that is load balanced in Kubernetes using a Gateway, implemented with traefik.
Minikube is used to run the demonstration locally.
By using the new Gateway API, GRPCRoute, and Traefik, gRPC services can be deployed and balanced. This gets past the need for tears.
-
Start the cluster. This will build a kubernetes cluster using a single node, locally. The method (Docker, VM, etc) is dependent on config and OS.
This will set your kubectl context to the minikube cluster.
minikube start
-
Enable addons
minikube addons enable dashboard minikube addons enable metrics-server
-
Start the dashboard. This will block the terminal it is run in and open a web browser.
minikube dashboard
-
Open a tunnel. This is used so the Gateway is accessible from the host machine. This also blocks the terminal it is run in.
minikube tunnel
- Follow the instructions here to install in the cluster.
- Configure Traefik to enable Gateway and not Ingress.
helm upgrade --install --version 36.2.0 --namespace default traefik traefik/traefik -f values.yaml
- Build an image for the server
docker build -f Dockerfile -t test-server .
- Add the image to the cluster (no remote downloads).
eval $(minikube docker-env -u) minikube image load test-server:latest
- Deploy
kubectl apply -f manifests.yml
- Get the IP of the Gateway
kubectl get Gateway traefik
- Add to /etc/hosts
123.123.123.123 echo.test
- Run the client
go run client/main.go
-
In the browser tab that minikube dashboard opened, open "Pods" and watch as requests are balanced across all 5 pods. It may take a couple minutes for the metrics to update.
-
Port forward directly to the service
kubectl port-forward svc/my-service 8000:8000
-
Run the client, pointed at the port forwarded.
go run client/main.go "localhost:8000"
Only one pod will get load now.
- Delete the cluster
minikube delete