Programming Kubernetes

Book description

If you’re looking to develop native applications in Kubernetes, this is your guide. Developers and AppOps administrators will learn how to build Kubernetes-native applications that interact directly with the API server to query or update the state of resources. AWS developer advocate Michael Hausenblas and Red Hat principal software engineer Stefan Schimanski explain the characteristics of these apps and show you how to program Kubernetes to build them.

You’ll explore the basic building blocks of Kubernetes, including the client-go API library and custom resources. All you need to get started is a rudimentary understanding of development and system administration tools and practices, such as package management, the Go programming language, and Git.

  • Walk through Kubernetes API basics and dive into the server’s inner structure
  • Explore Kubernetes’s programming interface in Go, including Kubernetes API objects
  • Learn about custom resources—the central extension tools used in the Kubernetes ecosystem
  • Use tags to control Kubernetes code generators for custom resources
  • Write custom controllers and operators and make them production ready
  • Extend the Kubernetes API surface by implementing a custom API server

Publisher resources

View/Submit Errata

Table of contents

  1. Preface
    1. Who Should Read This Book
    2. Why We Wrote This Book
    3. Ecosystem
    4. Technology You Need to Understand
    5. Conventions Used in This Book
    6. Using Code Examples
    7. O’Reilly Online Learning
    8. How to Contact Us
    9. Acknowledgments
  2. 1. Introduction
    1. What Does Programming Kubernetes Mean?
    2. A Motivational Example
    3. Extension Patterns
    4. Controllers and Operators
      1. The Control Loop
      2. Events
      3. Edge- Versus Level-Driven Triggers
      4. Changing Cluster Objects or the External World
      5. Optimistic Concurrency
      6. Operators
    5. Summary
  3. 2. Kubernetes API Basics
    1. The API Server
      1. The HTTP Interface of the API Server
      2. API Terminology
      3. Kubernetes API Versioning
      4. Declarative State Management
    2. Using the API from the Command Line
    3. How the API Server Processes Requests
    4. Summary
  4. 3. Basics of client-go
    1. The Repositories
      1. The Client Library
      2. Kubernetes API Types
      3. API Machinery
      4. Creating and Using a Client
      5. Versioning and Compatibility
      6. API Versions and Compatibility Guarantees
    2. Kubernetes Objects in Go
      1. TypeMeta
      2. ObjectMeta
      3. spec and status
    3. Client Sets
      1. Status Subresources: UpdateStatus
      2. Listings and Deletions
      3. Watches
      4. Client Expansion
      5. Client Options
    4. Informers and Caching
      1. Work Queue
    5. API Machinery in Depth
      1. Kinds
      2. Resources
      3. REST Mapping
      4. Scheme
    6. Vendoring
      1. glide
      2. dep
      3. Go Modules
    7. Summary
  5. 4. Using Custom Resources
    1. Discovery Information
    2. Type Definitions
    3. Advanced Features of Custom Resources
      1. Validating Custom Resources
      2. Short Names and Categories
      3. Printer Columns
      4. Subresources
    4. A Developer’s View on Custom Resources
      1. Dynamic Client
      2. Typed Clients
      3. controller-runtime Client of Operator SDK and Kubebuilder
    5. Summary
  6. 5. Automating Code Generation
    1. Why Code Generation
    2. Calling the Generators
    3. Controlling the Generators with Tags
      1. Global Tags
      2. Local Tags
      3. deepcopy-gen Tags
      4. runtime.Object and DeepCopyObject
      5. client-gen Tags
      6. informer-gen and lister-gen
    4. Summary
  7. 6. Solutions for Writing Operators
    1. Preparation
    2. Following sample-controller
      1. Bootstrapping
      2. Business Logic
    3. Kubebuilder
      1. Bootstrapping
      2. Business Logic
    4. The Operator SDK
      1. Bootstrapping
      2. Business Logic
    5. Other Approaches
    6. Uptake and Future Directions
    7. Summary
  8. 7. Shipping Controllers and Operators
    1. Lifecycle Management and Packaging
      1. Packaging: The Challenge
      2. Helm
      3. Kustomize
      4. Other Packaging Options
      5. Packaging Best Practices
      6. Lifecycle Management
    2. Production-Ready Deployments
      1. Getting the Permissions Right
      2. Automated Builds and Testing
      3. Custom Controllers and Observability
    3. Summary
  9. 8. Custom API Servers
    1. Use Cases for Custom API Servers
    2. Example: A Pizza Restaurant
    3. The Architecture: Aggregation
      1. API Services
      2. Inner Structure of a Custom API Server
      3. Delegated Authentication and Trust
      4. Delegated Authorization
    4. Writing Custom API Servers
      1. Options and Config Pattern and Startup Plumbing
      2. The First Start
      3. Internal Types and Conversion
      4. Writing the API Types
      5. Conversions
      6. Defaulting
      7. Roundtrip Testing
      8. Validation
      9. Registry and Strategy
      10. API Installation
      11. Admission
    5. Deploying Custom API Servers
      1. Deployment Manifests
      2. Setting Up RBAC
      3. Running the Custom API Server Insecurely
      4. Certificates and Trust
      5. Sharing etcd
    6. Summary
  10. 9. Advanced Custom Resources
    1. Custom Resource Versioning
      1. Revising the Pizza Restaurant
      2. Conversion Webhook Architecture
      3. Conversion Webhook Implementation
      4. Setting Up the HTTPS Server
      5. Deploying the Conversion Webhook
      6. Seeing Conversion in Action
    2. Admission Webhooks
      1. Admission Requirements in the Restaurant Example
      2. Admission Webhook Architecture
      3. Registering Admission Webhooks
      4. Implementing an Admission Webhook
      5. Admission Webhook in Action
    3. Structural Schemas and the Future of CustomResourceDefinitions
      1. Structural Schemas
      2. Pruning Versus Preserving Unknown Fields
      3. Controlling Pruning
      4. IntOrString and RawExtensions
      5. Default Values
    4. Summary
  11. A. Resources
    1. General
    2. Books
    3. Tutorials and Examples
    4. Articles
    5. Repositories
  12. Index

Product information

  • Title: Programming Kubernetes
  • Author(s): Michael Hausenblas, Stefan Schimanski
  • Release date: July 2019
  • Publisher(s): O'Reilly Media, Inc.
  • ISBN: 9781492047100