Kubernetes NGINX LoadBalancer Deployment Guide

Step 1: Optional - Allow Deployment on Control Plane Nodes

If you want to allow deployments on control plane nodes (not required for most setups), run the following command:

kubectl taint nodes --all node-role.kubernetes.io/control-plane-

Step 2: Create the Deployment

Deploy the NGINX application:

kubectl create deployment nginx --image=nginx

Step 3: Scale the Deployment

Scale the NGINX Deployment to 3 replicas:

kubectl scale deployment/nginx --replicas=3

Step 4: Expose the Deployment Using a LoadBalancer

Expose the deployment to create a LoadBalancer Service:

kubectl expose deployment/nginx --type=LoadBalancer --port=80 --target-port=80 --name=nginx-lb

This exposes port 80, mapping to port 80 on NGINX. Change --port=XX to your preferred external port.

Step 5: Check the LoadBalancer Service

Verify the status of the Service:

kubectl get service nginx-lb

Step 6: Retrieve the External IP

Get the External IP of the LoadBalancer Service:

kubectl get svc nginx-lb

Step 7: Test the Deployment

Access the NGINX service using the External IP:

curl http://<external ip>

Step 8: Cleanup

Remove the Deployment and Service when you're done:

kubectl delete deployment nginx
kubectl delete service nginx-lb