0%

In Bootstrapping Microservices with Docker, Kubernetes, and Terraform, author Ashley Davis lays out a comprehensive approach to building microservices. You’ll start with a simple design and work layer-by-layer until you’ve created your own video streaming application. As you go, you’ll learn to configure cloud infrastructure with Terraform, package microservices using Docker, and deploy your finished project to a Kubernetes cluster.

Table of Contents

  1. Bootstrapping Microservices with Docker, Kubernetes, and Terraform
  2. Copyright
  3. brief contents
  4. contents
  5. front matter
    1. preface
    2. acknowledgments
    3. about this book
    4. Who should read this book
    5. How this book is organized: A roadmap
    6. About the code
    7. liveBook discussion forum
    8. about the author
    9. about the cover illustration
  6. 1 Why microservices?
    1. 1.1 This book is practical
    2. 1.2 What will I learn?
    3. 1.3 What do I need to know?
    4. 1.4 Managing complexity
    5. 1.5 What is a microservice?
    6. 1.6 What is a microservices application?
    7. 1.7 What’s wrong with the monolith?
    8. 1.8 Why are microservices popular now?
    9. 1.9 Benefits of microservices
    10. 1.10 Drawbacks of microservices
    11. 1.11 Modern tooling for microservices
    12. 1.12 Designing a microservices application
    13. 1.13 An example application
    14. Summary
  7. 2 Creating your first microservice
    1. 2.1 New tools
    2. 2.2 Getting the code
    3. 2.3 Why Node.js?
    4. 2.4 Our philosophy of development
    5. 2.5 Establishing our single-service development environment
    6. 2.5.1 Installing Git
    7. 2.5.2 Cloning the code repo
    8. 2.5.3 Getting Visual Studio (VS) Code
    9. 2.5.4 Installing Node.js
    10. 2.6 Building an HTTP server for video streaming
    11. 2.6.1 Creating a Node.js project
    12. 2.6.2 Installing Express
    13. 2.6.3 Creating the Express boilerplate
    14. 2.6.4 Running our simple web server
    15. 2.6.5 Adding streaming video
    16. 2.6.6 Configuring our microservice
    17. 2.6.7 Setting up for production
    18. 2.6.8 Live reloading for fast iteration
    19. 2.6.9 Running the finished code from this chapter
    20. 2.7 Node.js review
    21. 2.8 Continue your learning
    22. Summary
  8. 3 Publishing your first microservice
    1. 3.1 New tools
    2. 3.2 Getting the code
    3. 3.3 What is a container?
    4. 3.4 What is an image?
    5. 3.5 Why Docker?
    6. 3.6 What are we doing with Docker?
    7. 3.7 Extending our development environment with Docker
    8. 3.7.1 Installing Docker
    9. 3.7.2 Checking your Docker installation
    10. 3.8 Packaging our microservice
    11. 3.8.1 Creating a Dockerfile
    12. 3.8.2 Packaging and checking our Docker image
    13. 3.8.3 Booting our microservice in a container
    14. 3.9 Publishing our microservice
    15. 3.9.1 Creating a private container registry
    16. 3.9.2 Pushing our microservice to the registry
    17. 3.9.3 Booting our microservice from the registry
    18. 3.10 Docker review
    19. 3.11 Continue your learning
    20. Summary
  9. 4 Data management for microservices
    1. 4.1 New tools
    2. 4.2 Getting the code
    3. 4.3 Developing microservices with Docker Compose
    4. 4.3.1 Why Docker Compose?
    5. 4.3.2 Installing Docker Compose
    6. 4.3.3 Creating our Docker Compose file
    7. 4.3.4 Booting our microservices application
    8. 4.3.5 Working with the application
    9. 4.3.6 Shutting down the application
    10. 4.3.7 Can we use Docker Compose for production?
    11. 4.4 Adding file storage to our application
    12. 4.4.1 Using Azure Storage
    13. 4.4.2 Updating the video-streaming microservice
    14. 4.4.3 Adding our new microservice to the Docker Compose file
    15. 4.4.4 Testing the updated application
    16. 4.4.5 Cloud storage vs. cluster storage
    17. 4.4.6 What did we achieve?
    18. 4.5 Adding a database to our application
    19. 4.5.1 Why MongoDB?
    20. 4.5.2 Adding a database server in development
    21. 4.5.3 Adding a database server in production
    22. 4.5.4 Database-per-microservice or database-per-application?
    23. 4.5.5 What did we achieve?
    24. 4.6 Docker Compose review
    25. 4.7 Continue your learning
    26. Summary
  10. 5 Communication between microservices
    1. 5.1 New and familiar tools
    2. 5.2 Getting the code
    3. 5.3 Getting our microservices talking
    4. 5.4 Introducing the history microservice
    5. 5.5 Live reload for fast iterations
    6. 5.5.1 Creating a stub for the history microservice
    7. 5.5.2 Augmenting the microservice for live reload
    8. 5.5.3 Splitting our Dockerfile for development and production
    9. 5.5.4 Updating the Docker Compose file for live reload
    10. 5.5.5 Trying out live reload
    11. 5.5.6 Testing production mode in development
    12. 5.5.7 What have we achieved?
    13. 5.6 Methods of communication for microservices
    14. 5.6.1 Direct messaging
    15. 5.6.2 Indirect messaging
    16. 5.7 Direct messaging with HTTP
    17. 5.7.1 Why HTTP?
    18. 5.7.2 Directly targeting messages at particular microservices
    19. 5.7.3 Sending a message with HTTP POST
    20. 5.7.4 Receiving a message with HTTP POST
    21. 5.7.5 Testing the updated application
    22. 5.7.6 Sequencing direct messages
    23. 5.7.7 What have we achieved?
    24. 5.8 Indirect messaging with RabbitMQ
    25. 5.8.1 Why RabbitMQ?
    26. 5.8.2 Indirectly targeting messages to microservices
    27. 5.8.3 Creating a RabbitMQ server
    28. 5.8.4 Investigating the RabbitMQ dashboard
    29. 5.8.5 Connecting our microservice to the message queue
    30. 5.8.6 Single-recipient indirect messaging
    31. 5.8.7 Multiple-recipient messages
    32. 5.8.8 Sequencing indirect messages
    33. 5.8.9 What have we achieved?
    34. 5.9 Microservices communication review
    35. 5.10 Continue your learning
    36. Summary
  11. 6 Creating your production environment
    1. 6.1 New tools
    2. 6.2 Getting the code
    3. 6.3 Getting to production
    4. 6.4 Infrastructure as code
    5. 6.5 Hosting microservices on Kubernetes
    6. 6.5.1 Why Kubernetes?
    7. 6.5.2 How does Kubernetes work?
    8. 6.6 Working with the Azure CLI
    9. 6.6.1 Installing the Azure CLI
    10. 6.6.2 Authenticating with Azure
    11. 6.6.3 Which version of Kubernetes?
    12. 6.6.4 What have we achieved?
    13. 6.7 Creating infrastructure with Terraform
    14. 6.7.1 Why Terraform?
    15. 6.7.2 Installing Terraform
    16. 6.7.3 Terraform project setup
    17. 6.8 Creating an Azure resource group for your application
    18. 6.8.1 Evolutionary architecture with Terraform
    19. 6.8.2 Scripting infrastructure creation
    20. 6.8.3 Initializing Terraform
    21. 6.8.4 By-products of Terraform initialization
    22. 6.8.5 Fixing provider version numbers
    23. 6.8.6 Building your infrastructure
    24. 6.8.7 Understanding Terraform state
    25. 6.8.8 Destroying and recreating your infrastructure
    26. 6.8.9 What have we achieved?
    27. 6.9 Creating your container registry
    28. 6.9.1 Continuing the evolution of our infrastructure
    29. 6.9.2 Creating the container registry
    30. 6.9.3 Terraform outputs
    31. 6.9.4 What have we achieved?
    32. 6.10 Refactoring to share configuration data
    33. 6.10.1 Continuing the evolution of our infrastructure
    34. 6.10.2 Introducing Terraform variables
    35. 6.11 Creating our Kubernetes cluster
    36. 6.11.1 Scripting creation of your cluster
    37. 6.11.2 Cluster authentication with Azure
    38. 6.11.3 Building your cluster
    39. 6.11.4 What have we achieved?
    40. 6.12 Interacting with Kubernetes
    41. 6.12.1 Kubernetes authentication
    42. 6.12.2 The Kubernetes CLI
    43. 6.12.3 The Kubernetes dashboard
    44. 6.12.4 What have we achieved?
    45. 6.13 Terraform review
    46. 6.14 Continue your learning
    47. Summary
  12. 7 Getting to continuous delivery
    1. 7.1 New and familiar tools
    2. 7.2 Getting the code
    3. 7.3 Continuing to evolve our infrastructure
    4. 7.4 Continuous delivery (CD)
    5. 7.5 Deploying containers with Terraform
    6. 7.5.1 Configuring the Kubernetes provider
    7. 7.5.2 Deploying our database
    8. 7.5.3 Preparing for continuous delivery
    9. 7.5.4 Testing the new database server
    10. 7.5.5 Deploying and testing RabbitMQ
    11. 7.5.6 Tightening our security
    12. 7.5.7 What have we achieved?
    13. 7.6 Deploying our first microservice with Terraform
    14. 7.6.1 Using local variables to compute configuration
    15. 7.6.2 Building and publishing the Docker image
    16. 7.6.3 Authentication with the container registry
    17. 7.6.4 Deploying the video-streaming microservice
    18. 7.6.5 Testing your microservice
    19. 7.6.6 What have we achieved?
    20. 7.7 Continuous delivery with Bitbucket Pipelines
    21. 7.7.1 Why Bitbucket Pipelines?
    22. 7.7.2 Importing the example code to Bitbucket
    23. 7.7.3 Creating a deployment shell script
    24. 7.7.4 Managing Terraform state
    25. 7.7.5 The Bitbucket Pipelines script
    26. 7.7.6 Configuring environment variables
    27. 7.7.7 Testing your deployment pipeline
    28. 7.7.8 Debugging your deployment pipeline
    29. 7.7.9 What have we achieved?
    30. 7.8 Continue your learning
    31. Summary
  13. 8 Automated testing for microservices
    1. 8.1 New tools
    2. 8.2 Getting the code
    3. 8.3 Testing for microservices
    4. 8.4 Automated testing
    5. 8.5 Testing with Jest
    6. 8.5.1 Why Jest?
    7. 8.5.2 Setting up Jest
    8. 8.5.3 The math library to test
    9. 8.5.4 Your first Jest test
    10. 8.5.5 Running your first test
    11. 8.5.6 Live reload with Jest
    12. 8.5.7 Interpreting test failures
    13. 8.5.8 Invoking Jest with npm
    14. 8.5.9 Populating your test suite
    15. 8.5.10 Mocking with Jest
    16. 8.5.11 What have we achieved?
    17. 8.6 Unit testing
    18. 8.6.1 The metadata microservice
    19. 8.6.2 Creating unit tests with Jest
    20. 8.6.3 Running the tests
    21. 8.6.4 What have we achieved?
    22. 8.7 Integration testing
    23. 8.7.1 The code to test
    24. 8.7.2 Running a MongoDB database
    25. 8.7.3 Loading database fixtures
    26. 8.7.4 Creating an integration test with Jest
    27. 8.7.5 Running the test
    28. 8.7.6 What have we achieved?
    29. 8.8 End-to-end testing
    30. 8.8.1 Why Cypress?
    31. 8.8.2 Installing Cypress
    32. 8.8.3 Starting the Cypress UI
    33. 8.8.4 Setting up database fixtures
    34. 8.8.5 Booting your application
    35. 8.8.6 Creating an end-to-end test with Cypress
    36. 8.8.7 Invoking Cypress with npm
    37. 8.8.8 What have we achieved?
    38. 8.9 Automated testing in the CD pipeline
    39. 8.10 Review of testing
    40. 8.11 Continue your learning
    41. Summary
  14. 9 Exploring FlixTube
    1. 9.1 No new tools!
    2. 9.2 Getting the code
    3. 9.3 Revisiting essential skills
    4. 9.4 Overview of FlixTube
    5. 9.4.1 FlixTube microservices
    6. 9.4.2 Microservice project structure
    7. 9.4.3 FlixTube project structure
    8. 9.5 Running FlixTube in development
    9. 9.5.1 Booting a microservice
    10. 9.5.2 Booting the application
    11. 9.6 Testing FlixTube in development
    12. 9.6.1 Testing a microservice with Jest
    13. 9.6.2 Testing the application with Cypress
    14. 9.7 FlixTube deep dive
    15. 9.7.1 Database fixtures
    16. 9.7.2 Mocking storage
    17. 9.7.3 The gateway
    18. 9.7.4 The user interface (UI)
    19. 9.7.5 Video streaming
    20. 9.7.6 Video upload
    21. 9.8 Manually deploying FlixTube to production with Terraform
    22. 9.8.1 The Terraform scripts structure
    23. 9.8.2 Prerequisites
    24. 9.8.3 Azure authentication
    25. 9.8.4 Configuring storage
    26. 9.8.5 Deploying the application
    27. 9.8.6 Checking that it works
    28. 9.8.7 Teardown
    29. 9.8.8 Terraform modules
    30. 9.9 Continuous delivery to production
    31. 9.9.1 Prerequisites
    32. 9.9.2 Setting up your code repository
    33. 9.9.3 Preparing the backend
    34. 9.9.4 The deployment shell script
    35. 9.9.5 FlixTube’s CD configuration
    36. 9.9.6 Testing the continuous delivery (CD) pipeline
    37. 9.9.7 Adding automated testing
    38. 9.10 Review
    39. 9.11 FlixTube in the future
    40. 9.12 Continue your learning
    41. Summary
  15. 10 Healthy microservices
    1. 10.1 Maintaining healthy microservices
    2. 10.2 Monitoring your microservices
    3. 10.2.1 Logging in development
    4. 10.2.2 Error handling
    5. 10.2.3 Logging with Docker Compose
    6. 10.2.4 Basic logging with Kubernetes
    7. 10.2.5 Roll your own log aggregation for Kubernetes
    8. 10.2.6 Enterprise logging, monitoring and alerts
    9. 10.2.7 Automatic restarts with Kubernetes health checks
    10. 10.2.8 Tracing across microservices
    11. 10.3 Debugging microservices
    12. 10.3.1 The debugging process
    13. 10.3.2 Debugging production microservices
    14. 10.4 Reliability and recovery
    15. 10.4.1 Practice defensive programming
    16. 10.4.2 Practice defensive testing
    17. 10.4.3 Protect your data
    18. 10.4.4 Replication and redundancy
    19. 10.4.5 Fault isolation and graceful degradation
    20. 10.4.6 Simple techniques for fault tolerance
    21. 10.4.7 Advanced techniques for fault tolerance
    22. 10.5 Continue your learning
    23. Summary
  16. 11 Pathways to scalability
    1. 11.1 Our future is scalable
    2. 11.2 Scaling the development process
    3. 11.2.1 Multiple teams
    4. 11.2.2 Independent microservices
    5. 11.2.3 Splitting the code repository
    6. 11.2.4 Splitting the continuous delivery (CD) pipeline
    7. 11.2.5 The meta-repo
    8. 11.2.6 Creating multiple environments
    9. 11.2.7 Production workflow
    10. 11.3 Scaling performance
    11. 11.3.1 Vertically scaling the cluster
    12. 11.3.2 Horizontally scaling the cluster
    13. 11.3.3 Horizontally scaling an individual microservice
    14. 11.3.4 Elastic scaling for the cluster
    15. 11.3.5 Elastic scaling for an individual microservice
    16. 11.3.6 Scaling the database
    17. 11.3.7 Managing changes to infrastructure
    18. 11.4 Security
    19. 11.4.1 Trust models
    20. 11.4.2 Sensitive configuration
    21. 11.5 Refactoring to microservices
    22. 11.6 Microservices on a budget
    23. 11.7 From simple beginnings . . .
    24. 11.8 Continue your learning
    25. Summary
  17. appendix A. Creating a development environment with Vagrant
    1. A.1 Installing VirtualBox
    2. A.2 Installing Vagrant
    3. A.3 Creating your virtual machine (VM)
    4. A.4 Connecting to your VM
    5. A.5 Installing software in the VM
    6. A.6 Using the example setup
    7. A.7 Turning your VM off
  18. appendix B. Bootstrapping Microservices cheat sheet
    1. B.1 Node.js commands
    2. B.2 Docker commands
    3. B.4 Docker Compose commands
    4. Terraform commands
    5. B.5 Testing commands
  19. index
3.142.200.226