Operator SDK — Build Kubernetes Operators the Easy Way
The Operator SDK provides scaffolding, code generation, and lifecycle management tools for building Kubernetes operators in Go, Ansible, or Helm with best-practice patterns built in.
What it is
Operator SDK is part of the Operator Framework, an open-source toolkit for managing Kubernetes-native applications called Operators. It provides scaffolding, code generation, and lifecycle management tools that let you build operators in Go, Ansible, or Helm without writing boilerplate from scratch.
Operator SDK is designed for platform engineers and DevOps teams who need to encode operational knowledge into Kubernetes controllers that automate day-2 operations like backups, upgrades, and scaling.
How it saves time or tokens
Building a Kubernetes operator from scratch requires deep knowledge of controller-runtime, client-go, informers, and reconciliation loops. Operator SDK generates the project structure, CRD scaffolding, RBAC manifests, and test harnesses automatically. A Go-based operator that would take days to bootstrap can be scaffolded in minutes. The SDK also handles OLM (Operator Lifecycle Manager) integration for distribution, eliminating another layer of manual work.
How to use
- Install the Operator SDK CLI:
brew install operator-sdk
- Scaffold a new Go-based operator:
operator-sdk init --domain example.com --repo github.com/myorg/my-operator
operator-sdk create api --group app --version v1alpha1 --kind MyApp --resource --controller
- Implement your reconciliation logic in
internal/controllers/myapp_controller.go, then build and deploy:
make docker-build docker-push IMG=myregistry/my-operator:v0.1.0
make deploy IMG=myregistry/my-operator:v0.1.0
Example
A minimal reconcile loop for a Go-based operator:
func (r *MyAppReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
log := log.FromContext(ctx)
var myapp appv1alpha1.MyApp
if err := r.Get(ctx, req.NamespacedName, &myapp); err != nil {
return ctrl.Result{}, client.IgnoreNotFound(err)
}
log.Info("Reconciling MyApp", "name", myapp.Name)
// Ensure a Deployment exists for this MyApp
dep := &appsv1.Deployment{}
err := r.Get(ctx, types.NamespacedName{Name: myapp.Name, Namespace: myapp.Namespace}, dep)
if errors.IsNotFound(err) {
dep = r.deploymentForMyApp(&myapp)
if err := r.Create(ctx, dep); err != nil {
return ctrl.Result{}, err
}
}
return ctrl.Result{}, nil
}
Related on TokRepo
- DevOps tools — Browse infrastructure and operations tooling
- Automation tools — Explore automation frameworks for Kubernetes
Common pitfalls
- Not setting proper RBAC permissions in the generated ClusterRole. The scaffold provides a starting point, but you must add permissions for any additional resources your operator watches or modifies.
- Skipping the OLM bundle generation step when distributing via OperatorHub. Without a proper bundle, your operator cannot be discovered or installed through the standard catalog.
- Ignoring status subresource updates. Your reconciler should always write back to
.statusso that users and other controllers can observe the current state of your custom resource. - Starting with an overly complex configuration instead of defaults. Begin with the minimal setup, verify it works, then customize incrementally. This approach catches configuration errors early and keeps troubleshooting straightforward.
Frequently Asked Questions
Operator SDK supports three approaches: Go (using controller-runtime), Ansible (using ansible-runner), and Helm (wrapping existing Helm charts). Go provides the most flexibility, while Ansible and Helm let you reuse existing automation without writing Go code.
Operator SDK is one component of the broader Operator Framework, which also includes the Operator Lifecycle Manager (OLM) for installation and upgrades, and OperatorHub for discovery and distribution. The SDK handles building the operator; OLM handles running it.
Yes. Operator SDK has a Helm-based operator type that wraps an existing Helm chart in a Kubernetes operator. Run operator-sdk init --plugins helm and operator-sdk create api --helm-chart=your-chart to generate the project.
Operator SDK tracks the upstream controller-runtime and client-go libraries. It generally supports the three most recent Kubernetes minor versions. Check the SDK release notes for the exact compatibility matrix.
A basic understanding helps. Operator SDK generates the boilerplate, but you write the reconciliation logic using controller-runtime primitives like client.Client, ctrl.Request, and ctrl.Result. The SDK documentation includes tutorials that teach these concepts incrementally.
Citations (3)
- Operator SDK GitHub— Operator SDK is part of the Operator Framework
- Operator SDK Documentation— Supports Go, Ansible, and Helm operator types
- OLM Documentation— OLM manages operator lifecycle in Kubernetes
Related on TokRepo
Discussion
Related Assets
NAPI-RS — Build Node.js Native Addons in Rust
Write high-performance Node.js native modules in Rust with automatic TypeScript type generation and cross-platform prebuilt binaries.
Mamba — Fast Cross-Platform Package Manager
A drop-in conda replacement written in C++ that resolves environments in seconds instead of minutes.
Plasmo — The Browser Extension Framework
Build, test, and publish browser extensions for Chrome, Firefox, and Edge using React or Vue with hot-reload and automatic manifest generation.