日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Kubernetes CRD开发工具Operator-SDK简介

發(fā)布時間:2025/3/21 编程问答 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Kubernetes CRD开发工具Operator-SDK简介 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

原文連接:https://blog.csdn.net/weixin_33918114/article/details/92211707

概覽

  • 原文來自:https://github.com/operator-framework/operator-sdk

該項目是 Operator Framework的組成部分, 是一個開源的工具用于管理 Kubernetes 原生的應(yīng)用, 稱為 Operators, 以一種更為有效、自動化、可伸縮的方式。更多信息參考 introduction blog post。

Operators 使在Kubernetes中管理復(fù)雜的有狀態(tài)的應(yīng)用更為簡單。但是,目前編寫 operator 還是比較困難,因為需要與底層的APIs打交道,編寫模版和模塊化資源缺乏也導(dǎo)致重復(fù)的工作。

該 Operator SDK 是一個框架,使用 controller-runtime 庫來使得編寫 operators 更為容易,提供了:

  • 高階APIs 和抽象,使編寫運(yùn)維邏輯更為直觀。
  • Tools和啟動模塊,使創(chuàng)建新的工程時更快。
  • 覆蓋常用的operator的擴(kuò)展。

工作流

該 SDK 提供了一個工作流程,用于使用 Go、 Ansible 或 Helm來開發(fā)operators。

下面的工作流用于創(chuàng)建新的 Go operator:

  • 創(chuàng)建新的 operator project,使用 SDK Command Line Interface(CLI)。
  • 定義新的resource APIs,通過添加Custom Resource Definitions(CRD)。
  • 定義 Controllers 觀察和協(xié)調(diào)資源。
  • 編寫協(xié)調(diào)邏輯,使用 SDK 和 controller-runtime APIs。
  • 使用 SDK CLI 構(gòu)建和生成 operator deployment manifests。
  • 下面的工作流用于創(chuàng)建新的Ansible operator:

  • 創(chuàng)建新的 operator project,使用SDK Command Line Interface(CLI)。
  • 編寫協(xié)調(diào)邏輯,為自己的對象,使用ansible playbooks 和 roles。
  • 使用 SDK CLI 構(gòu)建和生成 operator deployment manifests。
  • 可選添加額外的 CRD's,使用 SDK CLI,重復(fù)步驟2、3。
  • 下面的工作流用于創(chuàng)建新的Helm operator:

  • 創(chuàng)建新的 operator project,使用 SDK Command Line Interface(CLI)。
  • 創(chuàng)建新的? (或添加已有的) Helm chart,用于 operator's 協(xié)調(diào)邏輯使用。
  • 使用SDK CLI 構(gòu)建和生成operator deployment manifests。
  • 可選添加額外的CRD's,使用SDK CLI,重復(fù)步驟 2 和 3。
  • 預(yù)先要求

    • dep version v0.5.0+.
    • git
    • go version v1.10+.
    • docker version 17.03+.
    • kubectl version v1.11.0+.
    • Access to a kubernetes v.1.11.0+ cluster.

    快速開始

    首先, 檢出和安裝 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

    創(chuàng)建和部署一個 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

    命令行界面-CLI

    了解更多 SDK CLI, 查看 SDK CLI Reference, 或者運(yùn)行 operator-sdk [command] -h。

    使用指南

    了解更多使用 Go 語言編寫 operator的方法,查看 user guide。

    該 SDK 同時支持使用 Ansible 和 Helm開發(fā) operator。查看 Ansible 和 Helm 的operator 用戶指南。

    例子

    探索operator-sdk的例子,查看 operator-sdk-samples。

    貢獻(xiàn)

    查看 CONTRIBUTING 了解提交布丁和貢獻(xiàn)的方法和流程。

    查看 proposal docs 提交需求和規(guī)劃。

    報告 bugs

    查看 reporting bugs 報告Bugs。

    許可

    Operator SDK的許可為 Apache 2.0 license. 查看許可文件 LICENSE 了解細(xì)節(jié)。

    總結(jié)

    以上是生活随笔為你收集整理的Kubernetes CRD开发工具Operator-SDK简介的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。