Day 45: Deployment of a Microservices Application on K8s: Assignment-2

Day 45: Deployment of a Microservices Application on K8s: Assignment-2

Flask App Deployment

Recap

In our previous assignment - Mongo DB, we have gone through the basic topics from how to install Kubeadm on Master and worker nodes to deploying Mongo DB Service in Kubernetes cluster.

Today we will go through the steps on how to deploy a Flask App on Kubernetes cluster

Flask App Project

Master Node

To deploy the Flask application, we will write a Deployment YAML file- "flask-deploy.yml" and deploy it.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: flask
  labels:
    app: flask
spec:
  replicas: 2
  selector:
    matchLabels:
      app: flask
  template:
    metadata:
      labels:
        app: flask
    spec:
      containers:
        - name: flask
          image: aminchivilkar/flask-app:latest
          ports:
            - containerPort: 5000
          imagePullPolicy: Always

Command to deploy

kubectl apply -f flask.yml

After setting up outbound rules on EC2 instance dashboard, we can now access the deployed flask app:

We will do the same using the YAML file service "flask-svc.yml" and apply it.

apiVersion: v1
kind: Service
metadata:
  name: flask
spec:
  selector:
    app: flask
  type: NodePort
  ports:
  - protocol: TCP
    port: 80
    targetPort: 5000
    nodePort: 30007

Command to deploy

kubectl apply -f flask-svc.yml

Worker Node

We have successfully deployed the Flask app as mentioned above and Mongo DB as mentioned below using all the YAML files.

Both services (mongo and flask) are exposing port 80 and forwarding traffic to port 5000 on their respective pods. Additionally, the flask service has been configured as a NodePort service with nodePort 30007, which allows external access to the service on that port.

The services should be discoverable by these labels and should allow communication between the microservices using their service DNS names.

One thing to keep in mind is that using port 80 is common for HTTP traffic, but it might be occupied by other services. If you intend to expose your microservices to the internet, it's a good practice to use different port numbers for each service. This can help avoid port conflicts and make it easier to manage different services running on your cluster.


Conclusion:

In this project, we've successfully deployed Flask app and connected Mongo DB using service.

In short, both the service YAML files appears to be correct for connecting the microservices using service discovery.

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