sample-controller is a reference implementation of a Kubernetes controller that demonstrates how to build a custom resource controller using CustomResourceDefinitions.
The tool addresses the problem of understanding how to implement a production-style Kubernetes controller. It shows the fundamental patterns: registering a custom resource type called Foo via CustomResourceDefinition, performing basic operations like create, get, and list on instances of that resource, and setting up a controller to handle create, update, and delete events. The implementation uses the client-go library extensively and leverages code generators from k8s.io/code-generator to produce typed clients, informers, listers, and deep-copy functions automatically rather than maintaining them by hand.
Developers building custom controllers for Kubernetes should use this as a template. It suits anyone implementing a controller for a single custom resource type and provides a foundation that can be extended for more complex scenarios. The example demonstrates practical use cases such as provisioning external databases or creating higher-level abstractions around Kubernetes primitives. The repository requires a Kubernetes cluster version greater than 1.9 due to its use of apps/v1 deployments.
This is a staged repository automatically published from the main Kubernetes codebase, meaning all contributions flow through the primary Kubernetes repository rather than being made directly here. The repository is read-only for importing purposes. The project includes documentation explaining the interaction points between the sample controller and the client-go library mechanisms, and provides an update-codegen script that developers should run to generate their own code rather than copying the generated files when creating controllers based on this implementation.