Common recommendations and suggestions

Common recommendations and suggestions to built solutions with Operator SDK

Overview

Any recommendations or best practices suggested by the Kubernetes community, such as how to develop Operator pattern solutions or how to use controller-runtime are good recommendations for those who are looking to build operator projects with operator-sdk. Also, see Operator Best Practices. However, here are some common recommendations.

Common Recommendations

Develop idempotent reconciliation solutions

When developing operators, it is essential for the controller’s reconciliation loop to be idempotent. By following the Operator pattern you will create Controllers which provide a reconcile function responsible for synchronizing resources until the desired state is reached on the cluster. Breaking this recommendation goes against the design principles of controller-runtime and may lead to unforeseen consequences such as resources becoming stuck and requiring manual intervention.

Understanding Kubernetes APIs

Building your own operator commonly involves extending the Kubernetes API itself. It is helpful to understand exactly how Custom Resource Definitions interact with the Kubernetes API. Also, the Kubebuilder documentation on Groups and Versions and Kinds may be helpful to better understand these concepts as they relate to operators.

Avoid a design solution where more than one Kind is reconciled by the same controller

Having many Kinds (such as CRDs) which are all managed by the same controller usually goes against the design proposed by controller-runtime. Furthermore this might hurt concepts such as encapsulation, the Single Responsibility Principle, and Cohesion. Damaging these concepts may cause unexpected side effects, and increase the difficulty of extending, reusing, or maintaining the operator.

Other common suggestions

  • Provide the images and tags used by the operator solution via environment variables in the config/manager/manager.yaml:
  1. ...
  2. spec:
  3. ...
  4. spec:
  5. ...
  6. containers:
  7. - command:
  8. - /manager
  9. ...
  10. env:
  11. - name: MY_IMAGE
  12. value: "quay.io/example.com/image:0.0.1"

Last modified November 11, 2021: docs [bestpractices/common suggestions]: small typo nit (#5352) (e60d4ccc)