Deploy Apache Web Server on Kubernetes Cluster with Replicas

Introdcution

Apache is a popular open-source web server software that allows you to serve websites and other web content to users over the internet.

Kubernetes is a free and open source container management tool, we can deploy and manage containerized applications across a cluster of nodes. It provides features such as automated rollouts and rollbacks, self-healing, load balancing, and scaling, all of which make it easier to manage and scale containerized applications.

In this post, We will show you how to deploy apache web server on kubernestes cluster.

Step 1: Creating Apache Deployment YAML

We need to create the apache web server deployment yaml config file and where we can update the replica count and image version and other things.

nano apache-deployment.yaml

Paste the following configuration.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: apache
spec:
  replicas: 1
  selector:
    matchLabels:
      app: apache
  template:
    metadata:
      labels:
        app: apache
    spec:
      containers:
        - name: apache
          image: ubuntu/apache2:latest
          imagePullPolicy: "IfNotPresent"
          ports:
            - containerPort: 80

Step 2: Deploy Apache Web Server

We are good to deploy the apache web server on k8s resources by following the given commands.

To deploy the apache.

kubectl create -f apache-deployment.yaml

To validate the deployment.

kubectl get deployment

To validate the pods.

kubectl get pods

Step 3: Deploy Apache Service

We need to create the apache service yaml config to make accessible apache web server from network, Use the following command for the same.

nano apache-service.yaml

Paste the following configuration.

apiVersion: v1
kind: Service
metadata:
  name: apache-service
  labels:
    app: apache
spec:
  type: LoadBalancer
  ports:
   - port: 80
  selector:
   app: apache

We can replace the port number and network type as per your need.

To deploy the apache service.

kubectl create -f apache-service.yaml

To validate the apache service.

kubectl get svc

Step 4: Accessing Apache Web Server

We need to use the external IP address / dns name with port 80 to get apache web server on the browser.

Step 5: Scaling Apache Web Server

We need to edit and put the number of count of apache replicas in the apache-depoyment.yaml file.

To edit the apache-deployment.yaml file.

nano apache-deployment.yaml

Update the replica count like 5 online number 6.

  replicas: 5

To apply new change.

kubectl apply -f apache-deployment.yaml

To validate the apache running pods.

kubectl get pods

We can control the apache replicas count by using replicas count in apache-deployment.yaml file.

Step 6: Clean Up

If we want to destroy the apache resources, We can do that by following given commands.

To destroy apache service.

kubectl delete svc apache-service

To destroy apache deplyment.

kubectl delete deployment apache

Conclusion

We have successfully deployed the apache web server on the K8S cluster. If you are still facing problems, feel free to leave a commit. 

Author

Deploy Apache Web Server on Kubernetes Cluster with Replicas

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to top