A load balancer distributes incoming requests across multiple instances or endpoints of a microservice. This spreads traffic and lets healthy replicas continue serving requests when one instance fails. section 11.4.4 section 11.1
In a Kubernetes deployment, a load balancer supports these operational goals:
- Expose a service outside the cluster by assigning an accessible IP address. section 6.11.4
- Distribute requests across replicated microservice instances. section 11.4.4
- Redirect requests to other instances while Kubernetes restarts a failed instance. section 11.4.4
- Improve continuity without eliminating the need to log and investigate failures. section 11.4.4
Expose a microservice on Azure Kubernetes
Set a Kubernetes Service to type LoadBalancer, select the deployed microservice, and map external port 80 to the container's port 4000. Azure then creates a load balancer and allocates an IP for HTTP testing. Treat this as a deliberate exposure: the service becomes reachable from outside the cluster and can receive attacks or abuse. section 6.11.4
Listing 6.2 Deploying our microservice to Kubernetes on Azure
apiVersion: apps/v1
kind: Deployment
metadata:
name: video-streaming
spec:
replicas: 1
selector:
matchLabels:
app: video-streaming
template:
metadata:
labels:
app: video-streaming
spec:
containers:
- name: video-streaming
image: bmdk1.azurecr.io/video-streaming:1 #1
imagePullPolicy: IfNotPresent #2
env:
- name: PORT
value: "4000"
---
apiVersion: v1
kind: Service
metadata:
name: video-streaming
spec:
selector:
app: video-streaming
type: LoadBalancer #3
ports:
- protocol: TCP
port: 80
targetPort: 4000
Use the deployment listing to inspect the Service selector, LoadBalancer type, external port, and target container port together. section 6.11.4

