本文主要是介绍kubebuilder(5)制作镜像部署,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
制作镜像
好了,前面是使用make run进行测试运行。现在我们把operator打出镜像进行分发。
先修改一下Dockerfile,否则可能下载依赖有问题
ENV GO111MODULE=onENV GOPROXY=https://goproxy.cn,direct
然后,默认的这个FROM gcr.io/distroless/static:nonroot也是下不到的
替换成这个
anjia0532/distroless.static:nonroot我这里是自己搭的私有harbor
make docker-build docker-push IMG=harbor-test.xxx.net/paas/demo-operator:1.0部署operator镜像
部署有两种方案
make deploy
使用项目自带的deploy指令,这种方式是将operator部署到本地集群中,其实和make run差不多
make deploy IMG=harbor-test.xxx.net/paas/demo-operator:1.0也可修改~/.kube/config来连接其他集群,但还是太麻烦。
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
查看部署情况
查看一下pod的日志
我们再部署一个demo测试一下
kubectl apply -f config/samples/tutorial_v1_demo.yaml执行调谐完成
如果你的部署遇到问题,可能会遇到镜像下载不下来的问题。
原因还是gcr.io/kubebuilder/kube-rbac-proxy被墙了
改一下
yaml部署
我们需要的当然是把写的operator分发到别的集群部署。
通过分析make deploy脚本,来编写yaml
.PHONY: deploydeploy: manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
$(KUSTOMIZE) build config/default | kubectl apply -f -
这个脚本的本质就是用kustomize对config下的manager和default中的yaml进行变量替换
然后整合成一个yaml,传给kubectl apply执行
所以啊,我们只要执行下这两行就可以得到我们想要的yaml文件,然后就可以随便到别的集群执行了哦
cd config/manager && /usr/local/bin/kustomize edit set image controller=harbor-test.xxx.net/paas/demo-operator:1.0cd ../.. && /usr/local/bin/kustomize build config/default > demo-operator.yaml
输出这样一个yaml
apiVersion: v1kind: Namespace
metadata:
labels:
control-plane: controller-manager
name: demo-operator-system
---
太长了,不贴了
去别的集群,部署试试
部署operator
kubectl apply -f demo-operator.yaml部署一个demo crd
kubectl apply -f demo-simple.yaml完成
这篇关于kubebuilder(5)制作镜像部署的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!