Kubernetes Cookbook

Book description

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

The book's easy-lookup problem-solution-discussion format helps you find the detailed answers you need—quickly. Kubernetes lets you deploy your applications quickly and predictably, so you can efficiently respond to customer demand. This cookbook, ideal for developers and system administers alike, provides the essential knowledge you need to get there.

You’ll find recipes for:

  • Kubernetes installation
  • Kubernetes API, API groups
  • Application primitives
  • Monitoring
  • 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. Online Resources
    7. Conventions Used in This Book
    8. Using Code Examples
    9. O’Reilly Safari
    10. How to Contact Us
    11. Acknowledgments
  2. Getting Started with Kubernetes
    1. 1.1. Using Kubernetes Without Installation
    2. 1.2. Installing the Kubernetes CLI, kubectl
    3. 1.3. Installing Minikube to Run a Local Kubernetes Instance
    4. 1.4. Using Minikube Locally for Development
    5. 1.5. Starting Your First Application on Minikube
    6. 1.6. Accessing the Dashboard in Minikube
  3. Creating a Kubernetes Cluster
    1. 2.1. Installing kubeadm to Create a Kubernetes Cluster
    2. 2.2. Bootstrapping a Kubernetes Cluster Using kubeadm
    3. 2.3. Downloading a Kubernetes Release from GitHub
    4. 2.4. Downloading Client and Server Binaries
    5. 2.5. Using a hyperkube Image to Run a Kubernetes Master Node with Docker
    6. 2.6. Writing a systemd Unit File to Run Kubernetes Components
    7. 2.7. Creating a Kubernetes Cluster on Google Kubernetes Engine (GKE)
    8. 2.8. Creating a Kubernetes Cluster on Azure Container Service (ACS)
  4. 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 Resources with kubectl
    5. 3.5. Asking kubectl to Explain Resources and Fields
  5. Creating and Modifying Fundamental Workloads
    1. 4.1. Creating a Deployment Using kubectl run
    2. 4.2. Creating Objects from File Manifests
    3. 4.3. Writing a Pod Manifest from Scratch
    4. 4.4. Launching a Deployment Using a Manifest
    5. 4.5. Updating a Deployment
  6. 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 on Minikube
    5. 5.5. Making Services Accessible from Outside the Cluster
  7. Exploring the Kubernetes API and Key Metadata
    1. 6.1. Discovering API Endpoints of the Kubernetes API Server
    2. 6.2. Understanding the Structure of a Kubernetes Manifest
    3. 6.3. Creating Namespaces to Avoid Name Collisions
    4. 6.4. Setting Quotas Within a Namespace
    5. 6.5. Labeling an Object
    6. 6.6. Using Labels for Queries
    7. 6.7. Annotating a Resource with One Command
  8. Managing Specialized Workloads
    1. 7.1. Running a Batch Job
    2. 7.2. Running a Task on a Schedule Within a Pod
    3. 7.3. Running Infrastructure Daemons per Node
    4. 7.4. Managing Stateful and Leader/Follower Apps
    5. 7.5. Influencing Pods’ Startup Behavior
  9. 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. Dynamically Provisioning Persistent Storage on GKE
  10. Scaling
    1. 9.1. Scaling a Deployment
    2. 9.2. Automatically Resizing a Cluster in GKE
    3. 9.3. Automatically Resizing a Cluster in AWS
    4. 9.4. Using Horizontal Pod Autoscaling on GKE
  11. 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. Monitoring and Logging
    1. 11.1. Accessing the Logs of a Container
    2. 11.2. Recover from a Broken State with a Liveness Probe
    3. 11.3. Controlling Traffic Flow to a Pod Using a Readiness Probe
    4. 11.4. Adding Liveness and Readiness Probes to Your Deployments
    5. 11.5. Enabling Heapster on Minikube to Monitor Resources
    6. 11.6. Using Prometheus on Minikube
    7. 11.7. Using Elasticsearch–Fluentd–Kibana (EFK) on Minikube
  13. 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. Getting a Detailed Snapshot of the Cluster State
    7. 12.7. Adding Kubernetes Worker Nodes
    8. 12.8. Draining Kubernetes Nodes for Maintenance
    9. 12.9. Managing etcd
  14. Developing Kubernetes
    1. 13.1. Compiling from Source
    2. 13.2. Compiling a Specific Component
    3. 13.3. Using a Python Client to Interact with the Kubernetes API
    4. 13.4. Extending the API Using Custom Resource Definitions (CRDs)
  15. The Ecosystem
    1. 14.1. Installing Helm, the Kubernetes Package Manager
    2. 14.2. Using Helm to Install Applications
    3. 14.3. Creating Your Own Chart to Package Your Application with Helm
    4. 14.4. Converting Your Docker Compose Files to Kubernetes Manifests
    5. 14.5. Creating a Kubernetes Cluster with kubicorn
    6. 14.6. Storing Encrypted Secrets in Version Control
    7. 14.7. Deploying Functions with kubeless
  16. Resources
    1. General
    2. Tutorials and Examples
  17. Index

Product information

  • Title: Kubernetes Cookbook
  • Author(s): Sébastien Goasguen, Michael Hausenblas
  • Release date: February 2018
  • Publisher(s): O'Reilly Media, Inc.
  • ISBN: 9781491979631