本篇主要介紹如何在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、讓修改生效
驗證成功