美文网首页
创建k8s自定义资源的controller

创建k8s自定义资源的controller

作者: 怀旧的艾克 | 来源:发表于2019-10-22 12:15 被阅读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/

    相关文章

      网友评论

          本文标题:创建k8s自定义资源的controller

          本文链接:https://www.haomeiwen.com/subject/nlfqvctx.html