700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > operator framework搭建operator开发环境

operator framework搭建operator开发环境

时间:2020-10-11 13:26:08

相关推荐

operator framework搭建operator开发环境

简介

operator framework 是一个为云原生开发者提供开发operator的组件框架的开源项目,它目前包含三个组件:

Operator SDK。集成controller-runtime,提供了:编写运维逻辑的高阶API,快速构建Operator项目及代码生成的脚手架工具,覆盖常见Operator用例的扩展。Operator SDK是Operator Framework中最核心的工程。

Operator Lifecycle Manager:K8S集群内所有Operator(及其关联服务)的生命周期管理( installation, updates, and management )

Operator Metering(joining in the coming months):提供对operator本身的监控以提供一些定制化服务。

搭建开发环境主要用到operator SDK,下面主要介绍其安装和使用。

operator SDK 安装

Mac OS

brew install operator-sdk

其他方式

参见官方安装指南

operator SDK搭建开发环境

以官方的app-operator为例:

# 创建项目目录mkdir -p $GOPATH/test/operator/cd $GOPATH/test/operator/# GO111MODULE=on 模块支持,go 会忽略 GOPATH 和 vendor 文件夹,只根据 go.mod 下载依赖。export GO111MODULE=on# 创建operator项目operator-sdk new app-operator --repo /example-inc/app-operatorcd app-operator# 拓展kubernetes apioperator-sdk add api --api-version=/v1alpha1 --kind=AppService# 构建对应的controller基础代码operator-sdk add controller --api-version=/v1alpha1 --kind=AppService# 可在对应的API文件中定义自己的需要的属性以及在对应的controller文件中构建自己的代码逻辑,完成之后按后续步骤构建镜像# 构建镜像并推送到自己的镜像仓库operator-sdk build kingdragon/app-operator:v1docker push kingdragon/app-operator:v1# 下为官方更改yaml文件里的镜像的shell命令# 不熟悉shell命令,熟悉kubernetes yaml语法可自行到对应文件更改相关配置亦可# Update the operator manifest to use the built image name (if you are performing these steps on OSX, see note below)$ sed -i 's|REPLACE_IMAGE|kingdragon/app-operator:v1|g' deploy/operator.yaml# On OSX use:$ sed -i "" 's|REPLACE_IMAGE|kingdragon/app-operator:v1|g' deploy/operator.yaml# 下为部署,根据自己的kubernetes集群环境自行部署。# Setup Service Account$ kubectl create -f deploy/service_account.yaml# Setup RBAC$ kubectl create -f deploy/role.yaml$ kubectl create -f deploy/role_binding.yaml# Setup the CRD$ kubectl create -f deploy/crds/_appservices_crd.yaml# Deploy the app-operator$ kubectl create -f deploy/operator.yaml# Create an AppService CR# The default controller will watch for AppService objects and create a pod for each CR$ kubectl create -f deploy/crds/_v1alpha1_appservice_cr.yaml# Verify that a pod is created$ kubectl get pod -l app=example-appserviceNAME READYSTATUS RESTARTS AGEexample-appservice-pod 1/1 Running 01m# Test the new Resource Type$ kubectl describe appservice example-appserviceName: example-appserviceNamespace: myprojectLabels: <none>Annotations: <none>API Version: /v1alpha1Kind: AppServiceMetadata:Cluster Name: Creation Timestamp: -12-17T21:18:43ZGeneration:1Resource Version: 248412Self Link: /apis//v1alpha1/namespaces/myproject/appservices/example-appserviceUID: 554f301f-0241-11e9-b551-080027c7d133Spec:Size: 3# Cleanup$ kubectl delete -f deploy/crds/_v1alpha1_appservice_cr.yaml$ kubectl delete -f deploy/operator.yaml$ kubectl delete -f deploy/role.yaml$ kubectl delete -f deploy/role_binding.yaml$ kubectl delete -f deploy/service_account.yaml$ kubectl delete -f deploy/crds/_appservices_crd.yaml

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。