kubebuilder的使用
1. kubebuilder
1.1. 安装kubebuilder
# download kubebuilder and install locally.
curl -L -o kubebuilder https://go.kubebuilder.io/dl/latest/$(go env GOOS)/$(go env GOARCH)
chmod +x kubebuilder && mv kubebuilder /usr/local/bin/1.2. kubebuilder命令
Development kit for building Kubernetes extensions and tools.
Provides libraries and tools to create new projects, APIs and controllers.
Includes tools for packaging artifacts into an installer container.
Typical project lifecycle:
- initialize a project:
kubebuilder init --domain example.com --license apache2 --owner "The Kubernetes authors"
- create one or more a new resource APIs and add your code to them:
kubebuilder create api --group <group> --version <version> --kind <Kind>
Create resource will prompt the user for if it should scaffold the Resource and / or Controller. To only
scaffold a Controller for an existing Resource, select "n" for Resource. To only define
the schema for a Resource without writing a Controller, select "n" for Controller.
After the scaffold is written, api will run make on the project.
Usage:
kubebuilder [command]
Available Commands:
create Scaffold a Kubernetes API or webhook.
edit This command will edit the project configuration
help Help about any command
init Initialize a new project
version Print the kubebuilder version
Flags:
-h, --help help for kubebuilder
Use "kubebuilder [command] --help" for more information about a command.2. 操作步骤
2.1. 初始化
2.2. 创建项目
查看生成文件:
2.3. 创建API
查看创建文件
查看api/v1/guestbook_types.go
3. troubleshooting
3.1. controller-gen: No such file or directory
由于本地存在多个GOPATH的目录,而获取了非当前项目下的GOPATH目录,因此将当前项目所在的GOPATH目录export到GOPATH环境变量中,就可以解决。
参考:
https://kubernetes.io/zh/docs/concepts/extend-kubernetes/operator/
https://github.com/kubernetes-sigs/kubebuilder
https://book.kubebuilder.io/quick-start.html
https://operatorhub.io/
https://devops.college/developing-kubernetes-operator-is-now-easy-with-operator-framework-d3194a7428ff
最后更新于
这有帮助吗?