In this Project, I will show you how to deploy the web application as a load-balanced set of replicas that can scale to the needs of your users. In my previous project, I package a web application in a Docker container image and run the Container image. If You want to know visit my Project Deploy-WebApp-With-Docker
- First we are going to push our docker image into Docker Hub
- Here are the steps that worked for me :
- Login to the docker.
docker login -u sovu
- Tag your image build
my image name here is : mylocalimage and by default it has tag : latestand my username is : sovu as registered with docker cloud, and I created a public repository named : dockerhub
so my personal repository becomes now : sovu/dockerhub and I want to push my image with tag : myfirstimagepush
I tagged as below :
docker tag mylocalimage:latest sovu/dockerhub:myfirstimagepush
- Pushed the image to my personal docker repository as below
docker push sovu/dockerhub:myfirstimagepush
- Now we will create a file with the name
deployment.yml
and then write the code for it.
apiVersion: apps/v1
kind: Deployment
metadata:
name: web
spec:
replicas: 1
selector:
matchLabels:
app: web
template:
metadata:
labels:
app: web
spec:
containers:
- name: portfolio-website
image: docker.io/sovu/portfolio-website:latest
ports:
- containerPort: 8080
If You are not that familiar with the YAML let me tell you that indentation is very important if the indentation will be wrong it will not work.
Now save the file
- Now I'm using Minikube as my Kubernetes cluster to run my web application
- Start the minikube
minikube start
- it will start one control node and one worker node.
- Now let's run the command to deploy our web application.
kubectl apply -f deployment.yml
kubectl
Kubernetes command-line tool, kubectl, allows you to run commands against Kubernetes clusters. You can use kubectl to deploy applications, inspect and manage cluster resources, and view logsapply
Manages applications through files defining Kubernetes resources. It creates and updates resources in a cluster through runningkubectl apply
f
it mean we are applying file.- We can use a command to see the deployment
kubectl rollout status deployment/web
- Now we have successfully deployed our containerized web page or docker image that was pushed in the docker hub repository.
- Now we can expose the port so that we can see that we have deployed the application.
kubectl port-forward deployment/web-app 8080:80
- We are exposing our web application at host port 8080.
- Now go to the browser and type at URL address bar
localhost:8080
and your web page is working.