Sitemap

Scaling our Docker Container using Kubernetes: End-to-End Series (Part — 6)

4 min readMar 23, 2021

--

By Hemanka Sarmah

Press enter or click to view image in full size

In our previous article, we used Docker to containerize our web app. Now, we will look at how to deploy docker containers in Kubernetes.

Also, Check out our Article on:

  1. Data Abstraction: End-to-End Series (Part — 1)
  2. Data Preprocessing and EDA: End-to-End Series (Part — 2)
  3. Model Building and Experimentation: End-to-End Series (Part — 3)
  4. Creating a WebApp using Flask+Gunicorn on Ubuntu Server: End-to-End Series (Part — 4)
  5. Containerizing the WebApp using Docker: End-to-End Series (Part — 5)
  6. Automating building and deployment using Jenkins: End-to-End Series (Part — 7)

Pushing docker image to docker hub

  • We will push our docker image to the docker hub so that the Kubernetes cluster could pull the image from the hub and add the container to the pod.

→ Tag the image with the docker hub username

docker tag <imagename> <Dockerhub_username>/<imagename>:latest
Press enter or click to view image in full size

→ Push to docker hub

  • Once the newly tagged image is created, we will then push that image to the hub.
docker push <Dockerhub_username>/<imagename>:latest
Press enter or click to view image in full size
Press enter or click to view image in full size

Enabling the Kubernetes in docker desktop

  • Open your docker desktop
Press enter or click to view image in full size
  • go to settings > Kubernetes
Press enter or click to view image in full size
  • Enable Kubernetes
  • Apply and Restart
Press enter or click to view image in full size

Creating YAML file

  • We will create a flask.YAML file.
apiVersion: apps/v1
kind: Deployment
metadata:
name: flask-demo
namespace: default
spec:
replicas: 1
selector:
matchLabels:
bb: web
template:
metadata:
labels:
bb: web
spec:
containers:
- name: flask
image: abhigyan97/flask-app:1.0
---
apiVersion: v1
kind: Service
metadata:
name: flask-entrypoint
namespace: default
spec:
type: NodePort
selector:
bb: web
ports:
- port: 8000
targetPort: 8000
nodePort: 30001

Deploying to Kubernetes

  • Open CLI and navigate to the folder location containing all the files and type the below command.
kubectl apply -f flask.yaml
Press enter or click to view image in full size
  • To confirm if your pod is running or not, run the command
kubectl get deployments

Ready indicates that 1 out of 1 pods are running, if it’s 0/1 that means your pod has crashed.

Press enter or click to view image in full size
  • Now, go to your browser and in the search bar type:
localhost:<nodeport>

The node port will the one mentioned in our YAML file, which is 30001 in our case.

Press enter or click to view image in full size

Deleting pod

After deployment, if you want to delete your pod.

  • Run the command to look at all the pods running.
kubectl get pods --all-namespaces

the name that we gave to our pod in the flask.yaml file was flask-demo

Press enter or click to view image in full size
  • Now, select the pod you want to delete and run the command.
kubectl delete deployment <pod_name>
Press enter or click to view image in full size

Follow us for more upcoming future articles related to Data Science, Machine Learning, and Artificial Intelligence.

Also, Do give us a Clap👏 if you find this article useful as your encouragement catalyzes inspiration for and helps to create more cool stuff like this.

Visit us on https://www.insaid.co/

About Accredian

Enjoyed this read? Take the next step. Curiosity brought you this far, let Accredian take you further. Partnering with top global institutes, Accredian brings you rigorous, relevant, and impactful programs. Designed for professionals serious about growing, upskilling, and leading with confidence.

If this article sparked something in you, imagine what the right program could do. Discover what’s possible at Accredian.

--

--

Accredian Publication
Accredian Publication

Written by Accredian Publication

One of India’s leading institutions providing world-class Data Science & AI programs for working professionals with a mission to groom Data leaders of tomorrow!