Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Hands-On Microservices with Kubernetes
Hands-On Microservices with Kubernetes

Hands-On Microservices with Kubernetes: Build, deploy, and manage scalable microservices on Kubernetes

eBook
$20.98 $29.99
Paperback
$43.99
Subscription
Free Trial
Renews at $19.99p/m

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Product feature icon AI Assistant (beta) to help accelerate your learning
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Table of content icon View table of contents Preview book icon Preview Book

Hands-On Microservices with Kubernetes

Getting Started with Microservices

In the previous chapter, you learned what Kubernetes is all about, and how it is well suited as a platform for developing, deploying, and managing microservices, and even played a little with your own local Kubernetes cluster. In this chapter, we are going to talk about microservices in general and why they are the best way to build complex systems. We will also discuss various aspects, patterns, and approaches that address common problems in microservice-based systems and how they compare to other common architectures, such as monolith and large services.

We will cover a lot of material in this chapter:

  • Programming in the small – less is more
  • Making your microservice autonomous
  • Employing interfaces and contracts
  • Exposing your service via APIs
  • Using client libraries
  • Managing dependencies
  • Orchestrating microservices
  • Taking advantage of...

Technical requirements

In this chapter, you'll see some code examples using Go. I recommend that you install Go and try to build and run the code examples yourself.

Installing Go with Homebrew on macOS

On macOS, I recommend using Homebrew:

$ brew install go

Next, make sure the go command is available:

$ ls -la `which go`
lrwxr-xr-x 1 gigi.sayfan admin 26 Nov 17 09:03 /usr/local/bin/go -> ../Cellar/go/1.11.2/bin/go

To see all the options, just type go. Also, make sure that you define GOPATH in your .bashrc file and add $GOPATH/bin to your path.

Go comes with the Go CLI that provides many capabilities, but you may want to install additional tools. Check out https://awesome-go.com/.

...

Programming in the small – less is more

Think about the time you learned to program. You wrote little programs that accepted simple input, did a little processing, and produced some output. Life was good. You could hold the entire program in your head.

You understood every line of code. Debugging and troubleshooting was easy. For example, consider a program to convert temperatures between Celsius and Fahrenheit:

package main

import (
"fmt"
"os"
"strconv"
)

func celsius2fahrenheit(t float64) float64 {
return 9.0/5.0*t + 32
}

func fahrenheit2celsius(t float64) float64 {
return (t - 32) * 5.0 / 9.0
}

func usage() {
fmt.Println("Usage: temperature_converter <mode> <temperature>")
fmt.Println()
fmt.Println("This program converts temperatures between Celsius and Fahrenheit&quot...

Making your microservice autonomous

One of the best ways to fight complexity is to make your microservice autonomous. An autonomous service is a service that doesn't depend on other services in the system or third-party services. An autonomous service manages its own state and can be largely unaware of the rest of the system.

I like to think of autonomous microservices as similar to immutable functions. Autonomous services never change the state of other components in the system. The benefit of such services is that their complexity remains the same, regardless of how the rest of the system evolves and however they are being used by other services.

Employing interfaces and contracts

Interfaces are one of the best tools a software engineer can use. Once you expose something as an interface, you can freely change the implementation behind it. Interfaces are a construct that's being used within a single process. They are extremely useful for testing interactions with other components, which are plentiful in microservice-based systems. Here is one of the interfaces of our sample application:

type UserManager interface {
Register(user User) error
Login(username string, authToken string) (session string, err error)
Logout(username string, session string) error
}

The UserManager interface defines a few methods, their inputs, and outputs. However, it doesn't specify the semantics. For example, what happens if the Login() method is called for an already logged-in user? Is it an error? Is the previous session terminated...

Exposing your service via APIs

Microservices interact with each other and sometimes with the outside world over the network. A service exposes its capabilities through an API. I like to think of APIs as over-the-wire interfaces. Programming language interfaces use the syntax of the language they are written in (for example, Go's interface type). Modern network APIs also use some high-level representation. The foundation is UDP and TCP. However, microservices will typically expose their capabilities over web transports, such as HTTP (REST, GraphQL, SOAP), HTTP/2 (gRPC), or, in some cases, WebSockets. Some services may imitate other wire protocols, such as memcached, but this is useful in special situations. In 2019, there is really no reason to build your own custom protocol directly over TCP/UDP or use proprietary and language-specific protocols. Approaches such as Java RMI...

Using client libraries

Interfaces are very convenient to work with. You operate within your programming language environments, calling methods with native data types. Working with network APIs is different. You need to use a network library, depending on the transport. You need to serialize your payload and responses and deal with network errors, disconnects, and timeouts. The client library pattern encapsulates the remote service and all these decisions and presents you with a standard interface that, as a client of the service, you just call. The client library behind the scenes will take care of all the ceremony involved with invoking a network API. The law of leaky abstractions (https://www.joelonsoftware.com/2002/11/11/the-law-of-leaky-abstractions/) says that you can't really hide the network. However, you can hide it pretty effectively from the consumer service and...

Managing dependencies

Modern systems have a lot of dependencies. Managing them effectively is a big part of the software development life cycle (SDLC). There are two kinds of dependencies:

  • Libraries/packages (linked to the running service process)
  • Remote services (accessible over the network)

Each of these dependencies can be internal or third party. You manage libraries or packages through your language's package management system. Go had no official package management system for a long time and several solutions, such as Glide and Dep, came along. These days (Go 1.12), Go modules are the official solution.

You manage remote services through the discovery of endpoints and tracking API versions. The difference between internal dependencies and third-party dependencies is the velocity of change. Internal dependencies will change much faster. With microservices, you&apos...

Coordinating microservices

When comparing a monolith system with a microservice-based system, one thing is clear. There is more of everything. The individual microservices are simpler and it's much easier to reason, modify, and troubleshoot individual services. But, understanding the whole system, making changes across multiple services, and debugging problems are more challenging. Many more interactions also happen over the network between separate microservices, where, with a monolith, these interactions would occur within the same process. It means that to benefit from microservices, you need a disciplined approach, you need to apply best practices, and have good tools at your disposal.

The uniformity versus flexibility trade-off

...

Taking advantage of ownership

Since microservices are small. A single developer can own a whole microservice and understand it completely. Other developers may also be familiar with it, but even if just a single developer is familiar with a service, it should be relatively simple and painless for a new developer to take over because the scope is so limited and ideally similar.

Sole ownership can be very powerful. The developer needs to communicate with the other developers and teams though the service API, but can iterate very fast on the implementation. You may still want other developers on the team to review the internal design and implementation, but even in the extreme case that the owner works completely on their own with no supervision, the potential damage is limited because the scope of each microservice is small and it interacts with the rest of the system through well...

Understanding Conway's law

Conway's law is defined as follows:

"Organizations which design systems ... are constrained to produce designs which are copies of the communication structures of these organizations."

This means the structure of the system will reflect the structure of the team building it. A famous variation by Eric Raymond is this:

"If you have four groups building a compiler you'll get a 4-pass compiler."

This is very insightful and I've personally witnessed it time and again in many different organizations. This is very relevant to microservice-based systems. With lots of small microservices, you don't need a dedicated team for each microservice. There will be some higher-level groups of microservices that work together to produce some aspect of the system. Now, the question is how to think about the high-level structure...

Troubleshooting across multiple services

Since most of the functions of the system will involve interactions between multiple microservices, it's important to be able to follow a request coming in across all those microservices and various data stores. One of the best ways to accomplish this is distributed tracing, where you tag each request and can follow it from beginning to end.

The subtleties of debugging distributed systems in general and microservice-based ones take a lot of expertise. Consider the following aspects along the path of a single request through the system:

  • The microservices processing the request may use different programming languages.
  • The microservices may expose APIs using different transports/protocols.
  • Requests may be part of asynchronous workflows that involve waiting in queues and/or periodical processing.
  • The persistent state of the request may...

Utilizing shared service libraries

If you choose the uniform microservices approach, it is very useful to have a shared library (or several libraries) that all services use and implement many cross-cutting concerns, such as the following:

  • Configuration
  • Secret management
  • Service discovery
  • API wrapping
  • Logging
  • Distributed tracing

This library may implement whole workflows, such as authentication and authorization, that interact with other microservices or third-party dependencies and do the heavy lifting for each microservice. This way, the microservice is only responsible for using these libraries properly and implements its own functionality.

This approach can work even if you choose the polyglot path and support multiple languages. You can implement this library for all the supported languages and the services themselves can be implemented in different languages.

However, there...

Choosing a source control strategy

This is a very interesting scenario. There are two main approaches: monorepo and multiple repos. Let's explore the pros and cons of each.

Monorepo

In the monorepo approach, your entire code base is in a single source control repository. It is very easy to perform operations over the entire code base. Whenever you make a change, it is reflected immediately in your entire code base. Versioning is pretty much off the table. That's great for keeping all your code in sync. But, if you do need to upgrade some parts of your systems incrementally, you'll need to come up with workarounds, such as creating a separate copy with your new changes. Also, the fact that your source code...

Creating a data strategy

One the most important responsibilities of a software system is to manage data. There are many types of data, and most of the data, should survive any failure of the system or you should be able to reconstruct it. Data often has complex relationships with other data. This is very explicit with relational databases, but exists in other types of data, too. Monoliths typically use large data stores that keep all the related data and, as a result, can perform queries and transactions over the entire set of data. Microservices are different. Each microservice is autonomous and responsible for its data. However, the system as a whole needs to query and operate over data that is now stored in many independent data stores and managed by many different services. Let's examine how to address this challenge using best practices.

...

Summary

In this chapter, we covered a lot of ground. We discussed the basic principle of microservices—less is more—and how breaking down your system to many small and self-contained microservices can help it scale. We also discussed the challenges that face developers utilizing the microservices architecture. We provided a slew of concepts, options, best practices, and pragmatic advice on architecting microservice-based systems. At this point, you should appreciate the flexibility that microservices offer, but also be a little apprehensive of the many ways you can choose to utilize them.

In the rest of the book, we will explore the terrain in detail and together build a microservice-based system using some of the best available frameworks and tools and deploy it on Kubernetes. In the next chapter, you'll meet Delinkcious—our sample application—...

Further reading

Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • Learn to design a scalable architecture by building continuous integration (CI) pipelines with Kubernetes
  • Get an in-depth understanding of role-based access control (RBAC), continuous deployment (CD), and observability
  • Monitor a Kubernetes cluster with Prometheus and Grafana

Description

Kubernetes is among the most popular open source platforms for automating the deployment, scaling, and operations of application containers across clusters of hosts, providing a container-centric infrastructure. Hands-On Microservices with Kubernetes starts by providing you with in-depth insights into the synergy between Kubernetes and microservices. You will learn how to use Delinkcious, which will serve as a live lab throughout the book to help you understand microservices and Kubernetes concepts in the context of a real-world application. Next, you will get up to speed with setting up a CI/CD pipeline and configuring microservices using Kubernetes ConfigMaps. As you cover later chapters, you will gain hands-on experience in securing microservices and implementing REST, gRPC APIs, and a Delinkcious data store. In addition to this, you’ll explore the Nuclio project, run a serverless task on Kubernetes, and manage and implement data-intensive tests. Toward the concluding chapters, you’ll deploy microservices on Kubernetes and learn to maintain a well-monitored system. Finally, you’ll discover the importance of service meshes and how to incorporate Istio into the Delinkcious cluster. By the end of this book, you’ll have gained the skills you need to implement microservices on Kubernetes with the help of effective tools and best practices.

Who is this book for?

This book is for developers, DevOps engineers, or anyone who wants to develop large-scale microservice-based systems on top of Kubernetes. If you are looking to use Kubernetes on live production projects or want to migrate existing systems to a modern containerized microservices system, then this book is for you. Coding skills, together with some knowledge of Docker, Kubernetes, and cloud concepts will be useful.

What you will learn

  • Understand the synergy between Kubernetes and microservices
  • Create a complete CI/CD pipeline for your microservices on Kubernetes
  • Develop microservices on Kubernetes with the Go kit framework using best practices
  • Manage and monitor your system using Kubernetes and open source tools
  • Expose your services through REST and gRPC APIs
  • Implement and deploy serverless functions as a service
  • Externalize authentication, authorization, and traffic shaping using a service mesh
  • Run a Kubernetes cluster in the cloud on Google Kubernetes Engine

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Jul 05, 2019
Length: 502 pages
Edition : 1st
Language : English
ISBN-13 : 9781789809732
Vendor :
Google
Tools :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Product feature icon AI Assistant (beta) to help accelerate your learning
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Product Details

Publication date : Jul 05, 2019
Length: 502 pages
Edition : 1st
Language : English
ISBN-13 : 9781789809732
Vendor :
Google
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
$199.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts
$279.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total $ 153.97
DevOps with Kubernetes
$54.99
Enterprise API Management
$54.99
Hands-On Microservices with Kubernetes
$43.99
Total $ 153.97 Stars icon
Banner background image

Table of Contents

15 Chapters
Introduction to Kubernetes for Developers Chevron down icon Chevron up icon
Getting Started with Microservices Chevron down icon Chevron up icon
Delinkcious - the Sample Application Chevron down icon Chevron up icon
Setting Up the CI/CD Pipeline Chevron down icon Chevron up icon
Configuring Microservices with Kubernetes Chevron down icon Chevron up icon
Securing Microservices on Kubernetes Chevron down icon Chevron up icon
Talking to the World - APIs and Load Balancers Chevron down icon Chevron up icon
Working with Stateful Services Chevron down icon Chevron up icon
Running Serverless Tasks on Kubernetes Chevron down icon Chevron up icon
Testing Microservices Chevron down icon Chevron up icon
Deploying Microservices Chevron down icon Chevron up icon
Monitoring, Logging, and Metrics Chevron down icon Chevron up icon
Service Mesh - Working with Istio Chevron down icon Chevron up icon
The Future of Microservices and Kubernetes Chevron down icon Chevron up icon
Other Books You May Enjoy Chevron down icon Chevron up icon

Customer reviews

Top Reviews
Rating distribution
Full star icon Full star icon Full star icon Full star icon Full star icon 5
(9 Ratings)
5 star 100%
4 star 0%
3 star 0%
2 star 0%
1 star 0%
Filter icon Filter
Top Reviews

Filter reviews by




David Sep 10, 2019
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Very in depth and interesting read. Highly recommended for both novice and experienced Kubernetes professionals. Some very good references for extending your Kubernetes knowledge.
Amazon Verified review Amazon
Siva Aug 06, 2019
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Well written by strongly explaining the fundamentals and the need of microservices. The source code provided is a great add-on to try things hands on.
Amazon Verified review Amazon
Donald E Lutz Jan 23, 2020
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Well written description on how Microservices work with Kubernetes as well as how to use cloud native concepts.
Amazon Verified review Amazon
Itay Jul 28, 2019
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Amazing book!A great book that helps you understand and aquire the tools needed in building scalable infrastructure to cloud-based applications.A must read for designers on their first steps.. Or even a more experienced designers!
Amazon Verified review Amazon
Andrew Harmon Aug 12, 2021
Full star icon Full star icon Full star icon Full star icon Full star icon 5
For a personal project, I've was looking to learn more about Kubernetes, micro-service architecture, and Go backend applications.Lucky for me, this book covered all three. While it doesn't go super in-depth for each, it does a good job of exploring each topic enough to make you more comfortable with them and giving you direction for further learning.My one complaint is that some of the code snippets in the book are heavily abstracted which can make them hard to understand on their own. The author provides a public git repo with the full code touched on in the book which gives some much needed context to many of the code snippets.If you're interested in learning how to build a web app backend in 2021, I'd recommend you start here.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.