Project 5 - Day 84 Deploying a Netflix Clone App on Kubernetes with Kubeadm

Project 5 - Day 84 Deploying a Netflix Clone App on Kubernetes with Kubeadm

Project Description

The project involves deploying a Netflix clone web application on a Kubernetes cluster, a popular container orchestration platform that simplifies the deployment and management of containerized applications. The project will require creating Docker images of the web application and its dependencies and deploying them onto the Kubernetes cluster using Kubernetes manifests. The Kubernetes cluster will provide benefits such as high availability, scalability, and automatic failover of the application. Additionally, the project will utilize Kubernetes tools such as Kubernetes Dashboard and Kubectl to monitor and manage the deployed application. Overall, the project aims to demonstrate the power and benefits of Kubernetes for deploying and managing containerized applications at scale.

Kubernetes Kubeadm Cluster setup

Log in to the AWS console and create 3 EC2 instance

To setup Kubeadm use this link

The Kubeadm Cluster setup is ready

Let's clone the Netflix clone repo from GitHub

git clone https://github.com/rjthapaa/netflix-clone-react-typescript.git

Docker file of Netflix Clone app

FROM node:16.17.0-alpine as builder
WORKDIR /app
COPY ./package.json .
COPY ./yarn.lock .
RUN yarn install
COPY . .
ARG TMDB_V3_API_KEY
ENV VITE_APP_TMDB_V3_API_KEY=${TMDB_V3_API_KEY}
ENV VITE_APP_API_ENDPOINT_URL="https://api.themoviedb.org/3"
RUN yarn build

FROM nginx:stable-alpine
WORKDIR /usr/share/nginx/html
RUN rm -rf ./*
COPY --from=builder /app/dist .
EXPOSE 80
ENTRYPOINT ["nginx", "-g", "daemon off;"]

Build the Docker image with the Dockerhub tag and push it to Docker Hub

docker build . -t <your_dockerhub_username>/netfliximage 
docker build . -t rjthapaa/netfliximage

Pull the newly created Netflix image to the docker hub

docker push <your_dockerhub_username>/netfliximage
docker push rjthapaa/netfliximage

Pushed image in DockerHub

Deploying the Netflix app using a manifest file

apiVersion: apps/v1
kind: Deployment
metadata:
  name: netflix-deployment
  labels:
    app: netflix-app
spec:
  replicas: 3
  selector:
    matchLabels:
      app: netflix-app
  template:
    metadata:
      labels:
        app: netflix-app
    spec:
      containers:
      - name: netflix-app
        image: rjthapaa/netfliximage
        ports:
        - containerPort: 80

Apply the deployment manifest to the Kubernetes cluster:

kubectl apply -f deployment.yml

# check the deployment 
$ kubectl get deployment

# List the Pods running on which instance IP
$ kubectl get pods -o wide

Service manifest for the Netflix app

Let's create a Kubernetes service manifest to expose the Netflix Clone app. Create a file named service.yml

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

A node port exposes the service on a static port on the node IP address. NodePorts are in the 30000-32767 range by default, which means a NodePort is unlikely to match a service's intended port (for example, 8080 may be exposed as 31020).

Apply the service manifest to the Kubernetes cluster:

$ kubectl apply -f service.yml

# list the services
$ kubectl het svc

Netflix Clone app is successfully deployed, let's check the status of the deployment and service

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

Access the Netflix Clone App

AnyPublicIPmaster/workernode:30007

You can access the service within the Cluster using Nodeport Cluster-IP with Port 80

Delete all the Deployment and services after the use

kubectl delete deployment <deployment name>
kubectl delete service <service name>
kubectl delete all -all