ScriptsApr 16, 2026·3 min read

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.

TL;DR
Operator SDK scaffolds and manages Kubernetes operators in Go, Ansible, or Helm with built-in best practices.
§01

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.

§02

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.

§03

How to use

  1. Install the Operator SDK CLI:
brew install operator-sdk
  1. 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
  1. 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
§04

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
}
§05

Related on TokRepo

§06

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 .status so 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

What languages can I use to write an operator with Operator SDK?+

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.

How does Operator SDK relate to the Operator Framework?+

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.

Can I convert a Helm chart into an operator?+

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.

What Kubernetes versions does Operator SDK support?+

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.

Do I need to understand controller-runtime to use the Go-based SDK?+

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)

Discussion

Sign in to join the discussion.
No comments yet. Be the first to share your thoughts.

Related Assets