Getting Started with Istio Service Mesh: Manage Microservices in Kubernetes
By Rahul Sharma and Avinash Singh
()
About this ebook
Build an in-depth understanding of the Istio service mesh and see why a service mesh is required for a distributed application. This book covers the Istio architecture and its features using a hands-on approach with language-neutral examples. To get your Istio environment up and running, you will go through its setup and learn the concepts of control plane and data plane. You will become skilled with the new concepts and apply them with best practices to continuously deliver applications.
What You Will Learn
- Discover the Istio architecture components and the Envoy proxy
- Master traffic management for service routing and application deployment
- Build application resiliency using timeout, circuit breakers, and connection pools
- Monitor using Prometheus and Grafana
- Configure application security
Who This Book Is For
Developers and project managers who are trying to run their application using Kubernetes. The book is not specific for any programming language even though all examples will be in Java or Python.
Rahul Sharma
Rahul Sharma is a former newspaper editor who now advises corporates on public affairs, policy issues, business and communication strategy. He is a keen China watcher since his days as a wire agency correspondent and editor in Asia, and has sustained his deep interest in international affairs, global diplomacy and economy. A co-founder and former President of the Public Affairs Forum of India, he also curates a foreign policy blog in his free time.
Read more from Rahul Sharma
Traefik API Gateway for Microservices: With Java and Python Microservices Deployed in Kubernetes Rating: 0 out of 5 stars0 ratingsThe Golden Heart and the Dark Heart Rating: 0 out of 5 stars0 ratings
Related to Getting Started with Istio Service Mesh
Related ebooks
Microservices for the Enterprise: Designing, Developing, and Deploying Rating: 0 out of 5 stars0 ratingsAdvanced Platform Development with Kubernetes: Enabling Data Management, the Internet of Things, Blockchain, and Machine Learning Rating: 0 out of 5 stars0 ratingsGetting Started with Terraform Rating: 5 out of 5 stars5/5Hands-on GitHub Actions: Implement CI/CD with GitHub Action Workflows for Your Applications Rating: 0 out of 5 stars0 ratingsRedis Essentials Rating: 0 out of 5 stars0 ratingsHands-on Azure Pipelines: Understanding Continuous Integration and Deployment in Azure DevOps Rating: 0 out of 5 stars0 ratingsOpenStack Sahara Essentials Rating: 0 out of 5 stars0 ratingsDocker Demystified: Learn How to Develop and Deploy Applications Using Docker (English Edition) Rating: 0 out of 5 stars0 ratingsInfrastructure Automation with Terraform: Automate and Orchestrate your Infrastructure with Terraform Across AWS and Microsoft Azure Rating: 0 out of 5 stars0 ratingsAWS DynamoDB A Complete Guide Rating: 0 out of 5 stars0 ratingsAkka Cookbook Rating: 2 out of 5 stars2/5Podman in Action: Secure, rootless containers for Kubernetes, microservices, and more Rating: 0 out of 5 stars0 ratingsDeploy Containers on AWS: With EC2, ECS, and EKS Rating: 0 out of 5 stars0 ratingsElasticsearch Blueprints Rating: 0 out of 5 stars0 ratingsKubernetes Secrets Management Rating: 0 out of 5 stars0 ratingsOpenStack in Action Rating: 0 out of 5 stars0 ratingsSpring Microservices in Action, Second Edition Rating: 0 out of 5 stars0 ratingsKubernetes A Complete Guide Rating: 0 out of 5 stars0 ratingsOnline Identity A Complete Guide - 2020 Edition Rating: 0 out of 5 stars0 ratingsIstio in Action Rating: 0 out of 5 stars0 ratingsEnterprise Bug Busting: From Testing through CI/CD to Deliver Business Results Rating: 0 out of 5 stars0 ratingsPro Spring MVC with WebFlux: Web Development in Spring Framework 5 and Spring Boot 2 Rating: 0 out of 5 stars0 ratingsAzure Infrastructure as Code: With ARM templates and Bicep Rating: 0 out of 5 stars0 ratingsIPv6 Complete Self-Assessment Guide Rating: 0 out of 5 stars0 ratingsDocker Complete Self-Assessment Guide Rating: 0 out of 5 stars0 ratingsQuick Start Kubernetes Rating: 0 out of 5 stars0 ratingsAnsible For Containers and Kubernetes By Examples Rating: 0 out of 5 stars0 ratings
Programming For You
Python: For Beginners A Crash Course Guide To Learn Python in 1 Week Rating: 4 out of 5 stars4/5Python Programming : How to Code Python Fast In Just 24 Hours With 7 Simple Steps Rating: 4 out of 5 stars4/5HTML & CSS: Learn the Fundaments in 7 Days Rating: 4 out of 5 stars4/5Java for Beginners: A Crash Course to Learn Java Programming in 1 Week Rating: 5 out of 5 stars5/5SQL: For Beginners: Your Guide To Easily Learn SQL Programming in 7 Days Rating: 5 out of 5 stars5/5SQL QuickStart Guide: The Simplified Beginner's Guide to Managing, Analyzing, and Manipulating Data With SQL Rating: 4 out of 5 stars4/5Learn to Code. Get a Job. The Ultimate Guide to Learning and Getting Hired as a Developer. Rating: 5 out of 5 stars5/5Coding All-in-One For Dummies Rating: 4 out of 5 stars4/5Python Machine Learning By Example Rating: 4 out of 5 stars4/5101 Amazing Nintendo NES Facts: Includes facts about the Famicom Rating: 4 out of 5 stars4/5Pokemon Go: Guide + 20 Tips and Tricks You Must Read Hints, Tricks, Tips, Secrets, Android, iOS Rating: 5 out of 5 stars5/5Linux: Learn in 24 Hours Rating: 5 out of 5 stars5/5Grokking Algorithms: An illustrated guide for programmers and other curious people Rating: 4 out of 5 stars4/5Learn SQL in 24 Hours Rating: 5 out of 5 stars5/5SQL All-in-One For Dummies Rating: 3 out of 5 stars3/5Excel : The Ultimate Comprehensive Step-By-Step Guide to the Basics of Excel Programming: 1 Rating: 5 out of 5 stars5/5PYTHON: Practical Python Programming For Beginners & Experts With Hands-on Project Rating: 5 out of 5 stars5/5Modern C++ for Absolute Beginners: A Friendly Introduction to C++ Programming Language and C++11 to C++20 Standards Rating: 0 out of 5 stars0 ratingsPython Projects for Beginners: A Ten-Week Bootcamp Approach to Python Programming Rating: 0 out of 5 stars0 ratings
Reviews for Getting Started with Istio Service Mesh
0 ratings0 reviews
Book preview
Getting Started with Istio Service Mesh - Rahul Sharma
© Rahul Sharma, Avinash Singh 2020
R. Sharma, A. SinghGetting Started with Istio Service Meshhttps://doi.org/10.1007/978-1-4842-5458-5_1
1. Quick Tour of Kubernetes
Rahul Sharma¹ and Avinash Singh²
(1)
Delhi, India
(2)
Gurgaon, Haryana, India
Kubernetes originated from the Greek word κυβερνήτης, meaning governor,
helmsman,
or pilot.
That’s what the founders Joe Beda, Brendan Burns, and Craig McLuckie had in mind. They wanted to drive a container ship
leading to the creation of a container orchestration platform, which these days is becoming the de facto standard for running microservices in the cloud.
In late 2013, the declarative configuration of IaaS started to gain strength over bash scripts for cloud infrastructure. Though companies like Netflix were popularizing immutable infrastructures, that came with the cost of heavyweight virtual machine images. Docker became a savior by offering a lightweight container. It allowed a simple way to package, distribute, and deploy applications on a machine as compared to heavyweight VM images. But running Docker containers on a single machine was not a solution for scaling applications, which required deploying Docker containers across multiple machines. This created a need for an orchestrator.
Kubernetes development started by focusing on the key features of an orchestrator, such as replication of an application with load balancing and service discovery, followed by basic health checks and repair features to ensure availability. Kubernetes was also released as an open source version of Borg, a large-scale cluster manager at Google running hundreds of thousands of jobs for different applications across clusters, with each cluster having tens of thousands of machines. In the middle of 2015, Kubernetes was committed to GitHub and opened for developers to start contributing. In no time, big players like Microsoft, Red Hat, IBM, Docker, Mesosphere, CoreOS, and SaltStack joined the community and started contributing. In time, multiple modules were developed in and on Kubernetes, ensuring the basic orchestrator was intact and optimized over time.
With the increasing popularity of Kubernetes in the developer community, developers started making the deployment process even simpler. Helm, a package manager for Kubernetes, was launched in early 2016, aimed at simplifying how one defines, installs, and upgrades complex Kubernetes applications. Sometime in the middle of 2016, Minikube was released; Minikube brought the Kubernetes environment to a developer’s local system. We will be using Minikube later in the chapter for our example Kubernetes application. One of the popular applications featuring Kubernetes in production was PokemonGo. At the time, it was one of the largest Kubernetes deployments on Google Container Engine. They released a case study explaining how Kubernetes helped the company scale when the traffic on the application was way beyond expectations.
Later, in 2017 and early 2018, cloud players like AWS and DigitalOcean made room for Kubernetes on their stacks. Kubernetes today is a portable, extensible, open source platform for managing containerized applications. It has micro components taking care of the basic features of the orchestrator. Let’s start by taking a look at what K8s, an abbreviation for the word Kubernetes, consists of.
K8s Architecture/Components
Kubernetes follows a client-server architecture where the master is installed on a machine and nodes are distributed across multiple machines accessible via the master. Figure 1-1 shows the building blocks of the Kubernetes architecture. The K8s master and K8s workers are part of the Kubernetes control plane, whereas the container registry may lie outside of the control plane.
../images/483921_1_En_1_Chapter/483921_1_En_1_Fig1_HTML.jpgFigure 1-1
Kubernetes architecture overview
Kubernetes Master
The Kubernetes master is the main node responsible for managing the entire cluster. The orchestration of the K8s workers is handled by this node. This node is replicable to avoid any single point of failure. The control panel accesses the master only to make modifications to the cluster. The master comprises four major components.
API server: This is the front end of a Kubernetes control plane. It maintains RESTful web services to define and configure a Kubernetes cluster.
etcd: This is a highly available component maintaining a record of all the objects running in the system. Any changes in the configuration of Kubernetes are stored here, and the changes are allowed to be watched for immediate action.
Scheduler: This schedules workloads on Kubernetes workers in the form of pods. We will cover pods in the next section. The scheduler reads through the resource requirements of each pod and distributes the pods throughout the cluster based on availability. By default, it also tries to distribute pod replicas to different nodes to maintain high availability.
Controller manager: This runs controllers in the background that are responsible for different important tasks in the cluster. Controllers keep watch on etcd for configuration changes and take the cluster to the desired state; on the other end, the control loops watch for the changes in the cluster and work to maintain the desired state as per etcd. Let’s visit a few controller examples to understand what controllers do in the cluster.
Node controller: This monitors the nodes in the cluster and responds when a node comes up or goes down. This is important so the scheduler can align pods per the availability of a node and maintain state per etcd.
Endpoint controller: This joins services and pods by creating endpoint records in the API, and it alters the DNS configuration to return an address pointing to one of the pods running the service.
Replication controller: Replication is a general practice to maintain the high availability of an application. The replication controller makes sure the desired number of pod replicas/copies is running in the cluster.
We will be looking at these controllers in action later in this chapter. In addition, there is a cloud controller manager, which allows cloud providers to integrate with Kubernetes easily by using plugins.
Kubernetes Workers
It might be clear by now that the actual application runs on worker nodes. Earlier these were also referred to as minions. The terms minions and nodes are still used interchangeably in some documentation. Each node has three major components.
Kubelet: Kubelet is the primary node agent running on each node and monitoring that the containers on the node are running and healthy. Kubelet takes a set of PodSpecs, which is a YAML or JSON object describing a pod, and monitors the containers described in those specs only. Note that there can be other containers, other than the containers listed in PodSpecs, running on the node, but Kubelet does not monitor these containers.
Kube-proxy: The Kubernetes master scheduler usually runs multiple services on a node. Kube-proxy creates a network proxy and load balancer for these services. It can do simple TCP, UDP, and SCTP stream forwarding or round-robin TCP, UDP, and SCTP forwarding across a set of back ends. It also allows, if configured, nodes to be exposed to the Internet.
Pods: A pod is the smallest unit of the Kubernetes object model that can be created, deployed, or destroyed. A Kubernetes pod usually has a single container but is allowed to contain a group of tightly coupled containers as well. A pod represents a running process on a cluster. It can be used in two broad ways.
a.
Single-container pod: This was the most common Kubernetes use case, also called one container per pod. The pod wraps the container and provides an abstract layer to Kubernetes to access or modify the container.
b.
Multiple-container pod: There are scenarios when an application requires multiple tightly coupled containers that are sharing resources. In such scenarios, a pod builds a wrapper on these containers and treats them as a single service. An example would be one container serving REST APIs to end users, with a sidecarcounting the number of requests implementing the API limitation. The containers inside a pod share the same IP that was given to the pod and share the same set of storage. In the following chapters, we will be looking at sidecars in action with Istio.
Containers, as stated earlier, deployed inside each pod run the service. The container packaging and storage depend on the container runtime and registry.
Container runtime: To understand this, let’s try to understand what a container is. A container is a unit of code packaged with its dependencies that creates an artifact that can run quickly on different computing environments. The container runtime lets someone run containers by providing a basic set of resources and libraries, which combined with the container’s package boots up an application. An application in a container has the liberty of its own environment including storage, network, etc., with the restriction of how much of each resource can be used. The container runtime also manages container images on a node. There are multiple container runtimes available, so let’s go through a couple of them.
a.
Rocket: Rocket, also referred to as rkt, is a container runtime provided by coreOS. Rkt uses a few similar terms as Kubernetes. A pod is the core execution unit of Rkt. Please note, though, that this pod is different from a Kubernetes pod. Rocket allows a container configuration at a more granular level; in other words, one may set the memory limit of an application running inside the pod. Rocket follows the app container specification in its containers but supports Docker images as well. The main difference brought in by Rocket is that it runs in daemon-less mode; the containers launched don’t run under the umbrella of a daemon but are given separate process IDs on the base machine. This allows it to run multiple processes inside the same container and restart any of them without killing the parent container.
b.
Docker: Docker is one of the most popular container runtimes these days. As stated earlier, its solution to provide lightweight containers was the reason orchestration was required, which led to the need for Kubernetes. The Docker community is vast because one may easily get any common package available as a Docker image in the registry.
Which container runtime to choose is a matter of personal preference and also depends on how complex your codebase is and the kind of resources it depends on. Using Rocket, you may be able to pass on file descriptors from one process to another with the file descriptions still listening. Though these kinds of scenarios are not common, they are important ones to consider before choosing a container runtime. In this book, we will be using Docker as our container runtime.
Container registry: Each container generation requires code development, adding libraries from different package managers and creating the basic environment to run the code. A container can be built every time when deploying, but getting the latest code, getting new libraries, and preparing the environment every time is time-consuming. To simplify this, developers store their once-created container and use it whenever required. The container registry is the place that allows developers to save their container images and use them as and when required. Individual providers such as Azure, Docker, and Google have their own container registries that host images in a highly available environment with access-level restrictions.
Kubernetes uses the Container Runtime Interface (CRI) to interact with the container runtime. Since Kubernetes 1.5, container runtimes are expected to implement CRI, which acts as a bridge between Kubernetes Kubelet and the container runtime. CRI provides an abstraction between Kubernetes and the container runtimes and enables Kubernetes to run independent of the container runtimes.
Now that you understand the architecture of Kubernetes, let’s try to understand a few important terminologies used in Kubernetes.
Kubernetes Terminology
There are a few terms that we may be using frequently throughout this book. Let’s go through a few of them to avoid any confusion in future references.
Deployment: A deployment is an abstract unit built on pods. To deploy an application or a microservice, one needs to run it inside a pod. To do so, a deployment configuration is created where one states what needs to be deployed along with the number of replicas of the application. On submitting this configuration to Kubernetes, a set of pods is spawned by the deployment controller deploying the application with the configured replicas.
Image: An image is the software/container that will be deployed on the cluster. In this book, we will be using image interchangeably with Docker image.
Kubectl: This is a CLI to interact with a Kubernetes cluster. We will be using this to deploy clusters, check the status of them, and update our clusters.
Namespace: As the name suggests, this is used to group multiple virtual clusters on the same Kubernetes instance or organize the resources within the same cluster. It allows each resource to be identified uniquely.
Replicaset: This is the same as a replication controller with an additional support of a set-based selector rather than an equality-based selector. This will be clearer in the example later in this chapter.
Service: This is a description of how an application deployed on one or multiple pods can be accessed internally or externally. Since pods are not permanent and Kubernetes may relocate pods from time to time based on availability, relying on direct access to pods is not recommended. The service discovers the application running in pods and provides access to them via ports, load balancers, or other mechanisms.
StatefulSet: This is similar to a deployment managing the ordering and uniqueness of the pods. In other words, if a pod dies, a new pod is spawned by the StatefulSet controller with the same identity and resources as the dead pod.
These are not all the terms used in this book, but the list should be sufficient to get us started on creating our first Kubernetes cluster. Before we do that, we need to set up the Kubernetes environment.
Set Up a Kubernetes Cluster
As mentioned, Minikube is a tool to run a Kubernetes cluster locally. Since it’s local, it provides a single-node Kubernetes cluster. Minikube starts a server of its own on a hypervisor. For simplicity, we will use VirtualBox as a hypervisor, which is available for Windows, Linux, and macOS.
Set Up VirtualBox
Before starting, make sure AMD-v or VT-x virtualization is enabled in your system BIOS. This allows you to run VirtualBox instances on the machine. Download and install VirtualBox by following the steps at https://www.virtualbox.org/wiki/Downloads. Once the installation is complete,