Hands-On Microservices with Kubernetes
eBook - ePub

Hands-On Microservices with Kubernetes

Build, deploy, and manage scalable microservices on Kubernetes

Gigi Sayfan

Condividi libro
  1. 502 pagine
  2. English
  3. ePUB (disponibile sull'app)
  4. Disponibile su iOS e Android
eBook - ePub

Hands-On Microservices with Kubernetes

Build, deploy, and manage scalable microservices on Kubernetes

Gigi Sayfan

Dettagli del libro
Anteprima del libro
Indice dei contenuti
Citazioni

Informazioni sul libro

Enhance your skills in building scalable infrastructure for your cloud-based applications

Key Features

  • 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

Book 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.

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

Who this book is 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.

Domande frequenti

Come faccio ad annullare l'abbonamento?
È semplicissimo: basta accedere alla sezione Account nelle Impostazioni e cliccare su "Annulla abbonamento". Dopo la cancellazione, l'abbonamento rimarrà attivo per il periodo rimanente già pagato. Per maggiori informazioni, clicca qui
È possibile scaricare libri? Se sì, come?
Al momento è possibile scaricare tramite l'app tutti i nostri libri ePub mobile-friendly. Anche la maggior parte dei nostri PDF è scaricabile e stiamo lavorando per rendere disponibile quanto prima il download di tutti gli altri file. Per maggiori informazioni, clicca qui
Che differenza c'è tra i piani?
Entrambi i piani ti danno accesso illimitato alla libreria e a tutte le funzionalità di Perlego. Le uniche differenze sono il prezzo e il periodo di abbonamento: con il piano annuale risparmierai circa il 30% rispetto a 12 rate con quello mensile.
Cos'è Perlego?
Perlego è un servizio di abbonamento a testi accademici, che ti permette di accedere a un'intera libreria online a un prezzo inferiore rispetto a quello che pagheresti per acquistare un singolo libro al mese. Con oltre 1 milione di testi suddivisi in più di 1.000 categorie, troverai sicuramente ciò che fa per te! Per maggiori informazioni, clicca qui.
Perlego supporta la sintesi vocale?
Cerca l'icona Sintesi vocale nel prossimo libro che leggerai per verificare se è possibile riprodurre l'audio. Questo strumento permette di leggere il testo a voce alta, evidenziandolo man mano che la lettura procede. Puoi aumentare o diminuire la velocità della sintesi vocale, oppure sospendere la riproduzione. Per maggiori informazioni, clicca qui.
Hands-On Microservices with Kubernetes è disponibile online in formato PDF/ePub?
Sì, puoi accedere a Hands-On Microservices with Kubernetes di Gigi Sayfan in formato PDF e/o ePub, così come ad altri libri molto apprezzati nelle sezioni relative a Computer Science e Systems Architecture. Scopri oltre 1 milione di libri disponibili nel nostro catalogo.

Informazioni

Anno
2019
ISBN
9781789809732
Edizione
1

Deploying Microservices

In this chapter, we will deal with two related, yet separate themes: production deployments and development deployments. The concerns, processes, and tools that are used for these two areas are very different. In both cases, the goal is to deploy new software to the cluster, but everything else is different. With production deployments, it's desirable to keep the system stable, be able to have a predictable build and deployment experience, and most importantly, to identify and be able to roll back bad deployments. With development deployments, it's desirable to have isolated deployments for each developer, a fast turnaround, and the ability to avoid cluttering source control or the continuous integration / continuous deployment (CI/CD) system (including image registries) with temporary development versions. Due to this, divergent emphasis is beneficial to isolate production deployments from development deployments.
In this chapter, we will cover the following topics:
  • Kubernetes deployments
  • Deploying to multiple environments
  • Understanding deployment strategies (rolling updates, blue-green deployment, canary deployment)
  • Rolling back deployments
  • Managing versions and upgrades
  • Local development deployments

Technical requirements

In this chapter, we will install many tools, including the following:
  • KO
  • Ksync
  • Draft
  • Skaffold
  • Tilt
There is no need to install them ahead of time.

The code

The code is split between two Git repositories:
  • You can find the code samples here: https://github.com/PacktPublishing/Hands-On-Microservices-with-Kubernetes/tree/master/Chapter11
  • You can find the updated Delinkcious application here: https://github.com/the-gigi/delinkcious/releases/tag/v0.9

Kubernetes deployments

We talked about deployments briefly in Chapter 1, Introduction to Kubernetes for Developers, and we've used Kubernetes deployments in almost every chapter. However, before diving into more sophisticated patterns and strategies, it will be useful to review the basic building blocks and the relationships between Kubernetes deployments, Kubernetes services, and scaling or autoscaling.
Deployments are Kubernetes resources that manage pods via a ReplicaSet. A Kubernetes ReplicaSet is a group of pods that are identified by a common set of labels with a certain number of replicas. The connection between the ReplicaSet to its pods is the ownerReferences field in the pod's metadata. The ReplicaSet controller ensures that the correct number of replicas are always running. If a pod dies for whatever reason, the ReplicaSet controller will schedule a new pod in its place. The following diagram illustrates this relationship:
Deployment and ReplicaSet
We can also observe the ownership chain in the metadata with kubectl. First, let's get the name of the social graph manager pod and find the name of its ReplicaSet owner from the ownerReferences metadata:
$ kubectl get po -l svc=social-graph,app=manager
NAME READY STATUS RESTARTS AGE
social-graph-manager-7d84ffc5f7-bst7w 1/1 Running 53 20d

$ kubectl get po social-graph-manager-7d84ffc5f7-bst7w -o jsonpath="{.metadata.ownerReferences[0]['name']}"
social-graph-manager-7d84ffc5f7

$ kubectl get po social-graph-manager-7d84ffc5f7-bst7w -o jsonpath="{.metadata.ownerReferences[0]['kind']}"
ReplicaSet
Next, we'll get the name of the deployment that owns the ReplicaSet:
$ kubectl get rs social-graph-manager-7d84ffc5f7 -o jsonpath="{.metadata.ownerReferences[0]['name']}"
graph-manager

$ kubectl get rs social-graph-manager-7d84ffc5f7 -o jsonpath="{.metadata.ownerReferences[0]['kind']}"
Deployment
So, if the ReplicaSet controller takes care of managing the number of pods, what does the Deployment object add? The Deployment object encapsulates the concept of a deployment, including a deployment strategy and rollout history. It also provides deployment-oriented operations such as updating a deployment and rolling back a deployment, which we will look at later.

Deploying to multiple environments

In this section, we will create a staging environment for Delinkcious in a new staging namespace. The staging namespace will be a full-fledged copy of the default namespace that will serve as our production environment.
First, let's create the namespace:
$ kubectl create ns staging
namespace/staging created
Then, in Argo CD, we can create a new project called staging:
Argo CD staging project
Now, we need to configure all our services so that Argo CD can sync them to the staging environment. This can be a little tedious to do in the UI now that we have a substantial amount of services. Instead, we will use the Argo CD CLI and a Python 3 program called bootstrap_staging.py to automate the process. The program expects the following:
  • The staging namespace has been created.
  • The Argo CD CLI is installed and in the path.
  • The Argo CD service is available through the localhost on port 8080.
  • The Argo CD admin password is configured as the environment variable.
To expose Argo CD on the localhost at port 80, we can run the following command:
kubectl port-forward -n argocd svc/argocd-server 8080:443
Let's break down the program and understand how it works. This is a good foundation where you can develop your own custom CI/CD solutions by automating CLI tools. The only dependencies are Python's standard library modules: subprocess (allows you to run command-line tools) and os (for accessing environment variables). Here, we only need to run the Argo CD CLI.
The run() function hides all the implementation details and provides a convenient interface where you just need to pass the arguments as a string. The run() function will prepare a proper command list that can be passed to the subprocess module's check_output() function, capture the output, and decode it from bytes to a string:
import os
import subprocess

def run(cmd):
cmd = ('argocd ' + cmd).split()
output = subprocess.check_output(cmd)
return output.decode('utf-8')
The login() function utilizes run(), gets the admin password from the environment, and constructs the proper command string with all the necessary flags so that you can log in as the admin user to Argo CD:
def ...

Indice dei contenuti