Hands On Docker for Microservices with Python 2nd Ed.

Design, deploy, and operate a complex system with multiple microservices using Docker and Kubernetes

Jaime Buelta

Publisher: Packt, 2019, 392 pages

ISBN: 978-1-83882-381-8

Keywords: Python, IT Architecture

Last modified: July 18, 2022, 11:55 a.m.

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.

Things you will learn:

  • Discover how to design, test, and operate scalable microservices
  • Coordinate and deploy 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 seaamless operation between the old monolithic and the new service
  • Section 1: Introduction to Microservices
    1. Making the Move — Design, Plan, and Execute
      • Technical requirements
      • The traditional monolith approach and its problems
      • The characteristics of a microservices approach
        • Docker containers
          • Container orchestration and Kubernetes
      • 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
        • The replacement approach
        • The divide approach
        • Change and structured approach
      • Executing the move
        • Web services' best friend — the load balancer
        • Keeping the balance between new and old
          • The pilot phase — setting up the first couple of microservices
          • The consolidation phase — steady migration to microservices
          • The final phase — the microservices shop
      • Summary
      • Questions
      • Further reading
  • Section 2: Designing and Operating a Single Service — Creating a Docker Container
    1. Creating a REST Service with Python
      • Technical requirements
      • Analyzing the Thoughts Backend microservice
        • Understanding the security API
      • Designing the RESTful API
        • Specifying the API endpoints
      • Defining the database schema
        • Working with SQLAlchemy
      • Implementing the service
        • Introducing Flask-RESTPlus
        • Handling resources
        • Parsing input parameters
        • Serializing results
        • Performing the action
        • Authenticating the requests
      • Testing the code
        • Defining the pytest fixtures
        • Understanding test_token_validation.py
        • test_thoughts.py
      • Summary
      • Questions
      • Further reading
    2. Build, Run, and Test Your Service Using Docker
      • Technical requirements
      • Building your service with a Dockerfile
        • Executing commands
        • Understanding the Docker cache
        • Building a web service container
        • Configuring uWSGI
        • Refreshing Docker commands
      • Operating with an immutable container
        • Testing the container
        • Creating a PostgreSQL database container
      • Configuring your service
      • Deploying the Docker service locally
      • Pushing your Docker image to a remote registry
        • Obtaining public images from Docker Hub
        • Using tags
        • Pushing into a registry
      • Summary
      • Questions
      • Further reading
    3. Creating a Pipeline and Workflow
      • Technical requirements
      • Understanding continuous integration practices
        • Producing automated builds
        • Knowing the advantages of using Docker for builds
        • Leveraging the pipeline concept
        • Branching, merging, and ensuring a clear main build
      • Configuring Travis CI
        • Adding a repo to Travis CI
        • Creating the .travis.yml file
        • Working with Travis jobs
        • Sending notifications
      • Configuring GitHub
      • Pushing Docker images from Travis CI
        • Setting the secret variables
        • Tagging and pushing builds
        • Tagging and pushing every commit
      • Summary
      • Questions
      • Further reading
  • Section 3: Working with Multiple Services – Operating the System through Kubernetes
    1. Using Kubernetes to Coordinate Microservices
      • Technical requirements
      • Defining the Kubernetes orchestrator
        • Comparing Kubernetes with Docker Swarm
      • Understanding the different Kubernetes elements
        • Nodes
        • Kubernetes Control Plane
        • Kubernetes Objects
      • Performing basic operations with kubectl
        • Defining an element
        • Getting more information
        • Removing an element
      • Troubleshooting a running cluster
      • Summary
      • Questions
      • Further reading
    2. Local Development with Kubernetes
      • Technical requirements
      • Implementing multiple services
        • Describing the Users Backend Microservice
        • Describing the Frontend Microservice
        • Connecting the services
      • Configuring the services
        • Configuring the deployment
        • Configuring the services
        • Configuring the Ingress
      • Deploying the full system locally
        • Deploying the Users Backend
        • Adding the Frontend
      • Summary
      • Questions
      • Further reading
    3. Configuring and Securing the Production System
      • Technical requirements
      • Using Kubernetes in the wild
        • Creating an IAM user
      • Setting up the Docker registry
      • Creating the cluster
        • Creating the Kubernetes cluster
        • Configuring the cloud Kubernetes cluster
          • Configuring the AWS image registry
          • Configuring the usage of an externally accessible load balancer
          • Deploying the system
      • Using HTTPS and TLS to secure external access
      • Being ready for migration to microservices
        • Running the example
      • Deploying a new Docker image smoothly
        • The liveness probe
        • The readiness probe
        • Rolling updates
      • Autoscaling the cluster
        • Creating a Kubernetes Horizontal Pod Autoscaler
          • Deploying the Kubernetes metrics server
          • Configuring the resources in deployments
          • Creating an HPA
        • Scaling the number of nodes in the cluster
          • Deleting nodes
        • Designing a winning autoscaling strategy
      • Summary
      • Questions
      • Further reading
    4. Using GitOps Principles
      • Technical requirements
      • Understanding the description of GitOps
        • Managing configuration
        • Understanding DevOps
        • Defining GitOps
      • Setting up Flux to control the Kubernetes cluster
        • Starting the system
        • Configuring Flux
      • Configuring GitHub
        • Forking the GitHub repo
        • Adding a deploy key
        • Syncing Flux
      • Making a Kubernetes cluster change through GitHub
      • Working in production
        • Creating structure
        • Using GitHub features
        • Working with tags
      • Summary
      • Questions
      • Further reading
    5. Managing Workflows
      • Understanding the life cycle of a feature
        • Features that affect multiple microservices
        • Implementing a feature
      • Reviewing and approving a new feature
        • Reviewing feature code
        • Approving releases
      • Setting up multiple environments
      • Scaling the workflow and making it work
        • Reviewing and approving is done by the whole team
        • Understanding that not every approval is the same
        • Defining a clear path for releases
          • Emergency releases
        • Releasing frequently and adding feature flags
          • Using feature flags
        • Dealing with database migrations
      • Summary
      • Questions
      • Further reading
  • Section 4: Production-Ready System – Making It Work in Real-Life Environments
    1. Monitoring Logs and Metrics
      • Technical requirements
      • Observability of a live system
        • Understanding logs
        • Understanding metrics
      • Setting up logs
        • Setting up an rsyslog container
        • Defining the syslog pod
          • log-volume
          • syslog container
          • The front rail container
        • Allowing external access
        • Sending logs
        • Generating application logs
          • Dictionary configuration
          • Logging a request ID
          • Logging each request
          • Searching through all the logs
      • Detecting problems through logs
        • Detecting expected errors
        • Capturing unexpected errors
        • Logging strategy
        • Adding logs while developing
      • Setting up metrics
        • Defining metrics for the Thoughts Backend
          • Adding custom metrics
        • Collecting the metrics
        • Plotting graphs and dashboards
          • Grafana UI
          • Querying Promotheus
          • Updating dashboards
      • Being Proactive
        • Alerting
        • Being prepared
      • Summary
      • Questions
      • Further reading
    2. Handling Change, Dependencies, and Secrets in the System
      • Technical requirements
      • Understanding shared configurations across microservices
        • Adding the ConfigMap file
          • Using kubectl commands
        • Adding ConfigMap to the deployment
          • Thoughts Backend ConfigMap configuration
          • Users Backend ConfigMap configuration
          • Frontend ConfigMap configuration
      • Handling Kubernetes secrets
        • Storing secrets in Kubernetes
        • Creating the secrets
          • Storing the secrets in the cluster
          • Secret deployment configuration
          • Retrieving the secrets by the applications
      • Defining a new feature affecting multiple services
        • Deploying one change at a time
        • Rolling back the microservices
      • Dealing with service dependencies
        • Versioning the services
          • Semantic versioning
        • Adding a version endpoint
          • Obtaining the version
          • Storing the version in the image
          • Implementing the version endpoint
        • Checking the version
          • Required version
          • The main function
          • Checking the version
      • Summary
      • Questions
      • Further reading
    3. Collaborating and Communicating across Teams
      • Keeping a consistent architectural vision
      • Dividing the workload and Conway's Law
        • Describing Conway's Law
        • Dividing the software into different kinds of software units
        • Designing working structures
          • Structuring teams around technologies
          • Structuring teams around domains
          • Structuring teams around customers
          • Structuring teams around a mix
      • Balancing new features and maintenance
        • Regular maintenance
        • Understanding technical debt
        • Continuously addressing technical debt
        • Avoiding technical debt
      • Designing a broader release process
        • Planning in the weekly release meeting
        • Reflecting on release problems
        • Running post-mortem meetings
      • Summary
      • Questions
      • Further reading
  • Assessments
  • Other Books You May Enjoy

Reviews

Hands-On Docker for Microservices with Python

Reviewed by Roland Buresund

Decent ****** (6 out of 10)

Last modified: Aug. 29, 2023, 8:04 a.m.

A fairly decent introduction to Docker, Kubernetes and microservices in general.

A bit dry to read but it covers the basics

Comments

There are currently no comments

New Comment

required

required (not published)

optional

required

captcha

required