Hands-On Microservices with Kubernetes
eBook - ePub

Hands-On Microservices with Kubernetes

Build, deploy, and manage scalable microservices on Kubernetes

Gigi Sayfan

Partager le livre
  1. 502 pages
  2. English
  3. ePUB (adapté aux mobiles)
  4. Disponible sur iOS et Android
eBook - ePub

Hands-On Microservices with Kubernetes

Build, deploy, and manage scalable microservices on Kubernetes

Gigi Sayfan

DĂ©tails du livre
Aperçu du livre
Table des matiĂšres
Citations

À propos de ce livre

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.

Foire aux questions

Comment puis-je résilier mon abonnement ?
Il vous suffit de vous rendre dans la section compte dans paramĂštres et de cliquer sur « RĂ©silier l’abonnement ». C’est aussi simple que cela ! Une fois que vous aurez rĂ©siliĂ© votre abonnement, il restera actif pour le reste de la pĂ©riode pour laquelle vous avez payĂ©. DĂ©couvrez-en plus ici.
Puis-je / comment puis-je télécharger des livres ?
Pour le moment, tous nos livres en format ePub adaptĂ©s aux mobiles peuvent ĂȘtre tĂ©lĂ©chargĂ©s via l’application. La plupart de nos PDF sont Ă©galement disponibles en tĂ©lĂ©chargement et les autres seront tĂ©lĂ©chargeables trĂšs prochainement. DĂ©couvrez-en plus ici.
Quelle est la différence entre les formules tarifaires ?
Les deux abonnements vous donnent un accĂšs complet Ă  la bibliothĂšque et Ă  toutes les fonctionnalitĂ©s de Perlego. Les seules diffĂ©rences sont les tarifs ainsi que la pĂ©riode d’abonnement : avec l’abonnement annuel, vous Ă©conomiserez environ 30 % par rapport Ă  12 mois d’abonnement mensuel.
Qu’est-ce que Perlego ?
Nous sommes un service d’abonnement Ă  des ouvrages universitaires en ligne, oĂč vous pouvez accĂ©der Ă  toute une bibliothĂšque pour un prix infĂ©rieur Ă  celui d’un seul livre par mois. Avec plus d’un million de livres sur plus de 1 000 sujets, nous avons ce qu’il vous faut ! DĂ©couvrez-en plus ici.
Prenez-vous en charge la synthÚse vocale ?
Recherchez le symbole Écouter sur votre prochain livre pour voir si vous pouvez l’écouter. L’outil Écouter lit le texte Ă  haute voix pour vous, en surlignant le passage qui est en cours de lecture. Vous pouvez le mettre sur pause, l’accĂ©lĂ©rer ou le ralentir. DĂ©couvrez-en plus ici.
Est-ce que Hands-On Microservices with Kubernetes est un PDF/ePUB en ligne ?
Oui, vous pouvez accĂ©der Ă  Hands-On Microservices with Kubernetes par Gigi Sayfan en format PDF et/ou ePUB ainsi qu’à d’autres livres populaires dans Computer Science et Systems Architecture. Nous disposons de plus d’un million d’ouvrages Ă  dĂ©couvrir dans notre catalogue.

Informations

Année
2019
ISBN
9781789809732
Édition
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 ...

Table des matiĂšres