# Project : KubeFlix: Deploying a Netflix Clone on Kubernetes

Project Objective : The project aims to deploy a Netflix clone web application on a Kubernetes cluster, leveraging containerization and Kubernetes manifests for streamlined deployment and management. Utilizing Kubernetes benefits, including high availability, scalability, and automatic failover, the project will showcase the power of Kubernetes for efficiently deploying and managing containerized applications at scale while emphasizing enhanced reliability and performance.

Prerequisite :

Before getting started, ensure you have set up three EC2 instances: one for the master and two for the nodes. Follow the steps in this script to set up Kubernetes:

[https://github.com/patelajay745/Scripts/blob/main/k8sss.sh](https://github.com/patelajay745/Scripts/blob/main/k8sss.sh)

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690871149356/00ac09cd-5aa8-4be2-96d2-4844bbfa404a.png align="center")

Let's get started.

we will be using this github repo for this project : [https://github.com/patelajay745/netflix-clone-react-typescript](https://github.com/patelajay745/netflix-clone-react-typescript)

Step 1 : clone the project into master :

step 2 : there will be Dockerfile so you can create docker image using this code.

```bash
docker build --build-arg TMDB_V3_API_KEY=your_api_key_here -t netflix-clone .
```

you can get api key from here : [https://developer.themoviedb.org/docs/getting-started](https://developer.themoviedb.org/docs/getting-started)

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690874062836/626559ef-6360-472c-8915-8fa82021c55e.png align="center")

step 3 : upload created docker image to dockerhub.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690874126278/555c47ee-604d-4698-8493-fb07289cfe82.png align="center")

If you are facing problem in uploading image to dockerhub you can follow this blog :  
[https://myproject.ltd/project2](https://myproject.ltd/project2)

or you can use my created docker image using this url : [https://hub.docker.com/repository/docker/patelajay745/netflix-clone/general](https://hub.docker.com/repository/docker/patelajay745/netflix-clone/general)

step 4 : ***Now create the Deployment yaml file.***

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690874596930/1ef12939-33e1-4ad2-9901-d05c0a93bab3.png align="center")

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

step 5 : ***Run and check the successful running of Deployment in the instance.***

```bash
kubectl apply -f deployment.yml
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690874718936/2d4fa896-32e3-4633-8a42-cbfddda92d57.png align="center")

step 6: Create my-service.yml using following command

```bash
apiVersion: v1
kind: Service
metadata:
  name: my-service
spec:
  type: NodePort
  selector:
    app: netflix
  ports:
      # By default and for convenience, the `targetPort` is set to the same value as the `port` field.
    - port: 80
      targetPort: 80
      # Optional field
      # By default and for convenience, the Kubernetes control plane will allocate a port from a range (default: 30000-32767)
      nodePort: 30007
```

Apply the service YAML file with the following command:

```bash
kubectl apply -f my-service.yml
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1691133289773/e2cc2c08-98d7-46fe-b516-cf20b4469ac9.png align="center")

Verify the status of your pods with:

```bash
kubectl get pods
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1691133394532/d0665efa-8f68-4dae-ae1f-e3630e0de9dd.png align="center")

Finally, access your Netflix clone application using the following URL:

https://&lt;publicIP-node:30008&gt;

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1691133501389/789c6285-2a81-45b1-a13c-c98f091e914e.png align="center")

**Conclusion:**

In this project, we successfully deployed a Netflix clone web application on a Kubernetes cluster. By containerizing the application and leveraging Kubernetes manifests, we demonstrated how Kubernetes offers high availability, scalability, and automatic failover, providing enhanced reliability and performance for containerized applications.
