Day 77: Project-6 (K8s)

AMIN CHIVILKARAMIN CHIVILKAR
5 min read

Introduction

This project focuses on the deployment of a Netflix Clone on a Kubernetes cluster, a widely used container orchestration platform that streamlines the management of containerized applications. The key tasks involve building Docker images for the web application and its prerequisites, followed by their deployment on the Kubernetes cluster through Kubernetes manifests. Leveraging Kubernetes delivers advantages like ensuring high availability, effortless scalability, and automatic failover for the application. Furthermore, the project will make use of Kubernetes tools such as kubectl, to supervise and govern the deployed application. In summary, this project serves as a demonstration of the robust capabilities and advantages of Kubernetes when it comes to deploying and managing containerized applications on a large scale.


Task-01

Get a Netflix clone from GitHub, and follow the below steps to deploy a Netflix Clone on the K8s cluster.


Step 1: Setup K8s cluster

Set up a Kubernetes cluster using Kubeadm.

Refer to the blog for complete instructions- Day 43: Deployment of a Microservices Application on K8s

Verify the connection using the command on the Master Node

kubectl get nodes

Step 2: Clone app from GitHub

Copy the Repository URL and us the clone command to clone the files from GitHub to Master node

git clone <URL_of_repository>

Step 3: Build an Image

Once the files are cloned, the image can be created using a docker file by command:

docker build -t amin/netflix-clone .

We have successfully created an image as mentioned below

Step 4: Push image

Log in to DockerHub, create a repository example- aminchivilkar/netflix-clone

Verify that the image you are trying to push is correctly tagged with the repository name. The tag should match your Docker Hub repository.

To re-tag an image, you can use the following command:

docker tag amin/netflix-clone:latest aminchivilkar/netflix-clone:latest
#docker tag local-image:tag dockerhub-repository:tag

Command to log in to DockerHub.

docker login -u username
#passsword prompt

Use the below command to push the image.

docker push aminchivilkar/netflix-clone:latest

The image is now on the DockerHub

Step 5: K8s Deployment

In Kubernetes (K8s), a deployment file is a configuration file that defines how to create and manage instances of your application. It specifies the desired state of your application, including the number of replicas, container images, and how updates should be rolled out. Deployment files are essential for orchestrating containerized applications in K8s.

Modify the Deployment file as per your requirements.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: netflix-app
  labels:
    app: netflix-app
spec:
  replicas: 2
  selector:
    matchLabels:
      app: netflix-app
  template:
    metadata:
      labels:
        app: netflix-app
    spec:
      containers:
      - name: netflix-app
        image: aminchivilkar/netflix-clone:latest
        ports:
        - containerPort: 80

To apply the configuration defined in the "deployment.yml" file use the below command.

It instructs K8s to create or update resources specified in the YAML file, such as deployments, pods, services, or other K8s objects. This command ensures that the desired state described in the YAML file is realized within the K8s cluster.

kubectl apply -f deployment.yml

Step 6: K8s Service

A "service.yml" file is used to define and create a Kubernetes Service object. A Service is an abstraction that enables network access to a set of Pods in K8s. This file specifies the desired state of the service, including details such as the type of service (ClusterIP, NodePort, LoadBalancer, or ExternalName), the selector for targeting pods, and port mappings.

 apiVersion: v1
 kind: Service
 metadata:
   name: netflix-app
   labels:
     app: netflix-app
 spec:
   type: NodePort
   ports:
   - port: 80
     targetPort: 80
     nodePort: 30007
   selector:
     app: netflix-app

The below command applies the configuration defined in the "service.yml" file to create or update a Kubernetes Service based on the specifications provided in the file. This command ensures that the desired state of the service is achieved within the K8s cluster, allowing for reliable network access to pods and load balancing of traffic.

kubectl apply -f service.yml

Step 7: Verify Deployment

The below commands will

  • Lists the Deployments within the current Kubernetes cluster.

  • Display the list of Pods running in the cluster.

  • Retrieve information about the Kubernetes Service named "netflix-app."

kubectl get deployment
kubectl get pods
kubectl get service netflix-app

Step 8: Access the application

Verify the application's availability by accessing the Public URL. Ensure that you've included a Custom TCP Rule for port 30007 on the worker node's security group. After adding the inbound rule, you should be able to access the Netflix Clone app through your web browser using the <worker_node_public_IP>:30007 address.

We have successfully deployed Netflix Clone in the Kubernetes Cluster.


Conclusion:

In this project, we've accomplished the deployment of a Netflix Clone on a Kubernetes cluster. This involved a series of tasks, including setting up the Kubernetes cluster, cloning the application from GitHub, building Docker images, pushing images to DockerHub, and defining deployment and service files. By following these steps, we've successfully demonstrated the power of Kubernetes for managing containerized applications. The Netflix Clone is now up and running, and it's accessible via the specified public URL. We hope you enjoyed this journey and found it informative.

Hope you like my post. Don't forget to like, comment, and share.

0
Subscribe to my newsletter

Read articles from AMIN CHIVILKAR directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

AMIN CHIVILKAR
AMIN CHIVILKAR

Experienced Sr. Member Technical with a demonstrated history of working in the human resources industry. Skilled in Python, AWS, Jenkins, K8s, Terraform and other DevOps tools. Strong professional with a Bachelor's degree focused in Computer Science from Abeda Inamdar Senior College - India.