加入收藏 | 设为首页 | 会员中心 | 我要投稿 拼字网 - 核心网 (https://www.hexinwang.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 教程 > 正文

KubeBuilder 基础入门指南让你不在迷失方向

发布时间:2021-05-26 10:03:24 所属栏目:教程 来源:互联网
导读:KubeBuilder 简明教程 安装 访问官方仓库下载已经编译好的二进制文件: Releases kubernetes-sigs/kubebuilder (github.com) 本文编写的时候 kubebuilder 已经推

 // Important: Run "make" to regenerate code after modifying this file 

 

 // Product 该应用所属的产品 

 Product string `json:"product,omitempty"` 

修改之后我们执行一下 make manifests generate 可以发现已经生成了相关的字段,并且代码中的字段注释也就是 yaml 文件中的注释

# config/crd/bases/apps.lailin.xyz_applications.yaml 

...... 

   properties: 

              product: 

                description: Product 该应用所属的产品 

                type: string 

...... 

实现 controller

kubebuilder 已经帮我们实现了 Operator 所需的大部分逻辑,我们只需要在 Reconcile 中实现业务逻辑就行了

// controllers/application_controller.go 

 

func (r *ApplicationReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { 

 _ = r.Log.WithValues("application", req.NamespacedName) 

 

 r.Log.Info("app changed", "ns", req.Namespace) 

 

 return ctrl.Result{}, nil 

逻辑修改好之后,我们先执行 make install 安装 CRD,然后执行 make run运行 controller

go run ./main.go 

(编辑:拼字网 - 核心网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!