mirror of
https://github.com/Estom/notes.git
synced 2026-04-05 03:48:56 +08:00
operator
This commit is contained in:
@@ -6,7 +6,13 @@ Operator 是由 CoreOS 开发的,用来扩展 Kubernetes API,特定的应用
|
||||
|
||||
Operator 直接使用 Kubernetes API进行开发,也就是说他们可以根据这些控制器内部编写的自定义规则来监控集群、更改 Pods/Services、对正在运行的应用进行扩缩容。
|
||||
|
||||
Operator pattern首先由 CoreOS 提出,通过结合 CRD 和 custom controller 将特定应用的运维知识转换为代码,实现应用运维的自动化和智能化。Operator 允许 kubernetes 来管理复杂的,有状态的分布式应用程序,并由 kubernetes 对其进行自动化管理,例如,etcd operator 能够创建并管理一组 etcd 集群, 定制化的 controller 组件了解这些资源,知道如何维护这些特定的应用。
|
||||
|
||||
通过 CRD,kubernetes 可以动态的添加并管理资源。CRD 解决了结构化数据存储的问题,Controller 则用来跟踪这些资源, 保证资源的状态满足期望值。
|
||||
|
||||
CRD+Controller=decalartive API,声明式 API 设计是 kubernetes 重要的设计思想, 该设计保证能够动态扩展 kubernetes API,这种模式也正是 Operator pattern。Operator一般也分为两种类型:
|
||||
* 通用的Operator,由各大云厂商开发,为了满足统一的云需求。
|
||||
* 专用型Operator,解决一个特定应用的自动化管理。
|
||||
|
||||
### 开发框架
|
||||
|
||||
@@ -26,71 +32,4 @@ Operator Framework 同样也是 CoreOS 开源的一个用于快速开发 Operato
|
||||
4. 定义 Operator 的协调(reconcile)逻辑
|
||||
5. 使用 Operator SDK 构建并生成 Operator 部署清单文件
|
||||
|
||||
## 使用实例
|
||||
|
||||
### 搭建go开发环境
|
||||
|
||||
1. 下载
|
||||
|
||||
```
|
||||
brew install go
|
||||
```
|
||||
2. 配置环境变量
|
||||
|
||||
```
|
||||
GOPATH=
|
||||
GOROOT=
|
||||
GOPROXY=
|
||||
```
|
||||
|
||||
3. 安装operator-sdk工具
|
||||
|
||||
```
|
||||
brew install operator-sdk
|
||||
```
|
||||
|
||||
### 创建项目
|
||||
|
||||
|
||||
```
|
||||
$ operator-sdk new opdemo
|
||||
......
|
||||
# 该过程需要科学上网,需要花费很长时间,请耐心等待
|
||||
......
|
||||
$ cd opdemo && tree -L 2
|
||||
.
|
||||
├── Gopkg.lock
|
||||
├── Gopkg.toml
|
||||
├── build
|
||||
│ ├── Dockerfile
|
||||
│ ├── _output
|
||||
│ └── bin
|
||||
├── cmd
|
||||
│ └── manager
|
||||
├── deploy
|
||||
│ ├── crds
|
||||
│ ├── operator.yaml
|
||||
│ ├── role.yaml
|
||||
│ ├── role_binding.yaml
|
||||
│ └── service_account.yaml
|
||||
├── pkg
|
||||
│ ├── apis
|
||||
│ └── controller
|
||||
├── vendor
|
||||
│ ├── cloud.google.com
|
||||
│ ├── contrib.go.opencensus.io
|
||||
│ ├── github.com
|
||||
│ ├── go.opencensus.io
|
||||
│ ├── go.uber.org
|
||||
│ ├── golang.org
|
||||
│ ├── google.golang.org
|
||||
│ ├── gopkg.in
|
||||
│ ├── k8s.io
|
||||
│ └── sigs.k8s.io
|
||||
└── version
|
||||
└── version.go
|
||||
|
||||
23 directories, 8 files
|
||||
```
|
||||
|
||||
|
||||
区有两个成熟的脚手架工具用于简化开发,一个是有 kube-sig 维护的 kubebuilder, 另一个是由 redhat 维护的 operator-sdk,这两个工具都是基于 controller-runtime 项目而实现,用户可自行选择,笔者用的是 kubebuilder。
|
||||
|
||||
68
kubenets/operator/02 Operator-sdk.md
Normal file
68
kubenets/operator/02 Operator-sdk.md
Normal file
@@ -0,0 +1,68 @@
|
||||
## 使用实例
|
||||
|
||||
### 搭建go开发环境
|
||||
|
||||
1. 下载
|
||||
|
||||
```
|
||||
brew install go
|
||||
```
|
||||
2. 配置环境变量
|
||||
|
||||
```
|
||||
GOPATH=
|
||||
GOROOT=
|
||||
GOPROXY=
|
||||
```
|
||||
|
||||
3. 安装operator-sdk工具
|
||||
|
||||
```
|
||||
brew install operator-sdk
|
||||
```
|
||||
|
||||
### 创建项目
|
||||
|
||||
|
||||
```
|
||||
$ operator-sdk new opdemo
|
||||
......
|
||||
# 该过程需要科学上网,需要花费很长时间,请耐心等待
|
||||
......
|
||||
$ cd opdemo && tree -L 2
|
||||
.
|
||||
├── Gopkg.lock
|
||||
├── Gopkg.toml
|
||||
├── build
|
||||
│ ├── Dockerfile
|
||||
│ ├── _output
|
||||
│ └── bin
|
||||
├── cmd
|
||||
│ └── manager
|
||||
├── deploy
|
||||
│ ├── crds
|
||||
│ ├── operator.yaml
|
||||
│ ├── role.yaml
|
||||
│ ├── role_binding.yaml
|
||||
│ └── service_account.yaml
|
||||
├── pkg
|
||||
│ ├── apis
|
||||
│ └── controller
|
||||
├── vendor
|
||||
│ ├── cloud.google.com
|
||||
│ ├── contrib.go.opencensus.io
|
||||
│ ├── github.com
|
||||
│ ├── go.opencensus.io
|
||||
│ ├── go.uber.org
|
||||
│ ├── golang.org
|
||||
│ ├── google.golang.org
|
||||
│ ├── gopkg.in
|
||||
│ ├── k8s.io
|
||||
│ └── sigs.k8s.io
|
||||
└── version
|
||||
└── version.go
|
||||
|
||||
23 directories, 8 files
|
||||
```
|
||||
|
||||
|
||||
13
kubenets/operator/03 Kubebuilder.md
Normal file
13
kubenets/operator/03 Kubebuilder.md
Normal file
@@ -0,0 +1,13 @@
|
||||
|
||||
## 1 概述
|
||||
|
||||
### 构建阶段
|
||||
|
||||

|
||||
|
||||
|
||||
### 工作流程
|
||||
|
||||

|
||||
## 2 执行流程
|
||||
|
||||
BIN
kubenets/operator/image/2023-08-15-22-02-45.png
Normal file
BIN
kubenets/operator/image/2023-08-15-22-02-45.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 210 KiB |
BIN
kubenets/operator/image/2023-08-15-22-05-58.png
Normal file
BIN
kubenets/operator/image/2023-08-15-22-05-58.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 146 KiB |
Reference in New Issue
Block a user