<h2><span/><span>將crd部署到k8s</span><span/><span> </span></h2>make install
<p>日志:</p><blockquote><p>kustomize build config/crd | kubectl apply -f -
customresourcedefinition.apiextensions.k8s.io/demoes.tutorial.demo.com created</p></blockquote><p>查看下</p>[root@paas-m-k8s-master-1 demo-operator]# kubectl api-resources | grep demo
demoes tutorial.demo.com true Demo
<p>確實有了,不錯哦呜投。</p><h2><span/><span>編譯運行controller</span><span/><span> </span></h2>make run
<p>保持窗口開啟</p>。。。日志如下
go run ./main.go
I0314 14:37:11.802311 20314 request.go:665] Waited for 1.037997549s due to client-side throttling, not priority and fairness, request: GET:https://apiserver.cluster.local:6443/apis/rbac.istio.io/v1alpha1?timeout=32s
2024-03-14T14:37:13.055+0800 INFO controller-runtime.metrics metrics server is starting to listen {"addr": ":8080"}
2024-03-14T14:37:13.055+0800 INFO setup starting manager
2024-03-14T14:37:13.055+0800 INFO starting metrics server {"path": "/metrics"}
2024-03-14T14:37:13.055+0800 INFO controller.demo Starting EventSource {"reconciler group": "tutorial.demo.com", "reconciler kind": "Demo", "source": "kind source: /, Kind="}
2024-03-14T14:37:13.055+0800 INFO controller.demo Starting Controller {"reconciler group": "tutorial.demo.com", "reconciler kind": "Demo"}
2024-03-14T14:37:13.258+0800 INFO controller.demo Starting workers {"reconciler group": "tutorial.demo.com", "reconciler kind": "Demo", "worker count": 1}
<h2><span/><span>創(chuàng)建一個crd實例</span><span/><span> </span></h2><p>在samples目錄下有一個默認的資源描述文件tutorial_v1_demo.yaml</p><p>我們可以使用進行部署測試</p>apiVersion: tutorial.demo.com/v1
kind: Demo
metadata:
namespace: demo
name: demo-sample
spec:
# TODO(user): Add fields here
image: nginx:1.22
svcName: demo-ng
replicas: 3
<p>現在還沒有我們自定義的demo crd實例,demo nameSpace下也沒有任何pod</p># kubectl -n demo get demo
No resources found in default namespace.
# kubectl -n demo get pod
No resources found in demo namespace.
<p>我們apply一下這個demo crd</p># kubectl apply -f config/samples/tutorial_v1_demo.yaml
<p>查看自定義資源</p># kubectl get demo -n demo
NAME AGE
demo-sample 12s
<h3><span/><span>controller的日志</span><span/></h3><div class="image-package"><img src="https://upload-images.jianshu.io/upload_images/5149787-5a97e0b6e2860ae3.jpeg" img-data="{"format":"jpeg","size":71841,"width":1080,"height":234,"space":"srgb","channels":3,"depth":"uchar","density":72,"chromaSubsampling":"4:2:0","isProgressive":false,"hasProfile":false,"hasAlpha":false}" class="uploaded-img" style="min-height:200px;min-width:200px;" width="auto" height="auto"/>
</div>
<h2><span/><span>查看資源</span><span/><span> </span></h2># kubectl -n demo get pod
NAME READY STATUS RESTARTS AGE
demo-ng-6df8f7c68f-4mg9n 1/1 Running 0 4m33s
demo-ng-6df8f7c68f-699bv 1/1 Running 0 4m33s
demo-ng-6df8f7c68f-n6zkc 1/1 Running 0 4m33s
<p>看到3個pod都創(chuàng)建出來了</p><p>驗證通過patch修改podNum脉顿,來增減pod的數量</p>kubectl -n demo patch demo demo-sample --type merge --patch '{"spec": {"replicas": 5}}'
<div class="image-package"><img src="https://upload-images.jianshu.io/upload_images/5149787-3f443d22d0164200.jpeg" img-data="{"format":"jpeg","size":37250,"width":948,"height":161,"space":"srgb","channels":3,"depth":"uchar","density":72,"chromaSubsampling":"4:2:0","isProgressive":false,"hasProfile":false,"hasAlpha":false}" class="uploaded-img" style="min-height:200px;min-width:200px;" width="auto" height="auto"/>
</div>
<p>自動加到了5個</p><p>減一下</p>kubectl -n demo patch demo demo-sample --type merge --patch '{"spec": {"replicas": 2}}'
<div class="image-package"><img src="https://upload-images.jianshu.io/upload_images/5149787-81252580c0df2d87.jpeg" img-data="{"format":"jpeg","size":13252,"width":561,"height":77,"space":"srgb","channels":3,"depth":"uchar","density":72,"chromaSubsampling":"4:2:0","isProgressive":false,"hasProfile":false,"hasAlpha":false}" class="uploaded-img" style="min-height:200px;min-width:200px;" width="auto" height="auto"/>
</div>
<p>controller中也會看到對應的日志</p><div class="image-package"><img src="https://upload-images.jianshu.io/upload_images/5149787-a317140c355bbc42.jpeg" img-data="{"format":"jpeg","size":39366,"width":808,"height":137,"space":"srgb","channels":3,"depth":"uchar","density":72,"chromaSubsampling":"4:2:0","isProgressive":false,"hasProfile":false,"hasAlpha":false}" class="uploaded-img" style="min-height:200px;min-width:200px;" width="auto" height="auto"/>
</div>
kubebuilder(4)部署&測試
?著作權歸作者所有,轉載或內容合作請聯系作者
- 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來同廉,“玉大人仪糖,你說我怎么就攤上這事∑刃ぃ” “怎么了乓诽?”我有些...
- 正文 為了忘掉前任稠集,我火速辦了婚禮奶段,結果婚禮上,老公的妹妹穿的比我還像新娘剥纷。我一直安慰自己痹籍,他們只是感情好,可當我...
- 文/花漫 我一把揭開白布晦鞋。 她就那樣靜靜地躺著蹲缠,像睡著了一般。 火紅的嫁衣襯著肌膚如雪悠垛。 梳的紋絲不亂的頭發(fā)上线定,一...
- 文/蒼蘭香墨 我猛地睜開眼搀缠,長吁一口氣:“原來是場噩夢啊……” “哼铛楣!你這毒婦竟也來了?” 一聲冷哼從身側響起艺普,我...
- 正文 年R本政府宣布,位于F島的核電站呻拌,受9級特大地震影響葱轩,放射性物質發(fā)生泄漏。R本人自食惡果不足惜,卻給世界環(huán)境...
- 文/蒙蒙 一靴拱、第九天 我趴在偏房一處隱蔽的房頂上張望垃喊。 院中可真熱鬧,春花似錦袜炕、人聲如沸本谜。這莊子的主人今日做“春日...
- 文/蒼蘭香墨 我抬頭看了看天上的太陽乌助。三九已至,卻和暖如春陌知,著一層夾襖步出監(jiān)牢的瞬間他托,已是汗流浹背。 一陣腳步聲響...
推薦閱讀更多精彩內容
- Centos8系統發(fā)布已有一段時間。kubernetes1.22.1也發(fā)布了皇耗,今天使用kubeadm在Centos...
- 本文主要講述如何在k3s上部署Flomesh BookInfo Demo南窗,在k8s上的安裝步驟基本一致,酌情調整即...
- 什么是Tekton? Tekton是一個功能強大且靈活的Kubernetes原生開源框架郎楼,是谷歌開源的万伤,功能強大且...
- CRD GitHub地址:https://github.com/kubernetes-sigs/kubebuild...
- 概述 tidb為分布式的newSQLdb,我們結合operator和k8s 完成tidb的部署和擴容 硬盤使用lo...