当前位置:网站首页>Operator-1 first acquaintance with operator
Operator-1 first acquaintance with operator
2022-07-01 12:48:00 【51CTO】
background :
Contact kubernetes For many years , I heard all kinds of things at the beginning Operator Of , But I have never learned more about it Operator
. Start experiencing simple Operator
Operator First experience
What is? Operator?
reference : Red hat official documents What is? Kubernetes Operator?
**coreos2016 In introducing ,** It's a package 、 Deployment and management Kubernetes Applied method
- crd webhook controller
development tool :
what is crd
**CRD ** The full name is Custom Resource Definition, CRD It is an extension of native without coding kubenetes API How to interface . Suitable for expansion kubernetes Custom interfaces and functions of . If you want to add logic more flexibly, you need API Aggregation The way .
Start to prepare
There are several common development tools :
My development tools Include goland kubebuilder kustomize,kubernetes1.23.6, The work environment rocky linux 8.5 go 1.17
Be careful : Be sure to have a look go edition The version corresponding to the development tool , As well as kubernetes Version of
kubebuilder kustomize install
https://github.com/kubernetes-sigs/kubebuilder/releases



Create and initialize project
goland Create a kube-oprator1 Project :

The terminal executes a command :

It seems to remind me go Version is too low ?(go edition 1.17.6 My is )
Upgrade go edition
Be careful : Not necessary , The latter is lowered kubebuilder Version of .go Keep the version 1.17 Version of the ,
Browser open https://golang.google.cn/dl/ go The download page , choice 1.17 Download the latest version and replace the local GO edition !
.... It seems that the report is wrong , Took a closer look https://github.com/kubernetes-sigs/kubebuilder/releases I'd better change it kubebuilder Version …
kubebuilder edition 3.4.1

The structure of the generated directory is as follows :
Focus on config/default/ kustomization.yaml file :
Now you can understand the configuration , Namespace ! I will not change the default configuration here !

The directory structure is as follows 
Be careful : About domain group version kind Corresponding :

Simply create one crd
api/v1/redis_type.go

Show me how to delete Foo Field , Add one Port Field , Set up port Field is int type !
With test Under the table of contents yaml File customization crd
test/redis.yaml
make install establish crd

About reconcile
controllers/redis_controller.go
About reconcile Just don't ask for a better understanding 

Local debugging make run
As soon as the terminal is running
terminal 2 function
Observation terminal 1 The output is as follows :
Preliminary release to kubernetes colony
notes : My environment has installed podman, About podman To baidu , The mirror warehouse uses Tencent cloud image warehouse Personal Edition
About Podman
First modify docker The build command is podman!
podman login Remember the password … Basic heel docker You can use it in the same way
dockerhub Speed up
In particular dockerhub Speed up
The acceleration address is added at the end of the file !
restart podman service
Build publishing image
Dockerfile Add... To the file GOPROXY

Incidentally, I found that one of Tencent cloud's personal warehouses is not displayed OCI-Image The size of bug…

notes : The process is tortuous . In the middle, there is science that doesn't move under the mirror on the Internet , Autonomic brain . Such as “gcr.io/distroless/static:nonroot Mirror my operating environment as rocky linux 8.5 When I couldn't download it, I went online directly …
How to publish :
make Failed again, finally according to Makefile in deploy Manually execute the following commands :
Be careful : Both commands are in kube-oprator1 Executed under the project root directory !

The default namespace is not modified kube-oprator1-system namespace Under the namespace pod state !
Theoretically pod The deployment was not successful , Here's why :gcr.io/kubebuilder/kube-rbac-proxy:v0.11.0 Unable to download … I use benzene method ,rocky Development machine science downloads images online and uploads them to Tencent and image warehouse , then pull Mirror to kuberntes machine work node . Yes, of course work Node i only have one test environment, which is OK ~
wait for pod running
CRD Custom resource simple validation
With test/redis.yaml For example
reference https://book.kubebuilder.io/reference/markers/crd-validation.html Just set it up port The scope of the !

make install Still failed ! Or manual command
notes : I made mistakes in this place several times , The reason is that I thought make install =kustomize build config/crd | kubectl apply -f -, Took a closer look Makefile:
contain manifests Steps for , I tried it, and it worked !


The output is as follows : The port is less than 1024 Cannot create successfully 
modify test/redis.yaml port: 1024

webhook A simple test
Simple access controller webhook create

kube-oprator1 api/v1 Added... To the directory webhook Related documents of , Made a simple verification ** name=zhangpeng**
Certificate management cert-manager:
visit https://github.com/cert-manager/cert-manager/releases The download page ,1.19.0 yes alpha edition I used it 1.18.2 Version of !


Be careful : Mirror images still need to be downloaded scientifically
Modify file
config/default/kustomization.yaml The down arrow callout section unlocks the annotation 

**config/manager/manager.yaml **
Delete crd
make uninstall Yes, but mine make Always fail … Delete... Directly !

Packaging image publishing
Packaging and publishing images , In fact, it is better to modify an image label tag, Here is a demonstration That's it first !make install I don't know there is a problem Direct copy Makefile The order in ! Build an image and publish it !




EN, modified to zhangpeng1
Created successfully ? to glance at make run,but make run Can't run ?
The local debug mode is commented out main.go SetupWebhookWithManager


summary :
1. Pay attention to the version matching between development tools
2.make Look at it when you fail Makefile You can manually run the relevant commands in
3. Resource cleanup , Local debugging mode
4. Next, we are going to design a simple Operator?
边栏推荐
- 使用nvm管理nodejs(把高版本降级为低版本)
- logstash报错:Cannot reload pipeline, because the existing pipeline is not reloadable
- 腾讯安全联合毕马威发布监管科技白皮书,解析“3+3”热点应用场景
- 运行Powershell脚本提示“因为在此系统上禁止运行脚本”解决办法
- [Maui] add click events for label, image and other controls
- 类的初始化与实例化
- leetcode:241. Design priority for operation expression [DFS + Eval]
- Exploration and practice of inress in kubernetes
- 王兴的无限游戏迎来“终极”一战
- 软件测试中功能测试流程
猜你喜欢
![[today in history] July 1: the father of time sharing system was born; Alipay launched barcode payment; The first TV advertisement in the world](/img/41/76687ea13e1722654b235f2cfa66ce.png)
[today in history] July 1: the father of time sharing system was born; Alipay launched barcode payment; The first TV advertisement in the world

项目部署,一点也不难!

A hole in solder paste

我花上万学带货:3天赚3元,成交靠刷单

Vs code setting Click to open a new file window without overwriting the previous window

使用nvm管理nodejs(把高版本降级为低版本)

Operator-1初识Operator

logstash报错:Cannot reload pipeline, because the existing pipeline is not reloadable
![leetcode:241. Design priority for operation expression [DFS + Eval]](/img/d0/8dedeba7ecedccd25e0e3e96ff3362.png)
leetcode:241. Design priority for operation expression [DFS + Eval]

The popular major I chose became "Tiankeng" four years later
随机推荐
请问flink mysql cdc 全量读取mysql某个表数据,对原始的mysql数据库有影响吗
flinkcdc要实时抽取oracle,对oracle要配置什么东西?
Understanding of NAND flash deblocking
ROS2 Foxy depthai_ros教程
The difference between memcpy and strcpy
买卖其实也有风险
VS Code 设置单击打开新文件窗口,不覆盖前一个窗口
R语言使用yardstick包的conf_mat函数计算多分类(Multiclass)模型在每个交叉验证(或者重采样)的每一折fold上的混淆矩阵、并使用summary输出每个fold的其它详细指标
用.Net Core接入微信公众号开发
79. 单词搜索【dfs + 回溯visit + 遍历起点】
leetcode:329. The longest incremental path in the matrix [DFS + cache + no backtracking + elegance]
手机便签应用
Simple Fibonacci (recursive)
数据库之MHA高可用集群部署及故障切换
QT 播放器之列表[通俗易懂]
【开发大杀器】之Idea
First intention is the most important
Like the three foot platform
Logstash error: cannot reload pipeline, because the existing pipeline is not reloadable
The popular major I chose became "Tiankeng" four years later