Kubernetes Assignment Deploying Flask-Microservices and Reddit Clone Application.
๐ถ Task-1. Deployment of a Microservices Application on K8s
- Do Mongo Db Deployment
- Do Flask App Deployment
- Connect both using Service Discovery
Make 2 instances of t2.medium, master and worker node.
Use the following commands to both the master and worker server.
sudo apt update
sudo apt-get install -y apt-transport-https ca-certificates curl
sudo apt install docker.io -y
sudo systemctl enable --now docker
# Adding GPG keys.
curl -fsSL "https://packages.cloud.google.com/apt/doc/apt-key.gpg" | sudo gpg --dearmor -o /etc/apt/trusted.gpg.d/kubernetes-archive-keyring.gpg
# Add the repository to the sourcelist.
echo 'deb https://packages.cloud.google.com/apt kubernetes-xenial main' | sudo tee /etc/apt/sources.list.d/kubernetes.list
sudo apt update
sudo apt install kubeadm=1.20.0-00 kubectl=1.20.0-00 kubelet=1.20.0-00 -y
Use the following command to master server.
sudo su
kubeadm init
# To start using your cluster, you need to run the following as a regular user:
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
# Alternatively, if you are the root user, you can run:
export KUBECONFIG=/etc/kubernetes/admin.conf
kubectl apply -f https://github.com/weaveworks/weave/releases/download/v2.8.1/weave-daemonset-k8s.yaml
kubeadm token create --print-join-command
To connect the worker node use the print join command token to the worker node server append with --v=5
To install and run the application on your Kubernetes cluster, follow these steps:
Clone this repository to your local machine.
Navigate to the project root directory.
Create a Kubernetes deployment and service by running the following command:
kubectl apply -f <yml files.yml
Add Inbound rules 30007 in the security group of your deployment server
๐ถ Task-2. Deployment of a Reddit-Clone Application
- Do Deployment of Reddit Clone app
- Write an ingress controller for the same to give a custom route
# First all update system and install Docker
sudo apt-get update
sudo apt-get install docker.io -y
sudo usermod -aG docker $USER && newgrp docker
# To install Minikube & Kubectl
curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
sudo install minikube-linux-amd64 /usr/local/bin/minikube
sudo snap install kubectl --classic
minikube start --driver=docker
Follow these steps to install and run the Reddit clone app on your machine:
- Clone this repository to your local machine:
git clone
https://github.com/niluflip/reddit-clone-k8s-ingress.git
- Build the Docker image for the Reddit clone app:
docker build -t nileshsahare/reditt-clone:latest .
Edit your deployment.yml file with your image.
apiVersion: apps/v1
kind: Deployment
metadata:
name: reddit-clone-deployment
labels:
app: reddit-clone
spec:
replicas: 2
selector:
matchLabels:
app: reddit-clone
template:
metadata:
labels:
app: reddit-clone
spec:
containers:
- name: reddit-clone
image: nileshsahare/reditt-clone:latest
ports:
- containerPort: 3000
Login to your Docker Hub by using your username and password and push your image to Docker Hub
docker push nileshsahare/reditt-clone:latest
Deploy the app to Kubernetes by using
kubectl apply -f deployment.yml
kubectl apply -f service.yml
kubectl apply -f ingress.yml
#check pod services and deployment
kubectl get pods
kubectl get deployment
kubectl get services
#expose our deployment by using
kubectl expose deployment reddit-clone-deployment --type=NodePort
#expose our app service
kubectl port-forward svc/reddit-clone-service 3000:3000 --address 0.0.0.0
Add Inbound rules 3000 in the security group of your deployment server
Check the application on the server
EC2ServerIP:Port
Check the application on the server with your ec2 server IP https://34.232.78.175:3000/
Happy Learning :)
If you find my blog valuable, I invite you to like, share, and join the discussion. Your feedback is immensely cherished as it fuels continuous improvement. Let's embark on this transformative DevOps adventure together! ๐ #devops #90daysofdevop #git&github #kubernetes