Docker and Kubernetes: How to Manage Containers at Scale. In this guide, we introduce Kubernetes, its major advantages in modern application deployment then show you how to deploy and manage containers at scale using Docker and Kubernetes.
Google designed an open source container orchestration platform called Kubernetes to deploy and manage containerized applications. This open source platform is even capable of deploying and scaling several microservices. It offers a strong and flexible framework for controlling workloads and services for containers in a distributed setting.
Basically, it is all about optimization, streamlining the work of software engineers by automating a number of manual DevOps operations. It uses different types of containers and develops a framework to operate these containers in clusters with images created using Docker. The system, sometimes referred to as K8s, handles application failovers, enables load balancing, and more.
Kubernetes has become popular in recent years as a means to meet container orchestration requirements for organizations. Many services are delivered over the network using open APIs and distribution mechanisms. In order to avoid downtime, the systems must be extremely scalable.
In fact, cloud native apps are deployed anywhere with the aid of Kubernetes, which offers pertinent services that cover all these capabilities. Over time, they have emerged as among the best and fastest expanding projects.
1. Self healing Service –Â For enabling self service Kubernetes on complex enterprise grade clusters, best practices are needed. If a container fails, the self service Kubernetes clusters can restart, replace the container, or reschedule once they notice the dead nodes. Additionally, they aid in killing containers that fail a user defined health check. They try to work on it and only discuss it with clients once the containers are prepared to be used.
2. Highly Portable and Flexible – Kubernetes’ flexible capabilities support continuously delivering your apps, no matter how complex your requirements are, be it local testing or managing a large organization. Kubernetes are practically working with any architecture, including a server on premises, a hybrid cloud, or a public cloud. Kubernetes enables the creation of portable deployments that are operated reliably across several environments. However, this feature is absent from other orchestrators. In fact, workloads are moved to your desired place with ease thanks to this trusted open source platform.
3. Container Orchestration –Â The management of containerized apps is made easier by Kubernetes, which automates processes like deployment, scaling, and load balancing. Instead of worrying about infrastructure management, it enables you to concentrate on application development. For the optimal use of resources, Kubernetes automatically configures and fits containers onto nodes.
4. Efficiency boost for DevOps in microservices architecture –Â Development, testing, and deployment are simplified by the integration of containers and access to storage resources across several cloud providers. Virtual machine (VM) images cannot be created as easily or as quickly as container images, which include all of the components a program needs to execute. All of this results in streamlined release and deployment timelines and quicker development.
5. Multi Cloud Features –Â Several cloud providers support container integration and offer access to storage resources that help simplify the deployment, development, and testing process. It is simpler and more effective to create container images than virtual machine (VM) images, which contain all the components an application needs to execute. All of this results in streamlined release and deployment timelines and quicker development.
To get the latest version of Docker, you need to install it from the Docker’s official repository. Here is the steps to install the Docker package to your server.
First, install the following packages to install the Docker package via secure HTTPS connection:
To create an Express app, you need to install the Node.js package to your server. To get the latest Node.js version, add the NodeSource repository to your server.
In this section, dockerize an Express application and run it inside the container. First, create a Dockerfile to define the Express application.
nano Dockerfile
Add the following code:
# Define Node.js version
FROM node:18
# Create app directory
WORKDIR /usr/src/app
# Install app dependencies
# A wildcard is used to ensure both package.json AND package-lock.json are copied
COPY package*.json ./
RUN npm install
# Bundle app source
COPY . .
# Define port to expose application for outside world.
EXPOSE 8080
CMD [ "node", "server.js" ]
Save and close the fiel then create the Docker image of your Express application:
cd /root/express-app
docker build -t express-app .
After the successful build, you see the following screen.
Now verify the created Docker image using the command given below:
docker images
Output:
REPOSITORY TAG IMAGE ID CREATED SIZE
express-app latest 13e0a201ae14 6 seconds ago 1.1GB
Finally, run your Express application container using your Express Docker image:
docker run --name express-app-container -p 80:8080 -d express-app
Verify your running container with the following command.
docker ps
This shows your Express container with a listening port:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
811520b27aee express-app "docker-entrypoint.s…" 10 seconds ago Up 9 seconds 0.0.0.0:80->8080/tcp, :::80->8080/tcp express-app-container
Access your Express application running inside the Docker container via http://server-ip. Next, stop and remove the Express application container using the following command.
You need to upload your Express Docker image in the Docker Hub registry to use it with Kubernetes.
First, log in to your Docker Hub account with the following command.
docker login
You will be asked to provide your username and password to login to Docker Hub registry.
Next, define a tag for your Docker image to maintain the built version of your image.
docker tag express-app hitjethva/express-app:v1
Verify the tagged docker image with the following command.
docker images
Output.
REPOSITORY TAG IMAGE ID CREATED SIZE
hitjethva/express-app v1 13e0a201ae14 About a minute ago 1.1GB
express-app latest 13e0a201ae14 About a minute ago 1.1GB
Now, push your Express image to the Docker hub registry using the following command.
docker push hitjethva/express-app:v1
You will see the following screen.
Setting Up a Local Kubernetes Cluster
You can use Minikube to set up a Kubernetes cluster for a development environment. First, download the latest Minikube version from their official release page.
Save and close the file. Then, apply the above configuration to the Kubernetes cluster.
kubectl apply -f deployment.yaml
You can now verify your deployment using the following command.
kubectl get pods
This will show your Express replicas in the following output.
NAME READY STATUS RESTARTS AGE
express-app-deployment-6fb5947748-xttw9 1/1 Running 0 59s
express-app-deployment-6fb5947748-zs78d 1/1 Running 0 59s
Expose an Express Application
At this point, your application is deployed on the Kubernetes. However, it can not be accessed outside the Kubernetes. So you need to expose your application using the kubectl expose command.
You can verify the exposed service using the following command.
kubectl get svc
This will show you the port of your Express application as shown below.
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
express-app-deployment NodePort 10.101.230.78 8080:31998/TCP 12s
kubernetes ClusterIP 10.96.0.1 443/TCP 5m57s
To see the more information about your deployment, run the following command.
kubectl describe services/express-app-deployment
You will see the following screen.
Now, verify your Express application running on the Kubernetes using the following command.
curl $(minikube ip):31998
You will see the following output.
Express application is working!
Scaling an Express Application
At this point, we have created two pods to run your application. You will need to scale the application when traffic increases. In this section, we scale an Express application to run on 4 pods.
First, verify the existing replica for your application using the following command.
kubectl get rs
You will see that there are two replicas for your application.
NAME DESIRED CURRENT READY AGE
express-app-deployment-6fb5947748 2 2 2 6m42s
Now, scale the deployment to 4 replicas using the following command.
Docker and Kubernetes: How to Manage Containers at Scale Conclusion
In this post, we have created an Express application, dockerize it then deploy and scale using the Kubernetes platform. Overall, Kubernetes makes managing and scaling containerized applications easier while enhancing the efficiency and flexibility of the deployment of new infrastructure and applications. Apart from supporting various types of infrastructure, Kubernetes even works well with any program that runs containers.
In fact, to meet rising demand and maintain system availability, it intelligently distributes and balances containerized workloads and expands clusters as necessary. Because of its benefits, it is now the industry’s top platform for container orchestration.
I am a fan of open source technology and have more than 10 years of experience working with Linux and Open Source technologies. I am one of the Linux technical writers for Cloud Infrastructure Services.
00votes
Article Rating
Subscribe
Login and comment with
I allow to create an account
When you login first time using a Social Login button, we collect your account public profile information shared by Social Login provider, based on your privacy settings. We also get your email address to automatically create an account for you in our website. Once your account is created, you'll be logged-in to this account.
DisagreeAgree
Login and comment with
I allow to create an account
When you login first time using a Social Login button, we collect your account public profile information shared by Social Login provider, based on your privacy settings. We also get your email address to automatically create an account for you in our website. Once your account is created, you'll be logged-in to this account.