Kubernetes Cookbook, 2nd Edition

Book description

Kubernetes is the de facto standard for container orchestration and distributed applications management across a microservices framework. With this practical cookbook, you'll learn hands-on Kubernetes recipes for automating the deployment, scaling, and operations of application containers across clusters of hosts.

In this fully updated second edition, Sameer Naik, Sébastien Goasguen, and Jonathan Michaux from TriggerMesh provide a problem-solution-discussion format with easy lookups to help you find the detailed answers you need—fast. Kubernetes lets you deploy your applications quickly and predictably, so you can efficiently respond to customer demand. This cookbook delivers the essential knowledge that developers and system administrators need to get there.

Recipes in this cookbook focus on:

  • Creating a Kubernetes cluster
  • Using the Kubernetes command-line interface
  • Managing fundamental workload types
  • Working with services
  • Exploring the Kubernetes API
  • Managing stateful and non-cloud-native apps
  • Working with volumes and configuration data
  • Cluster-level and application-level scaling
  • Securing your applications
  • Monitoring and logging
  • Maintenance and troubleshooting

Publisher resources

View/Submit Errata

Table of contents

  1. Preface
    1. Who Should Read This Book
    2. Why We Wrote This Book
    3. Navigating This Book
    4. A Note on Kubernetes Releases
    5. Technology You Need to Understand
    6. Conventions Used in This Book
    7. Using Code Examples
    8. O’Reilly Online Learning
    9. How to Contact Us
    10. Acknowledgments
  2. 1. Getting Started with Kubernetes
    1. 1.1. Installing the Kubernetes CLI, kubectl
    2. 1.2. Installing Minikube to Run a Local Kubernetes Instance
    3. 1.3. Using Minikube Locally for Development
    4. 1.4. Starting Your First Application on Minikube
    5. 1.5. Using kind to Run Kubernetes Locally
    6. 1.6. Using Kubernetes in Docker Desktop
    7. 1.7. Switching kubectl Contexts
    8. 1.8. Switching Contexts and Namespaces Using kubectx and kubens
  3. 2. Creating a Kubernetes Cluster
    1. 2.1. Preparing a New Node for a Kubernetes Cluster
    2. 2.2. Bootstrapping a Kubernetes Control-Plane Node
    3. 2.3. Installing a Container Network Add-on for Cluster Networking
    4. 2.4. Adding Worker Nodes to a Kubernetes Cluster
    5. 2.5. Deploying the Kubernetes Dashboard
    6. 2.6. Accessing the Kubernetes Dashboard
    7. 2.7. Deploying the Kubernetes Metrics Server
    8. 2.8. Downloading a Kubernetes Release from GitHub
    9. 2.9. Downloading Client and Server Binaries
    10. 2.10. Using systemd Unit Files for Running Kubernetes Components
    11. 2.11. Creating a Kubernetes Cluster on Google Kubernetes Engine
    12. 2.12. Creating a Kubernetes Cluster on Azure Kubernetes Service
    13. 2.13. Creating a Kubernetes Cluster on Amazon Elastic Kubernetes Service
  4. 3. Learning to Use the Kubernetes Client
    1. 3.1. Listing Resources
    2. 3.2. Deleting Resources
    3. 3.3. Watching Resource Changes with kubectl
    4. 3.4. Editing Objects with kubectl
    5. 3.5. Asking kubectl to Explain Resources and Fields
  5. 4. Creating and Modifying Fundamental Workloads
    1. 4.1. Creating a Pod Using kubectl run
    2. 4.2. Creating a Deployment Using kubectl create
    3. 4.3. Creating Objects from File Manifests
    4. 4.4. Writing a Pod Manifest from Scratch
    5. 4.5. Launching a Deployment Using a Manifest
    6. 4.6. Updating a Deployment
    7. 4.7. Running a Batch Job
    8. 4.8. Running a Task on a Schedule Within a Pod
    9. 4.9. Running Infrastructure Daemons per Node
  6. 5. Working with Services
    1. 5.1. Creating a Service to Expose Your Application
    2. 5.2. Verifying the DNS Entry of a Service
    3. 5.3. Changing the Type of a Service
    4. 5.4. Deploying an Ingress Controller
    5. 5.5. Making Services Accessible from Outside the Cluster
  7. 6. Managing Application Manifests
    1. 6.1. Installing Helm, the Kubernetes Package Manager
    2. 6.2. Adding Chart Repositories to Helm
    3. 6.3. Using Helm to Install Applications
    4. 6.4. Inspecting the Customizable Parameters of a Chart
    5. 6.5. Overriding Chart Parameters
    6. 6.6. Getting the User-Supplied Parameters of a Helm Release
    7. 6.7. Uninstalling Applications with Helm
    8. 6.8. Creating Your Own Chart to Package Your Application with Helm
    9. 6.9. Installing Kompose
    10. 6.10. Converting Your Docker Compose Files to Kubernetes Manifests
    11. 6.11. Converting Your Docker Compose File to a Helm Chart
    12. 6.12. Installing kapp
    13. 6.13. Deploying YAML Manifests Using kapp
  8. 7. Exploring the Kubernetes API and Key Metadata
    1. 7.1. Discovering the Kubernetes API Server’s Endpoints
    2. 7.2. Understanding the Structure of a Kubernetes Manifest
    3. 7.3. Creating Namespaces to Avoid Name Collisions
    4. 7.4. Setting Quotas Within a Namespace
    5. 7.5. Labeling an Object
    6. 7.6. Using Labels for Queries
    7. 7.7. Annotating a Resource with One Command
  9. 8. Volumes and Configuration Data
    1. 8.1. Exchanging Data Between Containers via a Local Volume
    2. 8.2. Passing an API Access Key to a Pod Using a Secret
    3. 8.3. Providing Configuration Data to an Application
    4. 8.4. Using a Persistent Volume with Minikube
    5. 8.5. Understanding Data Persistency on Minikube
    6. 8.6. Storing Encrypted Secrets in Version Control
  10. 9. Scaling
    1. 9.1. Scaling a Deployment
    2. 9.2. Using Horizontal Pod Autoscaling
    3. 9.3. Automatically Resizing a Cluster in GKE
    4. 9.4. Automatically Resizing an Amazon EKS Cluster
  11. 10. Security
    1. 10.1. Providing a Unique Identity for an Application
    2. 10.2. Listing and Viewing Access Control Information
    3. 10.3. Controlling Access to Resources
    4. 10.4. Securing Pods
  12. 11. Monitoring and Logging
    1. 11.1. Accessing the Logs of a Container
    2. 11.2. Recovering from a Broken State with a Liveness Probe
    3. 11.3. Controlling Traffic Flow to a Pod Using a Readiness Probe
    4. 11.4. Protecting Slow-Starting Containers Using a Start-up Probe
    5. 11.5. Adding Liveness and Readiness Probes to Your Deployments
    6. 11.6. Accessing Kubernetes Metrics in the CLI
    7. 11.7. Using Prometheus and Grafana on Minikube
  13. 12. Maintenance and Troubleshooting
    1. 12.1. Enabling Autocomplete for kubectl
    2. 12.2. Removing a Pod from a Service
    3. 12.3. Accessing a ClusterIP Service Outside the Cluster
    4. 12.4. Understanding and Parsing Resource Statuses
    5. 12.5. Debugging Pods
    6. 12.6. Influencing a Pod’s Start-up Behavior
    7. 12.7. Getting a Detailed Snapshot of the Cluster State
    8. 12.8. Adding Kubernetes Worker Nodes
    9. 12.9. Draining Kubernetes Nodes for Maintenance
  14. 13. Service Meshes
    1. 13.1. Installing the Istio Service Mesh
    2. 13.2. Deploying a Microservice with an Istio Sidecar
    3. 13.3. Routing Traffic Using an Istio Virtual Service
    4. 13.4. Rewriting a URL Using an Istio Virtual Service
    5. 13.5. Installing the Linkerd Service Mesh
    6. 13.6. Deploying a Service into the Linkerd Mesh
    7. 13.7. Routing Traffic to a Service in Linkerd
    8. 13.8. Authorizing Traffic to the Server in Linkerd
  15. 14. Serverless and Event-Driven Applications
    1. 14.1. Installing the Knative Operator
    2. 14.2. Installing the Knative Serving Component
    3. 14.3. Installing the Knative CLI
    4. 14.4. Creating a Knative Service
    5. 14.5. Installing the Knative Eventing Component
    6. 14.6. Deploying a Knative Eventing Source
    7. 14.7. Enabling Knative Eventing Sources
    8. 14.8. Installing Event Sources from TriggerMesh
  16. 15. Extending Kubernetes
    1. 15.1. Compiling from Source
    2. 15.2. Compiling a Specific Component
    3. 15.3. Using a Python Client to Interact with the Kubernetes API
    4. 15.4. Extending the API Using Custom Resource Definitions
  17. Appendix. Resources
    1. General
    2. Tutorials and Examples
  18. Index
  19. About the Authors

Product information

  • Title: Kubernetes Cookbook, 2nd Edition
  • Author(s): Sameer Naik, Sébastien Goasguen, Jonathan Michaux
  • Release date: November 2023
  • Publisher(s): O'Reilly Media, Inc.
  • ISBN: 9781098142247