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

Arrow left icon
Profile Icon Gigi Sayfan
Arrow right icon
$19.99 per month
Full star icon Full star icon Full star icon Full star icon Full star icon 5 (9 Ratings)
Paperback Jul 2019 502 pages 1st Edition
eBook
$20.98 $29.99
Paperback
$43.99
Subscription
Free Trial
Renews at $19.99p/m
Arrow left icon
Profile Icon Gigi Sayfan
Arrow right icon
$19.99 per month
Full star icon Full star icon Full star icon Full star icon Full star icon 5 (9 Ratings)
Paperback Jul 2019 502 pages 1st Edition
eBook
$20.98 $29.99
Paperback
$43.99
Subscription
Free Trial
Renews at $19.99p/m
eBook
$20.98 $29.99
Paperback
$43.99
Subscription
Free Trial
Renews at $19.99p/m

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing
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 : 9781789805468
Vendor :
Google
Languages :
Tools :

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing

Product Details

Publication date : Jul 05, 2019
Length: 502 pages
Edition : 1st
Language : English
ISBN-13 : 9781789805468
Vendor :
Google
Languages :
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

What is included in a Packt subscription? Chevron down icon Chevron up icon

A subscription provides you with full access to view all Packt and licnesed content online, this includes exclusive access to Early Access titles. Depending on the tier chosen you can also earn credits and discounts to use for owning content

How can I cancel my subscription? Chevron down icon Chevron up icon

To cancel your subscription with us simply go to the account page - found in the top right of the page or at https://subscription.packtpub.com/my-account/subscription - From here you will see the ‘cancel subscription’ button in the grey box with your subscription information in.

What are credits? Chevron down icon Chevron up icon

Credits can be earned from reading 40 section of any title within the payment cycle - a month starting from the day of subscription payment. You also earn a Credit every month if you subscribe to our annual or 18 month plans. Credits can be used to buy books DRM free, the same way that you would pay for a book. Your credits can be found in the subscription homepage - subscription.packtpub.com - clicking on ‘the my’ library dropdown and selecting ‘credits’.

What happens if an Early Access Course is cancelled? Chevron down icon Chevron up icon

Projects are rarely cancelled, but sometimes it's unavoidable. If an Early Access course is cancelled or excessively delayed, you can exchange your purchase for another course. For further details, please contact us here.

Where can I send feedback about an Early Access title? Chevron down icon Chevron up icon

If you have any feedback about the product you're reading, or Early Access in general, then please fill out a contact form here and we'll make sure the feedback gets to the right team. 

Can I download the code files for Early Access titles? Chevron down icon Chevron up icon

We try to ensure that all books in Early Access have code available to use, download, and fork on GitHub. This helps us be more agile in the development of the book, and helps keep the often changing code base of new versions and new technologies as up to date as possible. Unfortunately, however, there will be rare cases when it is not possible for us to have downloadable code samples available until publication.

When we publish the book, the code files will also be available to download from the Packt website.

How accurate is the publication date? Chevron down icon Chevron up icon

The publication date is as accurate as we can be at any point in the project. Unfortunately, delays can happen. Often those delays are out of our control, such as changes to the technology code base or delays in the tech release. We do our best to give you an accurate estimate of the publication date at any given time, and as more chapters are delivered, the more accurate the delivery date will become.

How will I know when new chapters are ready? Chevron down icon Chevron up icon

We'll let you know every time there has been an update to a course that you've bought in Early Access. You'll get an email to let you know there has been a new chapter, or a change to a previous chapter. The new chapters are automatically added to your account, so you can also check back there any time you're ready and download or read them online.

I am a Packt subscriber, do I get Early Access? Chevron down icon Chevron up icon

Yes, all Early Access content is fully available through your subscription. You will need to have a paid for or active trial subscription in order to access all titles.

How is Early Access delivered? Chevron down icon Chevron up icon

Early Access is currently only available as a PDF or through our online reader. As we make changes or add new chapters, the files in your Packt account will be updated so you can download them again or view them online immediately.

How do I buy Early Access content? Chevron down icon Chevron up icon

Early Access is a way of us getting our content to you quicker, but the method of buying the Early Access course is still the same. Just find the course you want to buy, go through the check-out steps, and you’ll get a confirmation email from us with information and a link to the relevant Early Access courses.

What is Early Access? Chevron down icon Chevron up icon

Keeping up to date with the latest technology is difficult; new versions, new frameworks, new techniques. This feature gives you a head-start to our content, as it's being created. With Early Access you'll receive each chapter as it's written, and get regular updates throughout the product's development, as well as the final course as soon as it's ready.We created Early Access as a means of giving you the information you need, as soon as it's available. As we go through the process of developing a course, 99% of it can be ready but we can't publish until that last 1% falls in to place. Early Access helps to unlock the potential of our content early, to help you start your learning when you need it most. You not only get access to every chapter as it's delivered, edited, and updated, but you'll also get the finalized, DRM-free product to download in any format you want when it's published. As a member of Packt, you'll also be eligible for our exclusive offers, including a free course every day, and discounts on new and popular titles.