https://github.com/surajkumar4-source/first_deployment_in_k8s
This guide covers deploying an HTTPD server in Kubernetes, exposing it via a NodePort service for external access, and scaling it up or down to handle varying loads efficiently.
https://github.com/surajkumar4-source/first_deployment_in_k8s
deployment-services k8s-cluster kubectl nodeport scalling
Last synced: 4 months ago
JSON representation
This guide covers deploying an HTTPD server in Kubernetes, exposing it via a NodePort service for external access, and scaling it up or down to handle varying loads efficiently.
- Host: GitHub
- URL: https://github.com/surajkumar4-source/first_deployment_in_k8s
- Owner: Surajkumar4-source
- Created: 2024-11-13T15:34:55.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-01-28T17:06:38.000Z (over 1 year ago)
- Last Synced: 2025-06-01T19:18:27.260Z (12 months ago)
- Topics: deployment-services, k8s-cluster, kubectl, nodeport, scalling
- Homepage:
- Size: 510 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Deploying and Exposing an HTTPD Server Using 'kubectl'
### This guide walks through creating a deployment for an HTTPD server (`suraj-app`) and exposing it using a NodePort service to enable external access.
### The steps also include scaling the deployment up and down to handle varying loads.
## Follow the Steps to Implement
### 1. Create the Deployment
- To start, create a deployment named `suraj-app` using the official `httpd` image.
```yml
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.*
### 2. Expose the Deployment via NodePort Service.
- Expose the deployment to allow external access through a NodePort service.
```yml
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.*
### 3. Verify the NodePort
- To confirm the assigned NodePort and external accessibility details, use:
```yml
kubectl get svc suraj-service
```
*Look under the PORT(S) column to see the NodePort assigned, which will look like 80:/TCP.*
### 4. Access the Service Externally
- Access the service from outside the cluster using the cluster node's IP and the assigned NodePort. For example:
```yml
http://:
```
*Replace with your cluster's external IP and with the actual port obtained from the previous step.*
### 5. Scale the Deployment
- Adjust the deploymentโs number of replicas as needed to manage workload:
#### a. Scale Up
- To increase the number of replicas to 10:
```yml
kubectl scale deployment suraj-app --replicas=10
```
*This command scales up the deployment, creating additional pods for suraj-app.*
- Verify the scaling:
```yml
kubectl get deployment suraj-app
kubectl get pods -o wide
```
#### b. Scale Down
- To decrease the replicas to 5:
```yml
kubectl scale deployment suraj-app --replicas=5
```
- Verify the new count:
```yml
kubectl get deployment suraj-app
kubectl get pods -o wide
```
## Explanation of Scaling
- 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.*
## ------------------Screnshots--------------------
1.

2.

3.

4.

5.

6.

7.
### Final Output: *at localhost*

**๐จโ๐ป ๐๐ป๐ช๐ฏ๐ฝ๐ฎ๐ญ ๐ซ๐**: [Suraj Kumar Choudhary](https://github.com/Surajkumar4-source) | ๐ฉ **๐๐ฎ๐ฎ๐ต ๐ฏ๐ป๐ฎ๐ฎ ๐ฝ๐ธ ๐๐ ๐ฏ๐ธ๐ป ๐ช๐ท๐ ๐ฑ๐ฎ๐ต๐น**: [csuraj982@gmail.com](mailto:csuraj982@gmail.com)