Project-5: π Deploying a Netflix Clone App on Kubernetes with Kubeadm π¬
Day 84: #90DaysOfDevOps Challange
Introduction π
In this project, we will walk you through the process of deploying a Netflix clone web application on a Kubernetes cluster using Kubeadm. Kubernetes is a powerful container orchestration platform that simplifies the deployment and management of containerized applications, providing benefits like high availability, scalability, and automatic failover. We will create Docker images of the web application and its dependencies, deploy them onto the Kubernetes cluster using Kubernetes manifests, and explore the Kubernetes Dashboard and kubectl for monitoring and management. Let's get started! π
Prerequisites π οΈ
Before diving into the deployment, make sure you have the following:
Basic knowledge of Docker and Kubernetes concepts.
A working Kubernetes cluster set up with Kubeadm. For setting up Kubernetes on AWS EC2, follow this guide.
Clone the Netflix Clone app from GitHub.
git clone https://github.com/crazy-man22/netflix-clone-react-typescript.git
Step 1: Containerize the Netflix Clone App π³
Let's start by containerizing the Netflix Clone app using Docker. Create a Dockerfile in the root directory of our application with the following content:
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 and push it to Docker Hub (replace <your_dockerhub_username>
with your Docker Hub username):
docker build -t <your_dockerhub_username>/my_netflixapp_image .
docker push <your_dockerhub_username>/my_netflixapp_image
Step 2: Deployment Manifest π
Now, let's create a Kubernetes deployment manifest to deploy the Netflix Clone app. Create a file named deployment.yml
with the following content:
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: <your_dockerhub_username>/my_netflixapp_image
ports:
- containerPort: 80
Apply the deployment manifest to the Kubernetes cluster:
kubectl apply -f deployment.yml
Step 3: Service Manifest βοΈ
Next, let's create a Kubernetes service manifest to expose the Netflix Clone app. Create a file named service.yml
with the following content:
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
Apply the service manifest to the Kubernetes cluster:
kubectl apply -f service.yml
Step 4: Verify the Deployment βοΈ
To ensure that the Netflix Clone app is successfully deployed, let's check the status of the deployment and service:
kubectl get deployment
kubectl get pods
kubectl get service netflix-app
You should see two pods running, and the service should be exposed on port 30007.
Step 5: Access the Netflix Clone App π₯οΈ
Now that the app is deployed, you can access it using the NodePort exposed on your Kubernetes cluster. Here's how to enable external access to the NodePort on AWS EC2:
Find the Worker Nodes' Security Group: Go to AWS EC2 Console > Instances > Select worker nodes > Note the associated security group.
Add an Inbound Rule to the Security Group: In the security group details, add a new inbound rule:
Type: Custom TCP Rule
Port Range: Specify the NodePort used in the service manifest (e.g., 30007).
Source: Set to "Anywhere" (0.0.0.0/0) for unrestricted access or define specific IP ranges for more control.
Save the rule to apply the changes.
With the inbound rule added, the Netflix Clone app should now be accessible via <worker_node_external_ip>:30007
in your web browser.
For production environments, consider using LoadBalancer or Ingress controllers for enhanced security and SSL termination.
Step 6: Monitoring and Management π
Kubernetes provides several tools for monitoring and managing applications. You can use the Kubernetes Dashboard and kubectl
to check pod logs, scale the deployment, and more. Additionally, set up monitoring and logging solutions for better visibility into your app's performance.
Conclusion π
Congratulations! π You have successfully deployed a Netflix Clone app on Kubernetes using Kubeadm. We covered containerizing the app with Docker, creating Kubernetes deployment and service manifests, and verifying the deployment. Kubernetes offers powerful features for scaling and managing containerized applications, making it an excellent choice for deploying apps at scale. Explore more of Kubernetes' capabilities to further enhance your deployment!
Now you can enjoy your Netflix Clone app running seamlessly on Kubernetes! πΏπ₯
Feel free to explore the Netflix Clone React TypeScript Repository to get the complete source code and continue your learning journey with Kubernetes and containerization. Happy coding! ππ