Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the principle and function of KubeBuilder

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly explains "what is the principle and function of KubeBuilder". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "what is the principle and function of KubeBuilder".

Overview of Operator

Operator is an extension of Kubernetes, which uses custom resource management applications and their components. Operator follows the philosophy of Kubernetes, especially in terms of controllers [^ 1]

K8s is a highly automated system, which covers most of the functions required by common applications, such as service discovery, load balancing, HPA, etc., these functions are realized by some controllers of K8s, but the requirements are always endless, when we have similar requirements but K8s can not meet very well, we can use Operator and Custome Resource (custom resources) to achieve similar results.

For example, common requirements include deployment of a database, automatic operation and maintenance of nodes, configuration of log collection components, and so on.

From the introduction of the concept of Operator to now, there are many tools that can help us to develop quickly and at a low cost, the most commonly used of which are CoreOS's open source operator-sdk [^ 3] and kubebuilder [^ 2] maintained by the K8s sig team. We choose kubebuilder for this series.

Before we begin, let's take a look at two core concepts that will soon be covered.

GV & GVK & GVR

GV: Api Group & Version

API Group is a collection of related API functions

Each Group has one or more Versions

GVK: Group Version Kind

Each GV contains N api types, called Kinds. Different Version and the same Kinds may be different.

GVR: Group Version Resource

Resource is the object identifier of Kind. Generally speaking, the relationship between Kind and Resource is 1:1, but sometimes there is a relationship of one Kind to n, but for Operator, it is always 1:1.

For example, our yaml file in K8s has the following two lines, such as the nginx deployment we deployed in the previous article

ApiVersion: apps/v1 # this is GV,G is apps,V is v1 kind: Deployment # this is Kind sepc: # plus decentralized spec is Resource.

According to GVK K8s, you can find out what type of resource you want to create. After creating the resource according to your defined Spec, it becomes Resource, that is, GVR. GVK/GVR is the coordinates of K8s resources and is the basis for us to create / delete / modify / read resources [^ 4].

KubeBuilder Concise tutorial

Installation

Visit the official warehouse to download the compiled binaries: Releases kubernetes-sigs/kubebuilder (github.com)

At the time of writing, kubebuilder has already launched the v3.0.0-rc.0 version, so in order to avoid the embarrassment of having already release as soon as the new version is written, this article directly uses version 3.0.

After downloading, remember to add the corresponding file to PATH.

After a successful installation, you can use kubebuilder version to view the installed version information.

❯ kubebuilder version Version: main.version {KubeBuilderVersion: "3.0.0-rc.0", KubernetesVendor: "1.19.2", GitCommit: "90fe4124c4c6965c6bfac63339888956952cda90", BuildDate: "2021-04-08T17:36:28Z", GoOs: "linux", GoArch: "amd64"} Project initialization

First create an empty folder, and then execute the following command in the folder

Kubebuilder init-domain lailin.xyz-repo github.com/mohuishou/blog-code/k8s-operator/02-kubebuilder

-- domain lailin.xyz the domain name of our project

-- repo xxx is the address of the warehouse as well as the repo address in go mode.

If your golang version is too low or too high, you may get the error message below. I am here because the 1.16 version is too high.

2021-04-25 20:47:14 failed to initialize project: unable to run pre-scaffold tasks of "base.go.kubebuilder.io/v3": go version 'go1.16' is incompatible because' requires 1.13

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report