This guide walks through creating a deployment for an HTTPD server (suraj-app
) and exposing it using a NodePort service to enable external access.
- To start, create a deployment named
suraj-app
using the officialhttpd
image.
kubectl create deployment suraj-app --image=httpd
This command initializes a deployment named suraj-app using the HTTPD image, which serves as our web server.
- Expose the deployment to allow external access through a NodePort service.
kubectl expose deployment suraj-app --type=NodePort --port=80 --name=suraj-service
This command creates a service named suraj-service that allows external traffic on port 80 by assigning a random NodePort.
- To confirm the assigned NodePort and external accessibility details, use:
kubectl get svc suraj-service
Look under the PORT(S) column to see the NodePort assigned, which will look like 80:/TCP.
- Access the service from outside the cluster using the cluster node's IP and the assigned NodePort. For example:
http://<NODE_IP>:<NodePort>
Replace <NODE_IP> with your cluster's external IP and with the actual port obtained from the previous step.
- Adjust the deployment’s number of replicas as needed to manage workload:
- To increase the number of replicas to 10:
kubectl scale deployment suraj-app --replicas=10
This command scales up the deployment, creating additional pods for suraj-app.
- Verify the scaling:
kubectl get deployment suraj-app
kubectl get pods -o wide
- To decrease the replicas to 5:
kubectl scale deployment suraj-app --replicas=5
- Verify the new count:
kubectl get deployment suraj-app
kubectl get pods -o wide
- Scaling Up: Creates more pods to distribute the load and ensure high availability.
- Scaling Down: Reduces the number of running pods, saving resources when demand is lower.
This setup deploys a scalable HTTPD server accessible from outside the cluster, allowing you to manage the web server load efficiently.
👨💻 𝓒𝓻𝓪𝓯𝓽𝓮𝓭 𝓫𝔂: Suraj Kumar Choudhary | 📩 𝓕𝓮𝓮𝓵 𝓯𝓻𝓮𝓮 𝓽𝓸 𝓓𝓜 𝓯𝓸𝓻 𝓪𝓷𝔂 𝓱𝓮𝓵𝓹: csuraj982@gmail.com