Hands-On Microservices with Kubernetes
eBook - ePub

Hands-On Microservices with Kubernetes

Build, deploy, and manage scalable microservices on Kubernetes

Gigi Sayfan

Compartir libro
  1. 502 páginas
  2. English
  3. ePUB (apto para móviles)
  4. Disponible en iOS y Android
eBook - ePub

Hands-On Microservices with Kubernetes

Build, deploy, and manage scalable microservices on Kubernetes

Gigi Sayfan

Detalles del libro
Vista previa del libro
Índice
Citas

Información del 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.

Preguntas frecuentes

¿Cómo cancelo mi suscripción?
Simplemente, dirígete a la sección ajustes de la cuenta y haz clic en «Cancelar suscripción». Así de sencillo. Después de cancelar tu suscripción, esta permanecerá activa el tiempo restante que hayas pagado. Obtén más información aquí.
¿Cómo descargo los libros?
Por el momento, todos nuestros libros ePub adaptables a dispositivos móviles se pueden descargar a través de la aplicación. La mayor parte de nuestros PDF también se puede descargar y ya estamos trabajando para que el resto también sea descargable. Obtén más información aquí.
¿En qué se diferencian los planes de precios?
Ambos planes te permiten acceder por completo a la biblioteca y a todas las funciones de Perlego. Las únicas diferencias son el precio y el período de suscripción: con el plan anual ahorrarás en torno a un 30 % en comparación con 12 meses de un plan mensual.
¿Qué es Perlego?
Somos un servicio de suscripción de libros de texto en línea que te permite acceder a toda una biblioteca en línea por menos de lo que cuesta un libro al mes. Con más de un millón de libros sobre más de 1000 categorías, ¡tenemos todo lo que necesitas! Obtén más información aquí.
¿Perlego ofrece la función de texto a voz?
Busca el símbolo de lectura en voz alta en tu próximo libro para ver si puedes escucharlo. La herramienta de lectura en voz alta lee el texto en voz alta por ti, resaltando el texto a medida que se lee. Puedes pausarla, acelerarla y ralentizarla. Obtén más información aquí.
¿Es Hands-On Microservices with Kubernetes un PDF/ePUB en línea?
Sí, puedes acceder a Hands-On Microservices with Kubernetes de Gigi Sayfan en formato PDF o ePUB, así como a otros libros populares de Computer Science y Systems Architecture. Tenemos más de un millón de libros disponibles en nuestro catálogo para que explores.

Información

Año
2019
ISBN
9781789809732
Edición
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 ...

Índice