A clear and practical beginner’s guide that shows you just how easy it can be to make the switch to Kubernetes! Kubernetes for Developers reveals practical and painless methods for deploying your apps on Kubernetes—even for small-to-medium sized applications! You’ll learn how to migrate your existing apps onto Kubernetes without a rebuild, and implement modern cloud native architectures that can handle your future growth. Inside, you’ll learn how to: Containerize a web application with Docker Host a containerized app on Kubernetes with a public cloud service Save money and improve performance with cloud native technologies Make your deployments reliable and fault tolerant Prepare your deployments to scale without a redesign Monitor, debug and tune application deployments on Kubernetes Designed for busy working developers, this hands-on guide helps your first steps into Kubernetes using the powerful Google Kubernetes Engine (GKE) service. Learn how the GKE’s powerful automation tools can perform automatic checks and scaling, giving you more time to spend developing great applications. You’ll soon see that you don’t need to incur huge costs or have the manpower of an enterprise organization to get a productivity boost from Kubernetes! Purchase of the print book includes a free eBook in PDF, Kindle, and ePub formats from Manning Publications. About the technology Modern software needs to perform at scale while effectively handling load balancing, state and security. Kubernetes makes these tasks easier and more reliable for apps of any size. This book, written especially for software developers creating applications that run on Kubernetes, shows you exactly how to address these and other important issues. About the book Kubernetes for Developers covers everything you need to know to containerize and deploy an app on Kubernetes from the developer’s perspective. You’ll start by creating a small application you can run on a cloud-based Kubernetes cluster. Then, you’ll systematically explore best practices for stable long-term deployment, including scaling, capacity planning, and resource optimization. What's inside Deploying reliable web applications using automated operations Scaling up without an application redesign Monitoring, debugging, and tuning workloads About the reader For developers familiar with building or deploying web applications. No Docker or Kubernetes experience required. About the author William Denniss is a product manager at Google working on Google Kubernetes Engine. Table of Contents PART 1 Getting started with Kubernetes 1 Kubernetes for application deployment 2 Containerizing apps 3 Deploying to Kubernetes 4 Automated operations 5 Resource management PART 2 Going to production 6 Scaling up 7 Internal services and load balancing 8 Node feature selection 9 Stateful applications 10 Background processing 11 GitOps: Configuration as code 12 Securing Kubernetes Kubernetes for Developers brief contents contents preface acknowledgments about this book Who should read the book How this book is organized About the code liveBook discussion forum Additional online resources about the author about the cover illustration Part 1—Getting started with Kubernetes 1 Kubernetes for application deployment 1.1 Why containers? 1.1.1 Container benefits 1.2 Why Kubernetes? 1.2.1 Composable building blocks 1.2.2 Features and benefits 1.2.3 Kubernetes vs. platforms as a service 1.2.4 When (not) to use Kubernetes Summary 2 Containerizing apps 2.1 Building Docker containers 2.1.1 Developer setup 2.1.2 Running commands in Docker 2.1.3 Building our own images 2.1.4 Using base images 2.1.5 Adding a default command 2.1.6 Adding dependencies 2.1.7 Compiling code in Docker 2.1.8 Compiling code with a multistage build 2.2 Containerizing a server application 2.2.1 Containerizing an application server 2.2.2 Debugging 2.3 Using Docker Compose for local testing 2.3.1 Mapping folders locally 2.3.2 Adding service dependencies 2.3.3 Faking external dependencies Summary 3 Deploying to Kubernetes 3.1 Kubernetes architecture 3.1.1 The Kubernetes cluster 3.1.2 Kubernetes objects 3.2 Deploying an application 3.2.1 Creating a cluster 3.2.2 Uploading your container 3.2.3 Deploying to Kubernetes 3.2.4 The PodSpec 3.2.5 Publishing your Service 3.2.6 Interacting with the Deployment 3.2.7 Updating your application 3.2.8 Cleaning up 3.3 Imperative commands 3.4 Local Kubernetes environments 3.4.1 Docker Desktop’s Kubernetes cluster 3.4.2 Minikube 3.4.3 Using your local Kubernetes cluster Summary 4 Automated operations 4.1 Automated uptime with health checks 4.1.1 Liveness and readiness probes 4.1.2 Adding a readiness probe 4.1.3 Adding a liveness probe 4.1.4 Designing good health checks 4.1.5 Rescheduling unready containers 4.1.6 Probe types 4.2 Updating live applications 4.2.1 Rolling update strategy 4.2.2 Re-create strategy 4.2.3 Blue/green strategy 4.2.4 Choosing a rollout strategy Summary 5 Resource management 5.1 Pod scheduling 5.1.1 Specifying Pod resources 5.1.2 Quality of service 5.1.3 Evictions, priority, and preemption 5.2 Calculating Pod resources 5.2.1 Setting memory requests and limits 5.2.2 Setting CPU requests and limits 5.2.3 Reducing costs by overcommitting CPU 5.2.4 Balancing Pod replicas and internal Pod concurrency Summary Part 2—Going to production 6 Scaling up 6.1 Scaling Pods and nodes 6.2 Horizontal Pod autoscaling 6.2.1 External metrics 6.3 Node autoscaling and capacity planning 6.3.1 Cluster autoscaling 6.3.2 Spare capacity with cluster autoscaling 6.4 Building your app to scale 6.4.1 Avoiding state 6.4.2 Microservice architectures 6.4.3 Background tasks Summary 7 Internal services and load balancing 7.1 Internal services 7.1.1 Kubernetes cluster networking 7.1.2 Creating an internal service 7.1.3 Service discovery 7.2 Ingress: HTTP(S) load balancing 7.2.1 Securing connections with TLS Summary 8 Node feature selection 8.1 Node feature selection 8.1.1 Node selectors 8.1.2 Node affinity and anti-affinity 8.1.3 Tainting nodes to prevent scheduling by default 8.1.4 Workload separation 8.2 Placing Pods 8.2.1 Building highly available deployments 8.2.2 Co-locating interdependent Pods 8.2.3 Avoiding certain Pods 8.3 Debugging placement problems 8.3.1 Placement rules don’t appear to work 8.3.2 Pods are pending Summary 9 Stateful applications 9.1 Volumes, persistent volumes, claims, and storage classes 9.1.1 Volumes 9.1.2 Persistent volumes and claims 9.1.3 Storage classes 9.1.4 Single-Pod stateful workload deployments 9.2 StatefulSet 9.2.1 Deploying StatefulSet 9.2.2 Deploying a multirole StatefulSet 9.3 Migrating/recovering disks 9.4 Generic ephemeral volume for scratch space Summary 10 Background processing 10.1 Background processing queues 10.1.1 Creating a custom task queue 10.1.2 Signal handling in worker Pods 10.1.3 Scaling worker Pods 10.1.4 Open source task queues 10.2 Jobs 10.2.1 Running one-off tasks with Jobs 10.2.2 Scheduling tasks with CronJobs 10.3 Batch task processing with Jobs 10.3.1 Dynamic queue processing with Jobs 10.3.2 Static queue processing with Jobs 10.4 Liveness probes for background tasks Summary 11 GitOps: Configuration as code 11.1 Production and staging environments using namespaces 11.1.1 Deploying to our new namespace 11.1.2 Syncing mutations from the cluster 11.2 Configuration as code the Kubernetes way 11.3 Rolling out safely 11.3.1 Deployment pipelines 11.3.2 Continuous deployment with Cloud Build 11.4 Secrets 11.4.1 String-based (password) secrets 11.4.2 Base64 encoded secrets 11.4.3 File-based secrets 11.4.4 Secrets and GitOps Summary 12 Securing Kubernetes 12.1 Staying up to date 12.1.1 Cluster and node updates 12.1.2 Updating containers 12.1.3 Handling disruptions 12.2 Deploying node agents with DaemonSet 12.3 Pod security context 12.4 Non-root containers 12.5 Admission controllers 12.5.1 Pod Security admission 12.5.2 Balancing security with compatibility 12.6 Role-based access control 12.7 Next steps 12.7.1 Network policies 12.7.2 Container isolation 12.7.3 Cluster hardening Summary index Numerics A B C D E F G H I J K L M N O P Q R S T U V W Kubernetes for Developers is a hands-on guide to taking your first steps into Kubernetes using the powerful Google Kubernetes Engine service. Kubernetes has changed everything about deploying applications to the cloudfor the better! Kubernetes for Developers is a clear and practical beginners guide that shows you just how easy, flexible, and cost-effective it can be to make the switch to Kubernetes deployment even for small to medium-sized applications. Youll learn how to migrate your existing apps onto Kubernetes without a rebuild, and implement modern cloud native architectures that can handle your future growth. Youll take advantage of the powerful automation tools in Google Kubernetes Engine to perform automatic checks and scaling, giving you more time to spend developing great applications! Purchase of the print book includes a free eBook in PDF, Kindle, and ePub formats from Manning Publications. About the technology You dont need to incur huge costs or have the manpower of an enterprise organization to get a productivity boost from Kubernetes. By organizing your application component into containerized components and automating tasks like scaling and replication, Kubernetes keeps your apps running smoothly. Cloud-based Kubernetes services like Google Kubernetes Engine (GKE) reduce OS issues, simplify operations, and give you the freedom to use whatever software stack you want. If youve heard that switching to Kubernetes is complex, good news Kubernetes for Developers will show you how it can be done without a time-consuming rebuild. Using examples from the Google Kubernetes Engine created by the team who invented Kubernetes itself, youll learn to set up future-proof application deployments that scale to handle evergrowing and complex workloads. About the book Kubernetes for Developers is a hands-on guide to taking your first steps into Kubernetes using the powerful Google Kubernetes Engine service. It lays out a map for taking an application, containerizing it, and then deploying it onto Kubernetes. Youll learn best practice techniques for a stable and long-term Kubernetes deployment, including scaling and capacity planning, saving money by optimizing resource consumption, and tricks to make your day-to-day monitoring easier such as debugging code in the cloud. Kubernetes is the future of app development, so make sure youre ahead of the curve get started with Kubernetes today! What's inside About the reader For programmers with experience managing web apps. No knowledge of Kubernetes or Docker containerization required. Examples use GKE, with careful explanations to allow you to adapt them to any Kuberentes system. About the author William Denniss is a product manager at Google on Kubernetes Engine. He participates in the CNCF Kubernetes Conformance working group and has a passion for interoperability and developer experience. He has presented on Kubernetes at KubeCon North America and Europe, DockerCon, and Google Cloud Next in San Francisco, London, and Tokyo. William authored RFC 8252, RFC 8417, and RFC 8628, and founded AppAuth, a leading open source OAuth client.