Deploy Nginx Web Server on Kubernetes Cluster

Ticker

6/recent/ticker-posts

Deploy Nginx Web Server on Kubernetes Cluster

Question Some of the Nautilus team developers are developing a static website and they want to deploy it on Kubernetes cluster. They want it to be highly available and scalable. Therefore, based on the requirements, the DevOps team has decided to create deployment for it with multiple replicas. Below you can find more details about it:

Create a deployment using nginx image with latest tag only and remember to mention tag i.e nginx:latest and name it as nginx-deployment. App labels should be app: nginx-app and type: front-end. The container should be named as nginx-container; also make sure replica counts are 3.

Also create a service named nginx-service and type NodePort. The targetPort should be 80 and nodePort should be 30011.

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


Please Note :-  Perform the below commands based on your question  server,  user name & other details might differ . So please read task carefully before executing. All the Best 👍

Solution:  

1. At first  check existing deployment and  pods running status   

    kubectl get namespace

    kubectl get pods


2.  Create YAML  file with all the parameters, you can copy form GitLab

    https://gitlab.com/nb-tech-support/devops.git

    Refer Below Video for more clarity )

thor@jump_host /$ vi /tmp/nginx.yml

thor@jump_host /$ cat /tmp/nginx.yml

apiVersion: v1

kind: Service

metadata:

  name: nginx-service

spec:

  type: NodePort

  selector:

    app: nginx-app

    type: front-end

  ports:

    - port: 80

      targetPort: 80

      nodePort: 30011

---

apiVersion: apps/v1

kind: Deployment

metadata:

  name: nginx-deployment

  labels:

    app: nginx-app

    type: front-end

spec:

  replicas: 3

  selector:

    matchLabels:

      app: nginx-app

      type: front-end

  template:

    metadata:

      labels:

        app: nginx-app

        type: front-end

    spec:

      containers:

        - name: nginx-container

          image: nginx:latest

thor@jump_host /$

 3. Run below command to create pod 

 thor@jump_host /$ kubectl create -f /tmp/nginx.yml

service/nginx-service created

deployment/nginx-deployment created

thor@jump_host /$ 

 4.  Wait for pods to get running status 


thor@jump_host /$ kubectl get pods

NAME        READY   STATUS    RESTARTS   AGE

nginx-deployment-56cdb5d774-49rqs      1/1     Running   0          34s

nginx-deployment-56cdb5d774-6q8b2     1/1     Running   0          34s

nginx-deployment-56cdb5d774-nfwfp      1/1     Running   0          34s

thor@jump_host /$

5.  Validate the task by running below command 

 kubectl exec nginx-deployment-56cdb5d774-49rqs  -- curl http://localhost

 6.  Click on Finish & Confirm to complete the task successfully

Happy Learning!!!!

 Apart from this if you need more clarity,  I have made a  tutorial video on this , 

please go through and share your comments. Like and share the knowledge


Post a Comment

0 Comments

Latest Posts

Kodekloud Server's Login Credentials