DEV Community

Cover image for 1.Deploy Apache Web Server on Kubernetes Cluster
Thu Kha Kyawe
Thu Kha Kyawe

Posted on

1.Deploy Apache Web Server on Kubernetes Cluster

Lab Information

There is an application that needs to be deployed on Kubernetes cluster under Apache web server. The Nautilus 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.
Enter fullscreen mode Exit fullscreen mode

Note: The kubectl utility on jump_host has been configured to work with the kubernetes cluster.


Lab Solutions

Step 1: Create the Namespace

First, let's create the required namespace:

kubectl create namespace httpd-namespace-devops
Enter fullscreen mode Exit fullscreen mode

Verify the namespace was created:

kubectl get namespaces
Enter fullscreen mode Exit fullscreen mode

Step 2: Create the Deployment

Create a YAML file for the deployment. Let's create a file called httpd-deployment.yaml:

cat > httpd-deployment.yaml << EOF
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
EOF
Enter fullscreen mode Exit fullscreen mode

Apply the deployment:

kubectl apply -f httpd-deployment.yaml
Enter fullscreen mode Exit fullscreen mode

Step 3: Create the Service

Create a YAML file for the service. Let's create a file called httpd-service.yaml:

cat > httpd-service.yaml << EOF
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
EOF
Enter fullscreen mode Exit fullscreen mode

Apply the service:

kubectl apply -f httpd-service.yaml
Enter fullscreen mode Exit fullscreen mode

Step 4: Verify All Resources

Let's verify everything was created correctly:

Check the deployments:

kubectl get deployment -n httpd-namespace-devops
kubectl get pods -n httpd-namespace-devops
kubectl get service -n httpd-namespace-devops
kubectl get all -n httpd-namespace-devops
Enter fullscreen mode Exit fullscreen mode


Resources & Next Steps
📦 Full Code Repository: KodeKloud Learning Labs
💬 Join Discussion: DEV Community - Share your thoughts and questions
💼 Let's Connect: LinkedIn - I'd love to connect with you

Credits
• All labs are from: KodeKloud
• I sincerely appreciate your provision of these valuable resources.

Top comments (0)