该项目是 Operator Framework的组成部分, 是一个开源的工具用于管理 Kubernetes 原生的应用, 称为 Operators, 以一种更为有效、自动化、可伸缩的方式。更多信息参考 introduction blog post。html
Operators 使在Kubernetes中管理复杂的有状态的应用更为简单。可是,目前编写 operator 仍是比较困难,由于须要与底层的APIs打交道,编写模版和模块化资源缺少也致使重复的工做。git
该 Operator SDK 是一个框架,使用 controller-runtime 库来使得编写 operators 更为容易,提供了:github
该 SDK 提供了一个工做流程,用于使用 Go、 Ansible 或 Helm来开发operators。golang
下面的工做流用于建立新的 Go operator:docker
下面的工做流用于建立新的Ansible operator:api
下面的工做流用于建立新的Helm operator:app
首先, 检出和安装 operator-sdk CLI,以下:框架
$ mkdir -p $GOPATH/src/github.com/operator-framework $ cd $GOPATH/src/github.com/operator-framework $ git clone https://github.com/operator-framework/operator-sdk $ cd operator-sdk $ git checkout master $ make dep $ make install
建立和部署一个 app-operator,使用SDK CLI来完成,以下:运维
# Create an app-operator project that defines the App CR. $ mkdir -p $GOPATH/src/github.com/example-inc/ # Create a new app-operator project $ cd $GOPATH/src/github.com/example-inc/ $ operator-sdk new app-operator $ cd app-operator # Add a new API for the custom resource AppService $ operator-sdk add api --api-version=app.example.com/v1alpha1 --kind=AppService # Add a new controller that watches for AppService $ operator-sdk add controller --api-version=app.example.com/v1alpha1 --kind=AppService # Build and push the app-operator image to a public registry such as quay.io $ operator-sdk build quay.io/example/app-operator $ docker push quay.io/example/app-operator # 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|quay.io/example/app-operator|g' deploy/operator.yaml # On OSX use: $ sed -i "" 's|REPLACE_IMAGE|quay.io/example/app-operator|g' deploy/operator.yaml # 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/app_v1alpha1_appservice_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/app_v1alpha1_appservice_cr.yaml # Verify that a pod is created $ kubectl get pod -l app=example-appservice NAME READY STATUS RESTARTS AGE example-appservice-pod 1/1 Running 0 1m # Test the new Resource Type $ kubectl describe appservice example-appservice Name: example-appservice Namespace: myproject Labels: <none> Annotations: <none> API Version: app.example.com/v1alpha1 Kind: AppService Metadata: Cluster Name: Creation Timestamp: 2018-12-17T21:18:43Z Generation: 1 Resource Version: 248412 Self Link: /apis/app.example.com/v1alpha1/namespaces/myproject/appservices/example-appservice UID: 554f301f-0241-11e9-b551-080027c7d133 Spec: Size: 3 # Cleanup $ kubectl delete -f deploy/crds/app_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/app_v1alpha1_appservice_crd.yaml
了解更多 SDK CLI, 查看 SDK CLI Reference, 或者运行 operator-sdk [command] -h
。ide
了解更多使用 Go 语言编写 operator的方法,查看 user guide。
该 SDK 同时支持使用 Ansible 和 Helm开发 operator。查看 Ansible 和 Helm 的operator 用户指南。
探索operator-sdk的例子,查看 operator-sdk-samples。
查看 CONTRIBUTING 了解提交布丁和贡献的方法和流程。
查看 proposal docs 提交需求和规划。
查看 reporting bugs 报告Bugs。
Operator SDK的许可为 Apache 2.0 license. 查看许可文件 LICENSE 了解细节。