Inhaltsverzeichnis

Alle Kapitel aufklappen
Alle Kapitel zuklappen
Preface
13
Structure
15
What You Should Already Know Now
16
What You Will Learn
17
Important to Know
17
Book Resources
19
1 Introduction to Kubernetes
21
1.1 Basic Principles and Concepts: Why Use Container Clusters at All?
21
1.1.1 Why Use Containers at All?
23
1.1.2 Why You Need a Container Management Tool
27
1.1.3 Of Pets and Cattle
28
1.1.4 Stateless and Stateful Applications
29
1.1.5 Separation of Concerns
31
1.2 Kubernetes, the Tool of Choice
34
1.2.1 Why Do Companies Want to Use Kubernetes?
34
1.2.2 The Promise of Kubernetes
37
1.2.3 Major Features
41
1.2.4 For Which Companies Is Kubernetes Useful?
42
1.2.5 Which Companies Should Not Use Kubernetes?
44
1.3 Architecture and Components
45
1.3.1 Master Nodes
46
1.3.2 Worker Nodes
49
1.3.3 API Call Flow
51
1.4 A Kubernetes Cluster on Your Computer
53
1.4.1 Minikube on macOS
54
1.4.2 Minikube on Linux
55
1.4.3 Minikube on Windows
57
1.4.4 Launching Minikube
58
1.4.5 Controlling Minikube
58
1.4.6 Possible Errors when Starting Minikube
59
1.4.7 Container Registry of Minikube
59
1.5 Interaction with Kubernetes via the Command Line and Dashboard
61
1.5.1 Minikube Comes With kubectl
61
1.5.2 Installing kubectl
61
1.5.3 Accessing the Cluster Using Kubeconfig
65
1.5.4 Namespaces
67
1.5.5 kubectl Commands
68
1.5.6 Switching Clusters and Namespaces Easily
77
1.5.7 The Kubernetes Dashboard
78
1.6 Lens: The IDE for Kubernetes
81
1.6.1 Overview of Lens
82
1.6.2 Advantages over the Kubernetes Dashboard
83
1.6.3 The Lens Reference
86
1.7 The Kubernetes Cluster from Raspberry Pis
89
1.7.1 Choosing the Right Raspberry Pis
90
1.7.2 Installation of Kubernetes
92
1.7.3 Using the Kubeconfig File of the Pi Cluster
93
2 Basic Objects and Concepts in Kubernetes
95
2.1 Pod and Container Management
98
2.1.1 Container Engines
101
2.1.2 Your First Own Pod
104
2.1.3 Multiple Containers within a Pod
106
2.1.4 Communication between Containers
109
2.1.5 Init Container
110
2.1.6 Pod Phases and Container Statuses
113
2.1.7 The Restart Policy of Pods
114
2.1.8 When the Pod Comes to an End
115
2.2 Annotations and Labels
118
2.2.1 Using Labels and Selectors
119
2.2.2 Field Selectors
121
2.2.3 NodeSelector
122
2.2.4 Node Affinity and Antiaffinity
124
2.2.5 Pod Affinity and Antiaffinity
128
2.2.6 Taints and Tolerations
133
2.2.7 Annotations
136
2.3 Deployments and ReplicaSets
138
2.3.1 The Role of ReplicaSets
139
2.3.2 Creating Deployments
142
2.3.3 Rolling Updates via the Deployment Object
144
2.3.4 Rollback via Deployment
150
2.4 ConfigMaps and Secrets
152
2.4.1 What Are ConfigMaps?
154
2.4.2 What Are Secrets?
162
2.5 Establishing a Communication with Services and an Ingress
171
2.5.1 Communication between Pods
173
2.5.2 Communication via a Service
174
2.5.3 Communication via Ingress
180
3 Everything as Code: Tools and Principles for Kubernetes Operations
187
3.1 Declarative Configurations
188
3.2 YAML: The Language for Kubernetes
192
3.2.1 Basics of YAML Syntax
192
3.2.2 Data Types in YAML
194
3.2.3 Anchors and Aliases
196
3.2.4 Single-Line YAML Notation in Documentation
197
3.2.5 Weaknesses of YAML
197
3.2.6 Tips for Practical Use
199
3.3 Version Management of Kubernetes Manifests
200
3.3.1 Using Git
201
3.3.2 Managing Numerous Kubernetes Manifests
203
3.3.3 Branching Strategies
207
3.3.4 Division of the Repositories
211
3.4 Continuous Integration and Continuous Delivery
213
3.4.1 Pipeline Steps for Kubernetes
213
3.4.2 Pipeline Architectures
218
3.4.3 GitOps
223
3.5 Templating Using Kustomize
225
3.5.1 Basic Principles of Kustomize
226
3.5.2 Resource Generator
231
3.5.3 More Kustomize Built-Ins
233
3.5.4 Conclusion on Kustomize
234
4 Advanced Objects and Concepts in Kubernetes
235
4.1 DaemonSets
236
4.2 Jobs in Kubernetes
239
4.2.1 Real-Life Kubernetes Jobs
240
4.2.2 Queue Worker with RabbitMQ
242
4.2.3 Kubernetes CronJobs
246
4.3 Custom Resources and Custom Resource Definitions
248
4.3.1 Example: A Monitoring CR
249
4.3.2 Validation in CRD
252
4.3.3 Operators
255
4.4 Downward API
258
4.5 Pod Priority and Preemption
261
4.6 Versioning Objects in Kubernetes
263
5 Stateful Applications and Storage
265
5.1 Stateful Applications in Kubernetes through StatefulSets
266
5.1.1 Pod Management Policy
269
5.1.2 Strategies for Updates
270
5.1.3 Retention Policy for Persistent Volume Claims
272
5.2 Persistent Volumes and Persistent Volume Claims
273
5.2.1 Storage Types for PVs
278
5.2.2 CSI Drivers for External Storage Media
281
5.2.3 Storage Classes and Dynamic PVs
283
5.2.4 PostgreSQL as StatefulSet with Persistent Volume
286
5.3 Ephemeral Volumes
289
5.4 Other Features of Volumes
291
5.4.1 Volume Snapshots
292
5.4.2 Projected Volumes
295
6 Kubernetes Governance and Security: Prepare for Production
299
6.1 Pod Security
301
6.2 Pod Security Admission
304
6.3 Admission Controller
306
6.4 Kubernetes Policies
308
6.5 Policy Objects
311
6.6 Role-Based Access Control in Kubernetes
313
6.6.1 Subjects: Users, Groups, and Service Accounts
315
6.6.2 Roles and Role Bindings
317
6.6.3 Conclusion
319
7 Developing Applications for Kubernetes: Ready for Production
321
7.1 Managing Pod Resources
322
7.2 Readiness, Liveness, and Startup Probes
325
7.2.1 How to Define Probes
328
7.2.2 Testing Probes Using an Example
330
7.3 Scaling and Load Balancing
335
7.3.1 Horizontal Pod Autoscaling
335
7.3.2 Vertical Pod Autoscaling
339
7.3.3 Cluster Autoscaler
341
7.4 Monitoring
342
7.4.1 Introduction: Prometheus, Grafana, and Alertmanager
343
7.4.2 Monitoring on the Pi Cluster
345
8 Orchestrating Kubernetes Using Helm
357
8.1 Helm: The Kubernetes Package Manager
358
8.1.1 Creating a First Helm Chart
361
8.1.2 Deploying a Helm Chart via the Command Line Interface
361
8.1.3 Setting Up and Managing a Helm Repository
363
8.1.4 Deploying a Helm Chart via Lens
365
8.1.5 Updating and Deleting Helm Releases
366
8.1.6 Downloading Helm Charts from a Repository
368
8.2 Reading and Developing Helm Charts
368
8.2.1 The Templating Engine and the Language of the Charts
369
8.2.2 Configuring Charts with Values
374
8.2.3 Conditions in Helm Templates
378
8.2.4 Other Operations and Control Structures
380
8.2.5 Helm Diff for Checking Changes
383
8.3 Developing Custom Charts
385
8.3.1 The Framework of Your Helm Chart
386
8.3.2 Packaging Charts and Storing Them in the Repository
387
8.3.3 Managing Dependencies in Helm Charts
390
8.4 Conclusion
394
The Author
395
Index
397