前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >kubernetes学习记录(15)——使用operator-sdk开发operator

kubernetes学习记录(15)——使用operator-sdk开发operator

作者头像
胡了了
发布2020-02-18 09:36:56
3.4K0
发布2020-02-18 09:36:56
举报
文章被收录于专栏:从零学习云计算

operator-sdk环境搭建

我的电脑环境为windows,安装operator-sdk需要自己编译构建二进制文件。 参考官方文档Compile and install from master 官方给的Prerequisites为:

  • git
  • mercurial version 3.9+
  • bazaar version 2.7.0+
  • go version v1.13+.

其中mercurial和bazaar我都没装,operator-sdk也编译安装成功了。

代码语言:javascript
复制
$ go get -d github.com/operator-framework/operator-sdk # This will download the git repository and not install it
$ cd $GOPATH/src/github.com/operator-framework/operator-sdk
$ git checkout master
$ make tidy
$ make install
  • 测试是否完成安装
代码语言:javascript
复制
$ operator-sdk version
operator-sdk version: "v0.15.0-33-ga1a9cbba", commit: "a1a9cbba09cb05914704c3229bc6df3f86269a56", go version: "go1.13.7 windows/amd64"

使用operator-sdk

仍然参考官方文档

代码语言:javascript
复制
$ cd $GOPATH/src/
$ export GO111MODULE=on && export GOPROXY=https://goproxy.io 
$ operator-sdk new operator-demo
time="2020-02-11T16:39:13+08:00" level=info msg="Creating new Go operator 'operator-demo'."
time="2020-02-11T16:39:13+08:00" level=info msg="Created go.mod"
time="2020-02-11T16:39:13+08:00" level=info msg="Created tools.go"
time="2020-02-11T16:39:13+08:00" level=info msg="Created cmd\\manager\\main.go"
time="2020-02-11T16:39:13+08:00" level=info msg="Created build\\Dockerfile"
time="2020-02-11T16:39:13+08:00" level=info msg="Created build\\bin\\entrypoint"
time="2020-02-11T16:39:13+08:00" level=info msg="Created build\\bin\\user_setup"
time="2020-02-11T16:39:13+08:00" level=info msg="Created deploy\\service_account.yaml"
time="2020-02-11T16:39:13+08:00" level=info msg="Created deploy\\role.yaml"
time="2020-02-11T16:39:13+08:00" level=info msg="Created deploy\\role_binding.yaml"
time="2020-02-11T16:39:13+08:00" level=info msg="Created deploy\\operator.yaml"
time="2020-02-11T16:39:13+08:00" level=info msg="Created pkg\\apis\\apis.go"
time="2020-02-11T16:39:13+08:00" level=info msg="Created pkg\\controller\\controller.go"
time="2020-02-11T16:39:13+08:00" level=info msg="Created version\\version.go"
time="2020-02-11T16:39:13+08:00" level=info msg="Created .gitignore"
time="2020-02-11T16:39:13+08:00" level=info msg="Validating project"
go: finding github.com/operator-framework/operator-sdk master
go: downloading github.com/operator-framework/operator-sdk v0.15.1-0.20200210173459-a1a9cbba09cb
go: extracting github.com/operator-framework/operator-sdk v0.15.1-0.20200210173459-a1a9cbba09cb
$ cd operator-demo/
$ operator-sdk add api --api-version=app.example.com/v1alpha1 --kind=AppService
time="2020-02-11T16:43:47+08:00" level=info msg="Generating api version app.example.com/v1alpha1 for kind AppService."
time="2020-02-11T16:43:47+08:00" level=info msg="Created pkg\\apis\\app\\group.go"
time="2020-02-11T16:44:13+08:00" level=info msg="Created pkg\\apis\\app\\v1alpha1\\appservice_types.go"
time="2020-02-11T16:44:14+08:00" level=info msg="Created pkg\\apis\\addtoscheme_app_v1alpha1.go"
time="2020-02-11T16:44:14+08:00" level=info msg="Created pkg\\apis\\app\\v1alpha1\\register.go"
time="2020-02-11T16:44:14+08:00" level=info msg="Created pkg\\apis\\app\\v1alpha1\\doc.go"
time="2020-02-11T16:44:14+08:00" level=info msg="Created deploy\\crds\\app.example.com_v1alpha1_appservice_cr.yaml"
time="2020-02-11T16:44:14+08:00" level=info msg="Running deepcopy code-generation for Custom Resource group versions: [app:[v1alpha1], ]\n"
time="2020-02-11T16:44:50+08:00" level=info msg="Code-generation complete."
time="2020-02-11T16:44:50+08:00" level=info msg="Running CRD generator."
time="2020-02-11T16:44:55+08:00" level=info msg="CRD generation complete."
time="2020-02-11T16:44:55+08:00" level=info msg="API generation complete."
$ operator-sdk add controller --api-version=app.example.com/v1alpha1 --kind=AppService
time="2020-02-11T16:46:02+08:00" level=info msg="Generating controller version app.example.com/v1alpha1 for kind AppService."
time="2020-02-11T16:46:02+08:00" level=info msg="Created pkg\\controller\\appservice\\appservice_controller.go"
time="2020-02-11T16:46:02+08:00" level=info msg="Created pkg\\controller\\add_appservice.go"
time="2020-02-11T16:46:02+08:00" level=info msg="Controller generation complete."

到此,operator的demo工程就建好了,并且可以打包构建镜像推到k8s里直接使用。

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • operator-sdk环境搭建
  • 使用operator-sdk
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档