创建k8s自定义资源的controller

2019-10-22  本文已影响0人  怀旧的艾克

自定义资源

api group: github.com
version: v1alpha1
resource name: MyResource

创建目录

mkdir $GOPATH/src/github.com/crd-code-generation
mkdir -p pkg/apis/myresource/v1alpha1

# 创建三个文件,需要自己写
touch pkg/apis/myresource/v1alpha1/register.go
touch pkg/apis/myresource/v1alpha1/doc.go
touch pkg/apis/myresource/v1alpha1/types.go

使用code-gen

Git clone https://github.com/kubernetes/code-generator.git
export GOPROXY=https://goproxy.io
export GO111MODULE=on
go mod vendor -v
export GOPATH="/Users/xxx/go”
go get -u k8s.io/apimachinery

bash generate-groups.sh all ../../github.com/crd-code-generation/pkg/client ../../github.com/crd-code-generation/pkg/apis aol:v1alpha1

# 上面生成的client目录是空的,退出到上上级目录执行才能成功生成client
bash k8s.io/code-generator/generate-groups.sh client,lister,informer github.com/crd-code-generation/pkg/client github.com/crd-code-generation/pkg/apis aol:v1alpha1

参考文档
https://medium.com/@trstringer/create-kubernetes-controllers-for-core-and-custom-resources-62fc35ad64a3
https://blog.openshift.com/kubernetes-deep-dive-code-generation-customresources/

上一篇下一篇

猜你喜欢

热点阅读