Kubernetes: An Enterprise Guide
local graph
Kubernetes: An Enterprise Guide
Section titled “Kubernetes: An Enterprise Guide”chapter_01
Section titled “chapter_01”node-book_kubernetes-an-enterprise-guide_chapter-01-docker-and-container-essentials — Docker and Container Essentials
chapter_02
Section titled “chapter_02”node-book_kubernetes-an-enterprise-guide_chapter-02-deploying-kubernetes-using-kind — Deploying Kubernetes Using KinD
chapter_03
Section titled “chapter_03”node-book_kubernetes-an-enterprise-guide_chapter-03-kubernetes-bootcamp — Kubernetes Bootcamp
chapter_04
Section titled “chapter_04”node-book_kubernetes-an-enterprise-guide_chapter-04-services-load-balancing-and-network-policies — Services, Load Balancing, and Network Policies
chapter_05
Section titled “chapter_05”node-book_kubernetes-an-enterprise-guide_chapter-05-external-dns-and-global-load-balancing — External DNS and Global Load Balancing
chapter_06
Section titled “chapter_06”node-book_kubernetes-an-enterprise-guide_chapter-06-integrating-authentication-into-your-cluster — Integrating Authentication into Your Cluster
chapter_07
Section titled “chapter_07”node-book_kubernetes-an-enterprise-guide_chapter-07-rbac-policies-and-auditing — RBAC Policies and Auditing
chapter_08
Section titled “chapter_08”node-book_kubernetes-an-enterprise-guide_chapter-08-managing-secrets — Managing Secrets
chapter_09
Section titled “chapter_09”node-book_kubernetes-an-enterprise-guide_chapter-09-building-multitenant-clusters-with-vclusters — Building Multitenant Clusters with vClusters
chapter_10
Section titled “chapter_10”node-book_kubernetes-an-enterprise-guide_chapter-10-deploying-a-secured-kubernetes-dashboard — Deploying a Secured Kubernetes Dashboard
chapter_11
Section titled “chapter_11”node-book_kubernetes-an-enterprise-guide_chapter-11-extending-security-using-open-policy-agent — Extending Security Using Open Policy Agent
chapter_12
Section titled “chapter_12”node-book_kubernetes-an-enterprise-guide_chapter-12-node-security-with-gatekeeper — Node Security with Gatekeeper
chapter_13
Section titled “chapter_13”node-book_kubernetes-an-enterprise-guide_chapter-13-kubearmor-securing-your-runtime — KubeArmor Securing Your Runtime
chapter_14
Section titled “chapter_14”node-book_kubernetes-an-enterprise-guide_chapter-14-backing-up-workloads — Backing Up Workloads
chapter_15
Section titled “chapter_15”node-book_kubernetes-an-enterprise-guide_chapter-15-monitoring-clusters-and-workloads — Monitoring Clusters and Workloads
chapter_16
Section titled “chapter_16”node-book_kubernetes-an-enterprise-guide_chapter-16-an-introduction-to-istio — An Introduction to Istio
chapter_17
Section titled “chapter_17”node-book_kubernetes-an-enterprise-guide_chapter-17-building-and-deploying-applications-on-istio — Building and Deploying Applications on Istio
chapter_18
Section titled “chapter_18”node-book_kubernetes-an-enterprise-guide_chapter-18-provisioning-a-multitenant-platform — Provisioning a Multitenant Platform
chapter_19
Section titled “chapter_19”node-book_kubernetes-an-enterprise-guide_chapter-19-building-a-developer-portal — Building a Developer Portal
Preface
Section titled “Preface”Kubernetes has taken the world by storm, becoming the standard infrastructure for DevOps teams to develop, test, and run applications. Most enterprises are either running it already or are planning to run it in the next year. A look at job postings on any of the major job sites shows that just about every big-name company has Kubernetes positions open. The fast rate of adoption has led to Kubernetes-related positions growing by over 2,000% in the last 4 years.
One common problem that companies are struggling to address is the lack of enterprise Kubernetes knowledge. While Kubernetes isn’t new anymore (it just turned 10!), companies have had issues with trying to build teams to run clusters reliably. They’ve also struggled to understand how to integrate Kubernetes workloads across the multiple silos and technology stacks that are common in the enterprise world. Finding people with basic Kubernetes skills is becoming easier, but finding people with knowledge on topics that are required for enterprise clusters is still a challenge.
Who this book is for
Section titled “Who this book is for”We created this book to help DevOps teams to expand their skills beyond the basics of Kubernetes. It was created from the years of experience we have working with clusters in multiple enterprise environments.
There are many books available that introduce Kubernetes and the basics of installing clusters, creating Deployments, and using Kubernetes objects. Our plan was to create a book that would go beyond a basic cluster, and to keep the book at a reasonable length, we have not re-hashed the basics of Kubernetes. Readers should have some experience with Kubernetes and DevOps before reading this book.
While the primary focus of the book is on extending clusters with enterprise features, the first section of the book will provide a refresher on key Docker topics and Kubernetes objects. It is important that you have a solid understanding of Kubernetes objects in order to get the most out of the more advanced chapters.
What this book covers
Section titled “What this book covers”Chapter 1, Docker and Container Essentials, covers the problems Docker and Kubernetes address for developers. You will be introduced to Docker, including the Docker daemon, data, installation, and using the Docker CLI.
Chapter 2, Deploying Kubernetes Using KinD, helps with creating development clusters using KinD, a powerful tool that allows you to create clusters ranging from a single-node cluster to a full multi-node cluster. The chapter goes beyond a basic KinD cluster, explaining how to use a load balancer running HAProxy to load-balance worker nodes. By the end of the chapter, you will understand how KinD works and how to create a custom multi-node cluster, which will be used for the exercises in the chapters.
Chapter 3, Kubernetes Bootcamp, provides a refresher on Kubernetes. This chapter will cover most of the objects that a cluster includes, which will be helpful if you are new to Kubernetes. It will explain each object with a description of what each object does and its function in a cluster. It is meant to be a refresher, or a “pocket guide” to objects. It does not contain exhaustive details for each object (that would require a second book).
Chapter 4, Services, Load Balancing, and Network Policies, explains how to expose a Kubernetes Deployment using services. Each service type will be explained with examples, and you will learn how to expose them using both a layer 7 and layer 4 load balancer. In this chapter, you will go beyond the basics of a simple Ingress controller, installing MetalLB, to provide layer 4 access to services. Finally, you will learn how to provide fine-grained control over the communication between pods, enhancing security and compliance within your cluster by using Kubernetes network policies.
Chapter 5, External DNS and Global Load Balancing, will make you learn about two add-ons that benefit enterprise clusters by installing an incubator project called external-dns to provide dynamic name resolution for the services exposed by MetalLB. You will also learn how to add a Global Load Balancer to your cluster, using a project called K8GB, which provides native Kubernetes Global Load Balancing.
Chapter 6, Integrating Authentication into Your Cluster, answers the question, “Once your cluster is built, how will users access it?” In this chapter we’ll detail how OpenID Connect works and why you should use it to access your cluster. You’ll also learn how to authenticate your pipelines, and finally, we’ll also cover several anti-patterns that should be avoided and explain why they should be avoided.
Chapter 7, RBAC Policies and Auditing, explains that once users have access to a cluster, you need to know how to limit their access. Whether you are providing an entire cluster to your users or just a namespace, you’ll need to know how Kubernetes authorizes access via its role-based access control (RBAC) system. In this chapter, we’ll detail how to design RBAC policies, how to debug them, and different strategies for multi-tenancy.
Chapter 8, Managing Secrets, puts the focus on one of the hardest to implement issues in the Kubernetes world: how to manage secret data. First, we’ll look at the challenges of managing Secrets in Kubernetes. Then we’ll learn about HashiCorp’s Vault for secret management. Finally, we’ll integrate our clusters with Vault using both the Vault sidecar and the popular External Secrets Operator.
Chapter 9, Building Multitenant Clusters with vClusters, moves out of a single cluster toward breaking up clusters into tenants using the vCluster project from Loft. You’ll learn how vClusters work, how they interact with host clusters, how to securely access them, and how to automate their rollout for your tenants. We’ll also build off what we learned in Chapter 8 to integrate managed Secrets into our vClusters too!
Chapter 10, Deploying a Secured Kubernetes Dashboard, covers Kubernetes Dashboard, which is often the first thing users try to launch once a cluster is up and running. There’s quite a bit of mythology around security (or lack thereof). Your cluster will be made of other web applications too, such as network dashboards, logging systems, and monitoring dashboards. This chapter looks at how the dashboard is architected, how to properly secure it, and examples of how not to deploy it with details as to why.
Chapter 11, Extending Security Using Open Policy Agent, provides you with the guidance you need to deploy Open Policy Agent and GateKeeper to enable policies that can’t be implemented using RBAC. We’ll cover how to deploy Gatekeeper, how to write policies in Rego, and how to test your policies using OPA’s built-in testing framework.
Chapter 12, Node Security with Gatekeeper, deals with the security of the nodes that run your pods. We will discuss how to securely design your containers so they are harder to abuse and how to build policies using GateKeeper that prevent your containers from accessing resources they don’t need.
Chapter 13, KubeArmor Securing Your Runtime, presents security, which is the job of everyone, and providing tools to address attack vectors is key to running a secure and resilient cluster. In this chapter, you will learn how to secure your containers runtime by using a CNCF project called KubeArmor. KubeArmor provides an easy way to lock down containers using easy to understand policies.
Chapter 14, Backing Up Workloads, explains how to create a backup of your cluster workloads for disaster recovery or cluster migrations, using Velero. You will work hands-on to create an S3-compatible storage location using MinIO to create a backup of example workloads and persistent storage. You will then restore the backup to a brand-new cluster to simulate a cluster migration.
Chapter 15, Monitoring Clusters and Workloads, explores how to know how healthy your cluster is using Prometheus and OpenSearch. You’ll start with understanding how Kubernetes and Prometheus handle metrics, then we’ll deploy the Prometheus stack with Alertmanager and Grafana. You’ll learn how to secure the stack and how to extend it to monitor additional workloads. After we’re done with monitoring, we will move on to log aggregation with OpenSearch. We will start with exploring how logging in Kubernetes works, move on to integrating OpenSearch, and wrap up with securing access to OpenSearch with OpenUnison.
Chapter 16, An Introduction to Istio, explains that many enterprises use a service mesh to provide advanced features such as security, traffic routing, authentication, tracing, and observability to a cluster. This chapter will introduce you to Istio, a popular open-source mesh, and its architecture, along with the most commonly used resources it provides. You will deploy Istio to your KinD cluster with an example application and learn how to observe the behavior of an application using an observability tool called Kiali.
Chapter 17, Building and Deploying Applications on Istio, acknowledges that once you’ve deployed Istio, you’ll want to develop and deploy applications that use it! This chapter starts with a walk-through of the differences between monoliths and microservices and how they’re deployed. Next, we’ll step through building a micro-service to run in Istio and get into advanced topics like authentication, authorization, and service-to-service authentication for your services. You will also learn how to secure Kiali access by leveraging existing roles in Kubernetes using an OIDC provider and JSON Web Tokens. You’ll also learn how to secure Istio services using JWTs, along with how to use token exchanges to gain access to different services, securely moving from one service to another. Finally, we use OPA to create a custom authorization rule we configure with Istio.
Chapter 18, Provisioning a Multitenant Platform, explores how to build pipelines, how to automate their creation, and how they relate to GitOps. We’ll explore how the objects that are used to drive pipelines are related to each other, how to build relationships between systems, and finally, design a self-service workflow for automating the Deployment of pipelines.
Chapter 19, Building a Developer Portal, builds off of our designs in Chapter 18 to build out a multitenant platform with many of the tools we used throughout this book. We’ll start with talking about building a lab to run our multitenant cluster in. Next we’ll roll out Kubernetes to three clusters and integrate them with GitLab, Vault, Argo CD, Harbor, and OpenUnison. Finally we’ll walk through onboarding a new vCluster based tenant using OpenUnison’s self-service portal.
To get the most out of this book
Section titled “To get the most out of this book”- You should have a basic understanding of Linux, basic commands, tools like Git, and a text editor like Vi.
- The book chapters contain both theory and hands-on exercises. We feel that the exercises help to reinforce the theory, but they are not required to understand each topic. If you want to do the exercises in the book, you will need to meet the requirement in the table below:
| Requirement for the chapter exercises | Version |
|---|---|
| Ubuntu Server | 22.04 or higher |
All exercises use Ubuntu, but most of them will work on other Linux installations.
Download the example code files
Section titled “Download the example code files”The code bundle for the book is hosted on GitHub at https://github.com/PacktPublishing/Kubernetes-An-Enterprise-Guide-Third-Edition.
Supplementary content
Section titled “Supplementary content”Here’s a link to the YouTube channel (created and managed by the authors Marc Boorshtein and Scott Surovich) that contains videos of the labs from this book, so you can see them in action before you start on your own:
Conventions used
Section titled “Conventions used”There are a number of text conventions used throughout this book.
CodeInText: Indicates code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles. For example: “The --name option will set the name of the cluster to cluster01, and --config tells the installer to use the cluster01-kind.yaml config file.”
A block of code is set as follows:
apiVersion: apps/v1kind: Deploymentmetadata: labels: app: grafana name: grafana namespace: monitoringWhen we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:
apiVersion: apps/v1kind: Deploymentmetadata: labels: app: grafana name: grafana namespace: monitoringAny command-line input or output is written as follows:
PS C:\Users\mlb> kubectl create ns not-going-to-worknamespace/not-going-to-work createdBold: Indicates a new term, an important word, or words that you see on the screen, for example, in menus or dialog boxes, also appear in the text like this. For example: “Hit the Finish Login button at the bottom of the screen.”
Warnings or important notes appear like this.
Tips and tricks appear like this.
Source: