該項目是 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 瞭解細節。