An open API service indexing awesome lists of open source software.

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.

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.



![Alt text for image](screenshots/1.png)

2.



![Alt text for image](screenshots/3.png)

3.



![Alt text for image](screenshots/4.png)

4.



![Alt text for image](screenshots/5.png)

5.



![Alt text for image](screenshots/6.png)

6.



![Alt text for image](screenshots/7.png)

7.

### Final Output: *at localhost*


![Alt text for image](screenshots/2.png)








**๐Ÿ‘จโ€๐Ÿ’ป ๐“’๐“ป๐“ช๐“ฏ๐“ฝ๐“ฎ๐“ญ ๐“ซ๐”‚**: [Suraj Kumar Choudhary](https://github.com/Surajkumar4-source) | ๐Ÿ“ฉ **๐“•๐“ฎ๐“ฎ๐“ต ๐“ฏ๐“ป๐“ฎ๐“ฎ ๐“ฝ๐“ธ ๐““๐“œ ๐“ฏ๐“ธ๐“ป ๐“ช๐“ท๐”‚ ๐“ฑ๐“ฎ๐“ต๐“น**: [csuraj982@gmail.com](mailto:csuraj982@gmail.com)