当前位置:网站首页>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?
边栏推荐
- Four years after graduation: work, resign, get married, buy a house
- 我选的热门专业,四年后成了“天坑”
- Has anyone ever encountered this situation? When Oracle logminer is synchronized, the value of CLOB field is lost
- Scene function of wooden frame
- ustime写出了bug
- Exploration and practice of inress in kubernetes
- 晓看天色暮看云,美图欣赏
- localtime居然不可重入,踩坑了
- Chapter 14 signals (IV) - examples of multi process tasks
- 2022-06-28-06-29
猜你喜欢
随机推荐
Quickly understand what the compressed list in redis is
Exploration and practice of inress in kubernetes
79. Word search [DFS + backtracking visit + traversal starting point]
数据库之MHA高可用集群部署及故障切换
网络socket的状态要怎么统计?
Topic 2612: the real topic of the 12th provincial competition of the Blue Bridge Cup in 2021 - the least weight (enumerating and finding rules + recursion)
快速整明白Redis中的压缩列表到底是个啥
localtime居然不可重入,踩坑了
flinkcdc要实时抽取oracle,对oracle要配置什么东西?
6.30模拟赛总结
Powerful, easy-to-use, professional editor / notebook software suitable for programmers / software developers, comprehensive evaluation and comprehensive recommendation
I spent tens of thousands of dollars to learn and bring goods: I earned 3 yuan in three days, and the transaction depends on the bill
Operations related to sequence table
Tencent always takes epoll, which is annoying
下半年还有很多事要做
codeforces -- 4B. Before an Exam
题目 1004: 母牛的故事(递推)
请问flink mysql cdc 全量读取mysql某个表数据,对原始的mysql数据库有影响吗
Chain storage of binary tree
Huawei interview question: Recruitment