
Hands-On Docker for Microservices with Python
Design, deploy, and operate a complex system with multiple microservices using Docker and Kubernetes
- 408 pages
- English
- ePUB (mobile friendly)
- Available on iOS & Android
Hands-On Docker for Microservices with Python
Design, deploy, and operate a complex system with multiple microservices using Docker and Kubernetes
About this book
A step-by-step guide to building microservices using Python and Docker, along with managing and orchestrating them with Kubernetes
Key Features
- Learn to use Docker containers to create, operate, and deploy your microservices
- Create workflows to manage independent deployments on coordinating services using CI and GitOps through GitHub, Travis CI, and Flux
- Develop a REST microservice in Python using the Flask framework and Postgres database
Book Description
Microservices architecture helps create complex systems with multiple, interconnected services that can be maintained by independent teams working in parallel. This book guides you on how to develop these complex systems with the help of containers.
You'll start by learning to design an efficient strategy for migrating a legacy monolithic system to microservices. You'll build a RESTful microservice with Python and learn how to encapsulate the code for the services into a container using Docker. While developing the services, you'll understand how to use tools such as GitHub and Travis CI to ensure continuous delivery (CD) and continuous integration (CI). As the systems become complex and grow in size, you'll be introduced to Kubernetes and explore how to orchestrate a system of containers while managing multiple services. Next, you'll configure Kubernetes clusters for production-ready environments and secure them for reliable deployments. In the concluding chapters, you'll learn how to detect and debug critical problems with the help of logs and metrics. Finally, you'll discover a variety of strategies for working with multiple teams dealing with different microservices for effective collaboration.
By the end of this book, you'll be able to build production-grade microservices as well as orchestrate a complex system of services using containers.
What you will learn
- Discover how to design, test, and operate scalable microservices
- Coordinate and deploy different services using Kubernetes
- Use Docker to construct scalable and manageable applications with microservices
- Understand how to monitor a complete system to ensure early detection of problems
- Become well versed with migrating from an existing monolithic system to a microservice one
- Use load balancing to ensure seamless operation between the old monolith and the new service
Who this book is for
This book is for developers, engineers, or software architects who are trying to move away from traditional approaches for building complex multi-service systems by adopting microservices and containers. Although familiarity with Python programming is assumed, no prior knowledge of Docker is required.
Tools to learn more effectively

Saving Books

Keyword Search

Annotating Text

Listen to it instead
Information
Section 1: Introduction to Microservices
- Chapter 1, Making the Move – Design, Plan, and Execute
Making the Move – Design, Plan, and Execute
- The traditional monolith approach and its problems
- The characteristics of a microservices approach
- Parallel deployment and development speed
- Challenges and red flags
- Analyzing the current system
- Preparing and adapting by measuring usage
- Strategic planning to break the monolith
- Executing the move
Technical requirements
The traditional monolith approach and its problems

If more than one server is used, there will be a load balancer to spread the load among them. We'll talk about them later in this chapter. The server (or load balancer) needs to be accessible on the internet, so it will have a dedicated DNS and a public IP address.
In other programming languages, the structure will be similar: a frontend web server that exposes the port in HTTP/HTTPS, and a backend that runs the monolith code in a dedicated web worker.
- The code will increase in size: Without strict boundaries between modules, developers will start having problems understanding the whole code base. While good practices can help, the complexity naturally tends to increase, making it more difficult to change the code in certain ways and increasing subtle bugs. Running all tests will become slow, decreasing the speed of any Continuous Integration system.
- Inefficient utilization of resources: Each individual deployed web worker will require all the resources required for the whole system to work, for example, the maximum amount of memory for any kind of request, even if a request that demands a lot of memory is rare and just a couple of workers will be sufficient. The same may happen with the CPU. If the monolith connects to a database, each individual worker will require a connection to it, whether that's used regularly or not, and so on.
- Issues with development scalability: Even if the system is perfectly designed to be horizontally scalable (unlimited new workers can be added), as the system grows and the development team grows, development will be more and more difficult without stepping on each other's toes. A small team can coordinate easily, but once several teams are working on the same code base, the probability of clashing will increase. Imposing boundaries for teams in terms of ownership and responsibility can also become blurry unless strict discipline is enforced. In any case, teams will need to be actively coordinated, which reduces their independence and speed.
- Deployment limitations: The deployment approach will need to be shared across teams, and teams can't be individually responsible for each deployment, as deployment will probably involve work for multiple teams. A deployment problem will bring down the whole system.
- Interdependency of technologies: Any new tech needs to fit with the tech in use in the monolith. A new technology, for example, a tool that's perfect for a particular problem, may be complicated to add to the monolith, due to a mismatch of technologies. Updating dependencies can also cause issues. For example, an update to a new version of Python (or a submodule) needs to operate with the whole code base. Some required maintenance tasks, such as a security patch, can cause a problem just because the monolith already uses a specific version of a library, which will break if changed. Adapting to these changes requires extra work too.
- A bug in a small part of the system can bring down the whole service: As the service is a whole, any critical issue that affects the stability affects everything, making it difficult to generate quality service strategies or causing degraded results.
The characteristics of a microservices approach
- A collection of specialized services, meaning that there are different, well-defined modules.
- Loosely coupled, meaning that each of the microservices can be independently deployed.
- That work in unison—each microservice is capable of communicating with others.
- To provide a comprehensive service, because our microservice system will need to replicate the same functionalities that were available using a monolith approach. There is an intent behind its design.

- If the communication between microservices is done through a standard protocol, each microservice can be programmed in different languages.
- Better resource utilization—if Microservice A requir...
Table of contents
- Title Page
- Copyright and Credits
- Dedication
- About Packt
- Contributors
- Preface
- Section 1: Introduction to Microservices
- Making the Move – Design, Plan, and Execute
- Section 2: Designing and Operating a Single Service – Creating a Docker Container
- Creating a REST Service with Python
- Build, Run, and Test Your Service Using Docker
- Creating a Pipeline and Workflow
- Section 3:Working with Multiple Services – Operating the System through Kubernetes
- Using Kubernetes to Coordinate Microservices
- Local Development with Kubernetes
- Configuring and Securing the Production System
- Using GitOps Principles
- Managing Workflows
- Section 4: Production-Ready System – Making It Work in Real-Life Environments
- Monitoring Logs and Metrics
- Handling Change, Dependencies, and Secrets in the System
- Collaborating and Communicating across Teams
- Assessments
- Other Books You May Enjoy
Frequently asked questions
- Essential is ideal for learners and professionals who enjoy exploring a wide range of subjects. Access the Essential Library with 800,000+ trusted titles and best-sellers across business, personal growth, and the humanities. Includes unlimited reading time and Standard Read Aloud voice.
- Complete: Perfect for advanced learners and researchers needing full, unrestricted access. Unlock 1.4M+ books across hundreds of subjects, including academic and specialized titles. The Complete Plan also includes advanced features like Premium Read Aloud and Research Assistant.
Please note we cannot support devices running on iOS 13 and Android 7 or earlier. Learn more about using the app