kubernetes kubebuilder實現crd(二)

本篇主要介紹如何在crd中添加字段信息

1、看下config/samples下面的yaml文件:

kubectl get guestbooks.webapp.my.domain -o yaml

spec:

  # Add fields here

  foo: bar

這裏參數裏只有foo:bar

 

2、我們來加個虛擬CPU,內存信息:

直接api/v1/guestbook_types.go即可
 

type GuestbookSpec struct {

        // INSERT ADDITIONAL SPEC FIELDS - desired state of cluster

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

        CPU    string `json:"cpu"`  //這是新增的

        Memory string `json:"memory"`//這是新增的

}

 

3、然後make一下:

3.1、編譯,真正執行的命令是go build -o bin/manager main.go

make

 

安裝CRD,真正執行的命令是kubectl apply -f config/crd/bases

make install

 

啓動controller:

make run,真正執行的命令是go run ./main.go

注意:

make實際執行的Makefile中的manager方法,可以先把下載包的給註釋掉

4、再去渲染一下controller的yaml就會發現CRD中已經帶上CPU和內存信息了:

kustomize build config/default

5、修改yaml文件:

/home/sankuai/m/config/samples/webapp_v1_guestbook.yaml

6、讓修改生效

驗證成功

發佈了17 篇原創文章 · 獲贊 1 · 訪問量 2024
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章