Our course you can check :- Udemy course
Ques:-
There is an application that needs to be deployed on Kubernetes cluster under Apache web server. Application development team has asked the DevOps team to deploy it. We need to develop a template as per requirements mentioned below:
Create a namespace named as httpd-namespace-devops.
Create a deployment named as httpd-deployment-devops under newly created namespace. For the deployment use httpd image with latest tag only and remember to mention the tag i.e httpd:latest, and make sure replica counts are 2.
Create a service named as httpd-service-devops under same namespace to expose the deployment, nodePort should be 30004.
Ans:-
Here's a complete Kubernetes manifest template that fulfills the requirements you've described:
raj@jumphost ~$ cat pod.yaml
apiVersion: v1
kind: Namespace
metadata:
name: httpd-namespace-devops
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: httpd-deployment-devops
namespace: httpd-namespace-devops
spec:
replicas: 2
selector:
matchLabels:
app: httpd-app
template:
metadata:
labels:
app: httpd-app
spec:
containers:
- name: httpd-container
image: httpd:latest
ports:
- containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
name: httpd-service-devops
namespace: httpd-namespace-devops
spec:
type: NodePort
selector:
app: httpd-app
ports:
- protocol: TCP
port: 80
targetPort: 80
nodePort: 30004
raj@jumphost ~$ kubectl apply -f pod.yaml
namespace/httpd-namespace-devops created
deployment.apps/httpd-deployment-devops created
service/httpd-service-devops created
raj@jumphost ~$ kubectl get all -n httpd-namespace-devops
NAME READY STATUS RESTARTS AGE
pod/httpd-deployment-devops-7b796fdd95-6xqfz 1/1 Running 0 26s
pod/httpd-deployment-devops-7b796fdd95-wstn9 1/1 Running 0 26s
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/httpd-service-devops NodePort 10.96.165.52 <none> 80:30004/TCP 26s
NAME READY UP-TO-DATE AVAILABLE AGE
deployment.apps/httpd-deployment-devops 2/2 2 2 26s
NAME DESIRED CURRENT READY AGE
replicaset.apps/httpd-deployment-devops-7b796fdd95 2 2 2 26s
raj@jumphost ~$
Ensure both pods are in Running
state and the service is exposing port 30004
.
Access the app in your browser at:
http://<NodeIP>:30004
Replace <NodeIP>
with your Kubernetes node’s external IP.
Conclusion:-
Learn how to deploy an Apache HTTPD web server on a Kubernetes cluster using a hands-on YAML template. In this step-by-step tutorial, we’ll cover:
- Creating a custom namespace for DevOps teams
- Building a deployment with the
httpd:latest
image and 2 replicas - Exposing the deployment using a NodePort service on port
30004
This video is perfect for DevOps engineers, Kubernetes beginners, and anyone looking to understand real-world deployment scenarios. By the end, you’ll be able to confidently deploy web applications on Kubernetes using best practices.
No comments:
Post a Comment