<h2><span/><span>制作镜像</span><span/><span> </span></h2><p>好了,前面是使用make run进行测试运行。现在我们把operator打出镜像进行分发。</p><p>先修改一下Dockerfile,否则可能下载依赖有问题</p>ENV GO111MODULE=on
ENV GOPROXY=https://goproxy.cn,direct
<p>然后,默认的这个FROM gcr.io/distroless/static:nonroot也是下不到的</p><p>替换成这个</p>anjia0532/distroless.static:nonroot
<div class="image-package"><img src="https://upload-images.jianshu.io/upload_images/5149787-9872b0b3f4a3d742.jpeg" img-data="{"format":"jpeg","size":72339,"width":838,"height":815,"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>我这里是自己搭的私有harbor</p>make docker-build docker-push IMG=harbor-test.xxx.net/paas/demo-operator:1.0
<div class="image-package"><img src="https://upload-images.jianshu.io/upload_images/5149787-03a5ef88ccb67d29.jpeg" img-data="{"format":"jpeg","size":54193,"width":827,"height":364,"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>部署operator镜像</span><span/><span> </span></h2><p>部署有两种方案</p><h3><span/><span>make deploy</span><span/></h3><p>使用项目自带的deploy指令,这种方式是将operator部署到本地集群中,其实和make run差不多</p>make deploy IMG=harbor-test.xxx.net/paas/demo-operator:1.0
<p>也可修改~/.kube/config来连接其他集群,但还是太麻烦。</p>kustomize build config/default | kubectl apply -f -
namespace/demo-operator-system created
customresourcedefinition.apiextensions.k8s.io/demoes.tutorial.demo.com unchanged
serviceaccount/demo-operator-controller-manager created
role.rbac.authorization.k8s.io/demo-operator-leader-election-role created
clusterrole.rbac.authorization.k8s.io/demo-operator-manager-role created
clusterrole.rbac.authorization.k8s.io/demo-operator-metrics-reader created
clusterrole.rbac.authorization.k8s.io/demo-operator-proxy-role created
rolebinding.rbac.authorization.k8s.io/demo-operator-leader-election-rolebinding created
clusterrolebinding.rbac.authorization.k8s.io/demo-operator-manager-rolebinding created
clusterrolebinding.rbac.authorization.k8s.io/demo-operator-proxy-rolebinding created
configmap/demo-operator-manager-config created
service/demo-operator-controller-manager-metrics-service created
deployment.apps/demo-operator-controller-manager created
<p>查看部署情况</p><div class="image-package"><img src="https://upload-images.jianshu.io/upload_images/5149787-cc197699b41ce8dd.jpeg" img-data="{"format":"jpeg","size":39063,"width":1080,"height":231,"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>查看一下pod的日志</p><div class="image-package"><img src="https://upload-images.jianshu.io/upload_images/5149787-656db5495ff6177d.jpeg" img-data="{"format":"jpeg","size":61872,"width":1080,"height":227,"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>我们再部署一个demo测试一下</p>kubectl apply -f config/samples/tutorial_v1_demo.yaml
<div class="image-package"><img src="https://upload-images.jianshu.io/upload_images/5149787-b381c98e888c4242.jpeg" img-data="{"format":"jpeg","size":59986,"width":1080,"height":250,"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>执行调谐完成</p><p>如果你的部署遇到问题,可能会遇到镜像下载不下来的问题。</p><p>原因还是gcr.io/kubebuilder/kube-rbac-proxy被墙了</p><p>改一下</p><div class="image-package"><img src="https://upload-images.jianshu.io/upload_images/5149787-124d1cf804a99991.jpeg" img-data="{"format":"jpeg","size":29632,"width":1080,"height":261,"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><h3><span/><span>yaml部署</span><span/></h3><p>我们需要的当然是把写的operator分发到别的集群部署。</p><p>通过分析make deploy脚本,来编写yaml</p>.PHONY: deploy
deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.
cd config/manager && {IMG}
$(KUSTOMIZE) build config/default | kubectl apply -f -
<p>这个脚本的本质就是用kustomize对config下的manager和default中的yaml进行变量替换</p><p>然后整合成一个yaml,传给kubectl apply执行</p><p>所以啊,我们只要执行下这两行就可以得到我们想要的yaml文件,然后就可以随便到别的集群执行了哦</p>cd config/manager && /usr/local/bin/kustomize edit set image controller=harbor-test.xxx.net/paas/demo-operator:1.0
cd ../.. && /usr/local/bin/kustomize build config/default > demo-operator.yaml
<p>输出这样一个yaml</p>apiVersion: v1
kind: Namespace
metadata:
labels:
control-plane: controller-manager
name: demo-operator-system
---
太长了,不贴了
<p>去别的集群,部署试试</p><p>部署operator</p>kubectl apply -f demo-operator.yaml
<p>部署一个demo crd</p>kubectl apply -f demo-simple.yaml
<div class="image-package"><img src="https://upload-images.jianshu.io/upload_images/5149787-1802de5b18bc939f.jpeg" img-data="{"format":"jpeg","size":22000,"width":690,"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><p>完成</p><p>
</p>
kubebuilder(5)制作镜像&部署
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 本文主要讲述如何在k3s上部署Flomesh BookInfo Demo,在k8s上的安装步骤基本一致,酌情调整即...
- 虚拟机: VMware ESXi 操作系统:CentOS Linux release 7.5 # 固定静态IP [...
- JaegerJaeger是Uber推出的一款调用链追踪系统,类似于Zipkin和Dapper,为微服务调用追踪而生...