Reader small image

You're reading from  Modern API Development with Spring 6 and Spring Boot 3 - Second Edition

Product typeBook
Published inSep 2023
Reading LevelIntermediate
PublisherPackt
ISBN-139781804613276
Edition2nd Edition
Languages
Concepts
Right arrow
Author (1)
Sourabh Sharma
Sourabh Sharma
author image
Sourabh Sharma

Sourabh Sharma is a Senior Development Manager at Oracle with over 20 years of experience in the industry. He is a manager and architect who has been designing on-premise and cloud-based applications using Java, Javascript, and Oracle DB. Sourabh has worked with leading companies and delivered enterprise products and applications. His expertise lies in conceptualizing, modeling, designing, and developing N-tier and cloud-based web applications while leading teams. Sourabh's experience also includes developing microservice-based solutions and implementing various types of workflow and orchestration engines. He believes in continuous learning and sharing knowledge through his books and training.
Read more about Sourabh Sharma

Right arrow

Deployment of Web Services

In this chapter, you will learn about the fundamentals of containerization, Docker, and Kubernetes. You will then use these concepts to containerize a sample e-commerce app using Docker. This container will then be deployed aws a Kubernetes cluster. You will use Minikube for Kubernetes, which makes learning and Kubernetes-based development easier.

After completing this chapter, you will be able to perform containerization and container deployment in a Kubernetes cluster.

In this chapter, you’ll explore the following topics:

  • Exploring the fundamentals of containerization
  • Building a Docker image
  • Deploying an application in Kubernetes

Technical requirements

You will need the following to develop and execute the code in this chapter:

Let’s begin!

What is containerization?

One problem that’s encountered frequently by teams while developing large, complex systems is that the code that works on one machine doesn’t work on another. The main reason behind these kinds of scenarios is a mismatch of dependencies (such as different versions of Java, a certain web server, or OS), configurations, or files.

Also, setting up a new environment to deploy new products sometimes takes a day or more. This is unacceptable in today’s environment and slows down your development turnaround. These kinds of issues can be solved by containerizing the application.

In containerization, an application is bundled, configured, and wrapped with all the required dependencies and files. This bundle can then be run on any machine that supports the containerization process. This bundling ensures that the application displays the exact same behavior in all environments. As a result, bugs related to misconfigurations or dependencies...

Building a Docker image

At this point, you know the benefit of containerization and why it is becoming popular – you create an application, product, or service, bundle it using containerization, and give it to the QA team, customer, or DevOps team to run without any issues.

In this section, you’ll learn how to use Docker as a containerization platform. Let’s learn about it before creating a Docker image of a sample e-commerce app.

What is Docker?

Launched in 2013, Docker is a leading container platform and an open source project. Ten thousand developers tried it after its interactive tutorial was launched in August 2013. It was downloaded 2.75 million times by the time of its 1.0 release in June 2013. Many large corporations have signed a partnership agreement with Docker Inc., including Microsoft, Red Hat, HP, and OpenStack, as well as service providers such as AWS, IBM, and Google.

Docker makes use of Linux kernel features to ensure resource isolation...

Deploying an application in Kubernetes

Docker containers are run in isolation. You need a platform that can execute multiple Docker containers and manage or scale them. Docker Compose does this for us. However, this is where Kubernetes helps. It not only manages the container but also helps you scale the deployed containers dynamically.

You will use Minikube to run Kubernetes locally. You can use it on Linux, macOS, and Windows. It runs a single-node Kubernetes cluster, which is used for learning or development purposes. You can install it by referring to the respective guide (https://minikube.sigs.k8s.io/docs/start/).

Once Minikube is installed, you need to update Minikube’s local insecure registry because, by default, Minikube’s registry uses Docker Hub. Adding an image to Docker Hub and then fetching it for local usage is cumbersome for development. You can add a local insecure registry to your Minikube environment by adding your host IP and local Docker registry...

Summary

In this chapter, you learned about containerization and how it is different from virtualization. You also learned about the Docker containerization platform and how to use the Spring Boot plugin to generate a Docker image for a sample e-commerce app.

Then, you learned about the Docker registry and how to configure a local insecure registry so that you can use it to push and pull images locally. The same commands can be used to push and pull images from a remote Docker registry.

You also learned about Kubernetes and its cluster operations by using Minikube. You configured it so that you can pull Docker images from insecure local Docker registries.

Now, you have the necessary skills to build a Docker image of a Spring Boot application and deploy it to a Kubernetes cluster.

In the next chapter, you’ll learn about the fundamentals of the gRPC APIs.

Questions

  1. What is the difference between virtualization and containerization?
  2. What is Kubernetes used for?
  3. What is kubectl?

Answers

  1. Virtualization is used to create VMs on top of the host system, which shares its hardware with the VMs, whereas containerization creates containers that are executed as an isolated process on top of the hardware and its OS. Containers are lightweight and need only a few MB (occasionally, GB). VMs are heavyweight and need many GB. Containers run faster and are more portable than VMs.
  2. Kubernetes is a container orchestration system and is used to manage application containers. It keeps track of running containers. It shuts down containers when they are not used and restarts orphaned containers. A Kubernetes cluster is also used for scale. It can provision resources such as CPU, memory, and storage automatically when required.
  3. kubectl is a Kubernetes command-line interface (CLI) utility that is used to run commands against a Kubernetes cluster. You can manage Kubernetes resources using kubectl. You used kubectl’s apply and create commands in this chapter.
  4. ...
lock icon
The rest of the chapter is locked
You have been reading a chapter from
Modern API Development with Spring 6 and Spring Boot 3 - Second Edition
Published in: Sep 2023Publisher: PacktISBN-13: 9781804613276
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €14.99/month. Cancel anytime

Author (1)

author image
Sourabh Sharma

Sourabh Sharma is a Senior Development Manager at Oracle with over 20 years of experience in the industry. He is a manager and architect who has been designing on-premise and cloud-based applications using Java, Javascript, and Oracle DB. Sourabh has worked with leading companies and delivered enterprise products and applications. His expertise lies in conceptualizing, modeling, designing, and developing N-tier and cloud-based web applications while leading teams. Sourabh's experience also includes developing microservice-based solutions and implementing various types of workflow and orchestration engines. He believes in continuous learning and sharing knowledge through his books and training.
Read more about Sourabh Sharma