Say you've deployed your application on a server somewhere on AWS. Now what?
The "phonebook of the internet"
www.example.com
123.123.123.123
Problem: what IP do we use for our domain? What if we just used the IP of a single backend machine?
We can still only use a single IP, but we have some use cases to address:
We need a reverse proxy / load balancer
Forward Proxy
Reverse Proxy
From the client's perspective, they're talking directly to your application
There are various ways to determine how to load balance:
What if a backend server crashes?
GET /health
Health checks are also used in Kubernetes to determine if a pod is erroring.
server { listen 80; server_name example.com; location / { proxy_pass http://localhost:3000; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; } }
Define an upstream group:
upstream backend { server 10.0.1.10:3000; server 10.0.1.11:3000; server 10.0.1.12:3000; } server { listen 80; location / { proxy_pass http://backend; } }
upstream backend { server 10.0.1.10:3000 max_fails=3 fail_timeout=30s; server 10.0.1.11:3000 max_fails=3 fail_timeout=30s; server 10.0.1.12:3000 max_fails=3 fail_timeout=30s; }
max_fails=3
fail_timeout=30s
server { listen 80; location /api/ { proxy_pass http://api-backend; } location /static/ { root /var/www; } location / { proxy_pass http://frontend-backend; } }
You have services running in Kubernetes pods. How does external traffic reach them?
http://auth-service
api.example.com
https://medium.com/google-cloud/kubernetes-nodeport-vs-loadbalancer-vs-ingress-when-should-i-use-what-922f010849e0
How do we expose nginx to the internet?
apiVersion: v1 kind: Service metadata: name: nginx-loadbalancer annotations: service.beta.kubernetes.io/aws-load-balancer-type: "nlb" spec: type: LoadBalancer selector: app: nginx ports: - protocol: TCP port: 80 targetPort: 80
The LoadBalancer Service acts as the bridge:
app: nginx
upstream auth { server auth-service:80; } server { listen 80; location /auth/ { proxy_pass http://auth; } }
my-nlb-url.com/auth/login
nginx
/auth/
Note: Add diagram showing: DNS → AWS NLB → LoadBalancer Service → nginx pods → backend services