Kubernetes NGINX NodePort 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 NodePort

Expose the deployment to create a NodePort Service:

kubectl expose deployment/nginx --type=NodePort --port=8888 --target-port=80 --name=nginx-np

Step 5: Check the NodePort Service

Verify the status of the Service and cluster nodes:

kubectl get service nginx-np
kubectl get nodes -o wide

Step 6: Retrieve the Cluster IP

Get the Cluster IP of the NodePort Service:

kubectl get svc nginx-np

Step 7: Get Pod Names

List all running Pods:

kubectl get pod

Step 8: Access a Pod

Enter a specific Pod for testing purposes:

kubectl exec -it <pod name> -- /bin/bash

Step 9: Test the Deployment Internally

From inside a Pod, try accessing the NGINX Service using the Cluster IP:

curl http://<cluster ip>:8888

Step 10: Cleanup

Remove the Deployment and Service when you're done:

kubectl delete deployment nginx
kubectl delete service nginx-np