The Kubernetes Operator Framework Book

Book description

Design and deploy an operator for personal use and public distribution and get to grips with writing, packaging, and distributing a basic operator for a Kubernetes cluster

Key Features

  • Develop a holistic understanding of operators and the Operator Framework
  • Learn to design and develop your own operators as per industry standards
  • Find out how to implement best practices and troubleshoot Kubernetes operators

Book Description

From incomplete collections of knowledge and varying design approaches to technical knowledge barriers, Kubernetes users face various challenges when developing their own operators. Knowing how to write, deploy, and pack operators makes cluster management automation much easier – and that's what this book is here to teach you.

Beginning with operators and Operator Framework fundamentals, the book delves into how the different components of Operator Framework (such as the Operator SDK, Operator Lifecycle Manager, and OperatorHub.io) are used to build operators. You'll learn how to write a basic operator, interact with a Kubernetes cluster in code, and distribute that operator to users. As you advance, you'll be able to develop a sample operator in the Go programming language using Operator SDK tools before running it locally with Operator Lifecycle Manager, and also learn how to package an operator bundle for distribution. The book covers best practices as well as sample applications and case studies based on real-world operators to help you implement the concepts you've learned.

By the end of this Kubernetes book, you'll be able to build and add application-specific operational logic to a Kubernetes cluster, making it easier to automate complex applications and augment the platform.

What you will learn

  • Gain insight into the Operator Framework and the benefits of operators
  • Implement standard approaches for designing an operator
  • Develop an operator in a stepwise manner using the Operator SDK
  • Publish operators using distribution options such as OperatorHub.io
  • Deploy operators using different Operator Lifecycle Manager options
  • Discover how Kubernetes development standards relate to operators
  • Apply knowledge learned from the case studies of real-world operators

Who this book is for

This book is for DevOps and cloud engineers, Kubernetes engineers, SREs, developers, and cloud architects interested in automating the management of their Kubernetes clusters. It assumes a basic understanding of core Kubernetes topics or familiarity with Kubernetes and container orchestration.

Table of contents

  1. The Kubernetes Operator Framework Book
  2. Contributors
  3. About the author
  4. About the reviewers
  5. Preface
    1. Who this book is for
    2. What this book covers
    3. To get the most out of this book
    4. Download the example code files
    5. Code in Action
    6. Download the color images
    7. Conventions used
    8. Get in touch
    9. Share Your Thoughts
  6. Part 1: Essentials of Operators and the Operator Framework
  7. Chapter 1: Introducing the Operator Framework
    1. Technical requirements
    2. Managing clusters without Operators
      1. Demonstrating on a sample application
      2. Reacting to changing cluster states
    3. Introducing the Operator Framework
      1. Exploring Kubernetes controllers
      2. Knowing key terms for Operators
      3. Putting it all together
    4. Developing with the Operator SDK
    5. Managing Operators with OLM
    6. Distributing Operators on OperatorHub.io
    7. Defining Operator functions with the Capability Model
    8. Using Operators to manage applications
      1. Summarizing the Operator Framework
      2. Applying Operator capabilities
    9. Summary
  8. Chapter 2: Understanding How Operators Interact with Kubernetes
    1. Interacting with Kubernetes cluster resources
      1. Pods, ReplicaSets, and Deployments
      2. Custom resource definitions
      3. ServiceAccounts, roles, and RoleBindings (RBAC)
      4. Namespaces
    2. Identifying users and maintainers
      1. Cluster administrators
      2. Cluster users
      3. End users and customers
      4. Maintainers
    3. Designing beneficial features for your operator
    4. Planning for changes in your Operator
      1. Starting small
      2. Iterating effectively
      3. Deprecating gracefully
    5. Summary
  9. Part 2: Designing and Developing an Operator
  10. Chapter 3: Designing an Operator – CRD, API, and Target Reconciliation
    1. Describing the problem
    2. Designing an API and a CRD
      1. Following the Kubernetes API design conventions
      2. Understanding a CRD schema
      3. Example Operator CRD
    3. Working with other required resources
    4. Designing a target reconciliation loop
      1. Level- versus edge-based event triggering
      2. Designing reconcile logic
    5. Handling upgrades and downgrades
    6. Using failure reporting
      1. Reporting errors with logging
      2. Reporting errors with status updates
      3. Reporting errors with events
    7. Summary
  11. Chapter 4: Developing an Operator with the Operator SDK
    1. Technical requirements
    2. Setting up your project
    3. Defining an API
    4. Adding resource manifests
      1. Additional manifests and BinData
    5. Writing a control loop
    6. Troubleshooting
      1. General Kubernetes resources
      2. Operator SDK resources
      3. Kubebuilder resources
    7. Summary
  12. Chapter 5: Developing an Operator – Advanced Functionality
    1. Technical requirements
    2. Understanding the need for advanced functionality
    3. Reporting status conditions
      1. Operator CRD conditions
      2. Using the OLM OperatorCondition
    4. Implementing metrics reporting
      1. Adding a custom service metric
      2. RED metrics
    5. Implementing leader election
    6. Adding health checks
    7. Summary
  13. Chapter 6: Building and Deploying Your Operator
    1. Technical requirements
    2. Building a container image
      1. Building the Operator locally
      2. Building the Operator image with Docker
    3. Deploying in a test cluster
    4. Pushing and testing changes
      1. Installing and configuring kube-prometheus
      2. Redeploying the Operator with metrics
      3. Key takeaways
    5. Troubleshooting
      1. Makefile issues
      2. kind
      3. Docker
      4. Metrics
      5. Additional errors
    6. Summary
  14. Part 3: Deploying and Distributing Operators for Public Use
  15. Chapter 7: Installing and Running Operators with the Operator Lifecycle Manager
    1. Technical requirements
    2. Understanding the OLM
      1. Installing the OLM in a Kubernetes cluster
      2. Interacting with the OLM
    3. Running your Operator
      1. Generating an Operator's bundle
      2. Exploring the bundle files
      3. Building a bundle image
      4. Pushing a bundle image
      5. Deploying an Operator bundle with the OLM
    4. Working with OperatorHub
      1. Installing Operators from OperatorHub
      2. Submitting your own Operator to OperatorHub
    5. Troubleshooting
      1. OLM support
      2. OperatorHub support
    6. Summary
  16. Chapter 8: Preparing for Ongoing Maintenance of Your Operator
    1. Technical requirements
    2. Releasing new versions of your Operator
      1. Adding an API version to your Operator
      2. Updating the Operator CSV version
      3. Releasing a new version on OperatorHub
    3. Planning for deprecation and backward compatibility
      1. Revisiting Operator design
      2. Starting small
      3. Iterating effectively
      4. Deprecating gracefully
    4. Complying with Kubernetes standards for changes
      1. Removing APIs
      2. API conversion
      3. API lifetime
    5. Aligning with the Kubernetes release timeline
      1. Overview of a Kubernetes release
      2. Start of release
      3. Enhancements Freeze
      4. Call for Exceptions
      5. Code Freeze
      6. Test Freeze
      7. GA release/Code Thaw
      8. Retrospective
    6. Working with the Kubernetes community
    7. Summary
  17. Chapter 9: Diving into FAQs and Future Trends
    1. FAQs about the Operator Framework
      1. What is an Operator?
      2. What benefit do Operators provide to a Kubernetes cluster?
      3. How are Operators different from other Kubernetes controllers?
      4. What is the Operator Framework?
      5. What is an Operand?
      6. What are the main components of the Operator Framework?
      7. What programming languages can Operators be written in?
      8. What is the Operator Capability Model?
    2. FAQs about Operator design, CRDs, and APIs
      1. How does an Operator interact with Kubernetes?
      2. What cluster resources does an Operator act on?
      3. What is a CRD?
      4. How is a CRD different from a CR object?
      5. What Kubernetes namespaces do Operators run within?
      6. How do users interact with an Operator?
      7. How can you plan for changes early in an Operator's lifecycle?
      8. How does an Operator's API relate to its CRD?
      9. What are the conventions for an Operator API?
      10. What is a structural CRD schema?
      11. What is OpenAPI v3 validation?
      12. What is Kubebuilder?
      13. What is a reconciliation loop?
      14. What is the main function of an Operator's reconciliation loop?
      15. What are the two kinds of event triggering?
      16. What is a ClusterServiceVersion (CSV)?
      17. How can Operators handle upgrades and downgrades?
      18. How can Operators report failures?
      19. What are status conditions?
      20. What are Kubernetes events?
    3. FAQs about the Operator SDK and coding controller logic
      1. What is the Operator SDK?
      2. How can operator-sdk scaffold a boilerplate Operator project?
      3. What does a boilerplate Operator project contain?
      4. How can you create an API with operator-sdk?
      5. What does a basic Operator API created with operator-sdk look like?
      6. What other code is generated by operator-sdk?
      7. What do Kubebuilder markers do?
      8. How does the Operator SDK generate Operator resource manifests?
      9. How else can you customize generated Operator manifests?
      10. What are go-bindata and go:embed?
      11. What is the basic structure of a control/reconciliation loop?
      12. How does a control loop function access Operator config settings?
      13. What information does a status condition report?
      14. What are the two basic kinds of metrics?
      15. How can metrics be collected?
      16. What are RED metrics?
      17. What is leader election?
      18. What are the two main strategies for leader election?
      19. What are health and ready checks?
    4. FAQs about OperatorHub and the OLM
      1. What are the different ways to compile an Operator?
      2. How does a basic Operator SDK project build a container image?
      3. How can an Operator be deployed in a Kubernetes cluster?
      4. What is the OLM?
      5. What benefit does running an Operator with the OLM provide?
      6. How do you install the OLM in a cluster?
      7. What does the operator-sdk olm status command show?
      8. What is an Operator bundle?
      9. How do you generate a bundle?
      10. What is a bundle image?
      11. How do you build a bundle image?
      12. How do you deploy a bundle with the OLM?
      13. What is OperatorHub?
      14. How do you install an Operator from OperatorHub?
      15. How do you submit an Operator to OperatorHub?
    5. Future trends in the Operator Framework
      1. How do you release a new version of an Operator?
      2. When is it appropriate to add a new API version?
      3. How do you add a new API version?
      4. What is an API conversion?
      5. How do you convert between two versions of an API?
      6. What is a conversion webhook?
      7. How do you add a conversion webhook to an Operator?
      8. What is kube-storage-version-migrator?
      9. How do you update an Operator's CSV?
      10. What are upgrade channels?
      11. How do you publish a new version on OperatorHub?
      12. What is the Kubernetes deprecation policy?
      13. How can API elements be removed in the Kubernetes deprecation policy?
      14. How long are API versions generally supported?
      15. How long is the Kubernetes release cycle?
      16. What is Enhancements Freeze?
      17. What is Code Freeze?
      18. What is Retrospective?
      19. How do Kubernetes community standards apply to Operator development?
    6. Summary
  18. Chapter 10: Case Study for Optional Operators – the Prometheus Operator
    1. A real-world use case
      1. Prometheus overview
      2. Installing and running Prometheus
      3. Configuring Prometheus
      4. Summarizing the problems with manual Prometheus
    2. Operator design
      1. CRDs and APIs
      2. Reconciliation logic
    3. Operator distribution and development
    4. Updates and maintenance
    5. Summary
  19. Chapter 11: Case Study for Core Operator – Etcd Operator
    1. Core Operators – extending the Kubernetes platform
      1. RBAC Manager
      2. The Kube Scheduler Operator
      3. The etcd Operator
    2. etcd Operator design
      1. CRDs
      2. Reconciliation logic
      3. Failure recovery
    3. Stability and safety
    4. Upgrading Kubernetes
    5. Summary
    6. Why subscribe?
  20. Other Books You May Enjoy
    1. Packt is searching for authors like you
    2. Share Your Thoughts

Product information

  • Title: The Kubernetes Operator Framework Book
  • Author(s): Michael Dame
  • Release date: July 2022
  • Publisher(s): Packt Publishing
  • ISBN: 9781803232850