The way developers design, build, and run software has changed significantly with the evolution of microservices and containers. These modern architectures offer new distributed primitives that require a different set of practices than many developers, tech leads, and architects are accustomed to. With this focused guide, Bilgin Ibryam and Roland Huss provide common reusable patterns and principles for designing and implementing cloud native applications on Kubernetes. Each pattern includes a description of the problem and a Kubernetes-specific solution. All patterns are backed by and demonstrated with concrete code examples. This updated edition is ideal for developers and architects familiar with basic Kubernetes concepts who want to learn how to solve common cloud native challenges with proven design patterns. You'll explore: • Foundational patterns covering core principles and practices for building and running container-based cloud native applications • Behavioral patterns that delve into finer-grained concepts for managing various types of container and platform interactions • Structural patterns for organizing containers within a Pod for addressing specific use cases • Configuration patterns that provide insight into how application configurations can be handled in Kubernetes • Security patterns for hardening the access to cloud native applications running on Kubernetes Advanced patterns covering more complex topics such as operators and autoscaling Cover 1 Copyright 4 Table of Contents 5 Foreword 13 Preface 15 Kubernetes 15 Design Patterns 16 How This Book Is Structured 17 Who This Book Is For 18 What You Will Learn 19 What’s New in the Second Edition 19 Conventions Used in This Book 20 Using Code Examples 21 O’Reilly Online Learning 22 How to Contact Us 22 Acknowledgments 23 Chapter 1. Introduction 25 The Path to Cloud Native 25 Distributed Primitives 27 Containers 29 Pods 30 Services 31 Labels 32 Namespaces 34 Discussion 35 More Information 36 Part I. Foundational Patterns 37 Chapter 2. Predictable Demands 39 Problem 39 Solution 39 Runtime Dependencies 40 Resource Profiles 42 Pod Priority 45 Project Resources 47 Capacity Planning 49 Discussion 50 More Information 50 Chapter 3. Declarative Deployment 53 Problem 53 Solution 53 Rolling Deployment 55 Fixed Deployment 58 Blue-Green Release 58 Canary Release 59 Discussion 60 More Information 62 Chapter 4. Health Probe 65 Problem 65 Solution 65 Process Health Checks 66 Liveness Probes 66 Readiness Probes 68 Startup Probes 70 Discussion 72 More Information 73 Chapter 5. Managed Lifecycle 75 Problem 75 Solution 75 SIGTERM Signal 76 SIGKILL Signal 76 PostStart Hook 77 PreStop Hook 78 Other Lifecycle Controls 79 Discussion 82 More Information 83 Chapter 6. Automated Placement 85 Problem 85 Solution 85 Available Node Resources 86 Container Resource Demands 87 Scheduler Configurations 87 Scheduling Process 88 Node Affinity 90 Pod Affinity and Anti-Affinity 91 Topology Spread Constraints 92 Taints and Tolerations 94 Discussion 96 More Information 99 Part II. Behavioral Patterns 101 Chapter 7. Batch Job 103 Problem 103 Solution 104 Discussion 109 More Information 110 Chapter 8. Periodic Job 111 Problem 111 Solution 112 Discussion 113 More Information 114 Chapter 9. Daemon Service 115 Problem 115 Solution 116 Discussion 119 More Information 119 Chapter 10. Singleton Service 121 Problem 121 Solution 122 Out-of-Application Locking 122 In-Application Locking 124 Pod Disruption Budget 127 Discussion 128 More Information 129 Chapter 11. Stateless Service 131 Problem 131 Solution 132 Instances 132 Networking 134 Storage 135 Discussion 137 More Information 138 Chapter 12. Stateful Service 139 Problem 139 Storage 140 Networking 140 Identity 141 Ordinality 141 Other Requirements 141 Solution 142 Storage 143 Networking 144 Identity 145 Ordinality 146 Other Features 146 Discussion 148 More Information 149 Chapter 13. Service Discovery 151 Problem 151 Solution 152 Internal Service Discovery 153 Manual Service Discovery 157 Service Discovery from Outside the Cluster 159 Application Layer Service Discovery 163 Discussion 166 More Information 167 Chapter 14. Self Awareness 169 Problem 169 Solution 170 Discussion 173 More Information 173 Part III. Structural Patterns 175 Chapter 15. Init Container 177 Problem 177 Solution 178 Discussion 182 More Information 183 Chapter 16. Sidecar 185 Problem 185 Solution 186 Discussion 188 More Information 189 Chapter 17. Adapter 191 Problem 191 Solution 191 Discussion 194 More Information 194 Chapter 18. Ambassador 195 Problem 195 Solution 195 Discussion 197 More Information 198 Part IV. Configuration Patterns 199 Chapter 19. EnvVar Configuration 201 Problem 201 Solution 201 Discussion 206 More Information 207 Chapter 20. Configuration Resource 209 Problem 209 Solution 209 Discussion 215 More Information 215 Chapter 21. Immutable Configuration 217 Problem 217 Solution 218 Docker Volumes 218 Kubernetes Init Containers 220 OpenShift Templates 222 Discussion 223 More Information 224 Chapter 22. Configuration Template 225 Problem 225 Solution 225 Discussion 230 More Information 231 Part V. Security Patterns 233 Chapter 23. Process Containment 235 Problem 235 Solution 236 Running Containers with a Non-Root User 236 Restricting Container Capabilities 237 Avoiding a Mutable Container Filesystem 239 Enforcing Security Policies 240 Discussion 242 More Information 243 Chapter 24. Network Segmentation 245 Problem 245 Solution 246 Network Policies 247 Authorization Policies 255 Discussion 258 More Information 259 Chapter 25. Secure Configuration 261 Problem 261 Solution 262 Out-of-Cluster Encryption 263 Centralized Secret Management 271 Discussion 275 More Information 276 Chapter 26. Access Control 277 Problem 277 Solution 278 Authentication 279 Authorization 280 Admission Controllers 280 Subject 281 Role-Based Access Control 287 Discussion 298 More Information 299 Part VI. Advanced Patterns 301 Chapter 27. Controller 303 Problem 303 Solution 304 Discussion 314 More Information 315 Chapter 28. Operator 317 Problem 317 Solution 318 Custom Resource Definitions 318 Controller and Operator Classification 321 Operator Development and Deployment 324 Example 326 Discussion 330 More Information 331 Chapter 29. Elastic Scale 333 Problem 333 Solution 334 Manual Horizontal Scaling 334 Horizontal Pod Autoscaling 335 Vertical Pod Autoscaling 349 Cluster Autoscaling 352 Scaling Levels 355 Discussion 357 More Information 357 Chapter 30. Image Builder 359 Problem 359 Solution 360 Container Image Builder 361 Build Orchestrators 365 Build Pod 366 OpenShift Build 370 Discussion 377 More Information 377 Afterword 379 What We Covered 380 Final Words 381 Index 383 About the Authors 392 Colophon 392 The way developers design, build, and run software has changed significantly with the evolution of microservices and containers. These modern architectures use new primitives that require a different set of practices than most developers, tech leads, and architects are accustomed to. With this focused guide, Bilgin Ibryam and Roland Hu from Red Hat provide common reusable elements, patterns, principles, and practices for designing and implementing cloud-native applications on Kubernetes. Each pattern includes a description of the problem and a proposed solution with Kubernetes specifics. Many patterns are also backed by concrete code examples. This book is ideal for developers already familiar with basic Kubernetes concepts who want to learn common cloud-native patterns. You'll learn about the following pattern categories: Foundational patterns cover the core principles and practices for building container-based cloud-native applications. Behavioral patterns explore finer-grained concepts for managing various types of container and platform interactions. Structural patterns help you organize containers within a pod, the atom of the Kubernetes platform. Configuration patterns provide insight into how application configurations can be handled in Kubernetes. Advanced patterns cover more advanced topics such as extending the platform with operators. The way developers design, build, and run software has changed significantly with the evolution of microservices and containers. These modern architectures use new primitives that require a different set of practices than most developers, tech leads, and architects are accustomed to. With this focused guide, Bilgin Ibryam and Roland Huß from Red Hat provide common reusable elements, patterns, principles, and practices for designing and implementing cloud-native applications on Kubernetes. Each pattern includes a description of the problem and a proposed solution with Kubernetes specifics. Many patterns are also backed by concrete code examples. This book is ideal for developers already familiar with basic Kubernetes concepts who want to learn common cloud-native patterns. You'll learn about the following pattern categories: Foundational patterns cover the core principles and practices for building container-based cloud-native applications. Behavioral patterns explore finer-grained concepts for managing various types of container and platform interactions. Structural patterns help you organize containers within a pod, the atom of the Kubernetes platform. Configuration patterns provide insight into how application configurations can be handled in Kubernetes. Advanced patterns covers more advanced topics such as extending the platform with operators "The way developers design, build, and run software has changed significantly with the evolution of microservices and containers. These modern architectures offer new distributed primitives that require a differnet set of practices than many developers, tech leads, and architects are accustomed to. This focused guide provides common, reusable patterns and principles for designing and implementing cloud-native applications on Kubernetes. Each pattern includes a description of the problem and a Kubernetes-specific solution. All patterns are backed by and demonstrated with concrete code examples. This book is ideal for developers and architects already familiar with basic Kubernetes concepts who want to learn how to solve common cloud native challenges with proven design patterns."--Provided by publisher