404 Not Found
  • Introduction
  • Monitoring related
    • K8s cluster monitoring
    • Monitor Jenkins with G.A.P on K8s cluster
    • Monitoring tools | projects
      • Grafana
      • AlertManager
      • Prometheus
      • Wavefront
  • Logging related
    • BOSH logs
    • How to gather systemd log
    • K8s cluster logging
    • Logging tools | projects
      • vRealize Log Insight
      • Fluentd
      • syslog vs fluentd
  • Having fun with docker
    • Using docker-compose for redmine
    • Customize Fluentd docker image
  • K8S or Apache Mesos
  • K8S Related
    • Main Architecture
      • Master components
        • API Server
        • etcd
        • Controller Manager
        • Kube Scheduler
      • Worker components
        • kubelet
        • kube-proxy
    • K8S Storage
      • Volume Provisioning
      • Understand CSI
      • How to write CSI
      • VMware CNS
      • K8S storage e2e experiment under VMware vSphere
      • Experiment on Persistent Volume Access Mode
      • Design: Storage in Cluster-API architecture
    • K8S Networking
      • Ingress
      • Endpoints
    • K8S Policies
      • Resource Quotas
    • K8S Management Platform
    • K8S Tests Tool
    • K8S Extension
      • CRDs
        • Custom Resources
        • Custom Controllers
        • How to user code-generator
        • K8S Operators
        • Operators Development Tools
          • Kubebuilder
          • Metacontroller
          • Operator SDK
      • Custom API Server
    • K8S Resource CRUD Workflow
    • K8S Garbage Collection
  • K8S CONTROLLER RELATED
    • IsController: true
    • Controller clients
  • PKS RELATED
    • How to Access VMs and Databases related to PKS
    • PKS Basics
    • BOSH Director
    • Backup and Restore on Ent. PKS with Velero
  • CICD RELATED
    • Configure Jenkins to run on K8S
    • Customize Jenkins JNLP slave image
    • Jenkins global shared libs
  • Google Anthos
    • Google Anthos Day from KubeCon 2019 San Diego
    • Migrate for Anthos
    • Config Connector
  • SYSTEM DESIGN RELATED
    • Design Data Intensive Application - Notes
      • RSM
        • Reliability
        • Scalability
      • Data models and Query Languages
      • Storage and Retrieval
    • How Alibaba Ensure K8S Performance At Large Scale
  • Miscellaneous
    • Knative
    • Serverless
    • Service Mesh
    • gRPC
    • Local persistent volumes
    • ownerReferences in K8S
    • File(NAS) vs Block(SAN) vs Object storage
    • KubeVirt
    • Why K8S HA chooses 3 instead of 5..6..7 as the size of masters?
    • goroutine & go channel
    • How to make docker images smaller
Powered by GitBook
On this page
  • What is Kubebuilder?
  • Why Kubebuilder and Kubernetes APIs?
  • Under the hood of Kubebuilder
  • Kubebuilder component
  • Custome controller component
  • Installation of Kubebuilder
  • Known issues

Was this helpful?

  1. K8S Related
  2. K8S Extension
  3. CRDs
  4. Operators Development Tools

Kubebuilder

PreviousOperators Development ToolsNextMetacontroller

Last updated 5 years ago

Was this helpful?

What is Kubebuilder?

Kubebuilder is an SDK for quickly and easily building and publishing Kubernetes APIs in Golang. It is built on top of the Kubernetes existing canonical technique to provide simple abstractions to reduce the need for boilerplate.

Why Kubebuilder and Kubernetes APIs?

Applications and kubernetes cluster resources typically require some work operators, such as for replacing failed replicas with new ones, or scaling counts while resharding data. Running the MySQL application may require scheduling backups, reconfiguring replicas after scaling, setting up failure detection and remediation, etc.

With the Kubernetes API model, the management logic is embedded directly into application-specific Kubernetes APIs, for example, the “MySQL” API. Users then manage the application through YAML configuration using tools such as kubectl, just like they do for Kubernetes objects.

Under the hood of Kubebuilder

Kubebuilder component

Generic controller

  • Act as a wrapper of the custom controller, which is based on sample-controller.

  • It defines the queue in which Objects are delivered by Informers using event handlers (not shown). The queue itself is not exposed to our custom controller.

  • Defines a variable that will hold reference to the Reconcile function that our custom controller will implement.

Controller manager

The ControllerManager manages custom controllers. It maintains two data structures: list of controller references and a map of Objects and their Informers. It provides following functions to populate the two data structures: AddInformerProvider, AddController, RunInformersAndControllers.

Injector

An Injector defines two data structures:

  • a list for storing CRDs that need to be registered

  • a list for storing functions that should be invoked for starting informers and controllers.

The CRD list will be populated by the registration of CRDs whose Objects our custom controller will be monitoring. The registration of the CRDs is done in the setup phase. The function list is also populated during the setup phase.

Custome controller component

xxx_controller.go

The implementation of our controller.

main.go

The entrypoint of running a controller.

other bunch of generated files

These files have something like DeepCopy(), and the code which used by Kubebuilder components.

Installation of Kubebuilder

Known issues

Case

Solution

Remark

kubebuilder create api --group "storage.k8s.io" --version "v1" --kind "StorageClass" Create Resource under pkg/apis [y/n]? n Create Controller under pkg/controller [y/n]? y

......

2019/08/28 14:15:08 pkg/controller/storageclass/storageclass_controller.go:30:9: expected 'STRING', found '.' (and 10 more errors)

Change --group storage.k8s.io to --group storage

This might not be an official solution.

Check out the official kubebuilder book . Once you have kubebuilder installed, you could simply run kubebuilder version to check if the correct version is installed.

here