operator 之旅(一) (7)

不过实际生产环境中controller一般都会运行在kubernetes环境内,像上面这种运行在kubernetes之外的方式就不合适了,来试试将其做成docker镜像然后在kubernetes环境运行

将controller制作成docker镜像

执行以下命令构建docker镜像并推送到aliyun,镜像名为

# docker login --username=zisefeizhu registry.cn-shenzhen.aliyuncs.com Password: Login Succeeded # docker build -t registry.cn-shenzhen.aliyuncs.com/zisefeizhu-xm/application:v001 . # docker push registry.cn-shenzhen.aliyuncs.com/zisefeizhu-xm/application:v001 在kubernetes环境部署controller # make deploy IMG=registry.cn-shenzhen.aliyuncs.com/zisefeizhu-xm/application:v001 /Users/zisefeizhu/linkun/goproject/kubedev/bin/controller-gen "crd:trivialVersions=true,preserveUnknownFields=false" rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases cd config/manager && /Users/zisefeizhu/linkun/goproject/kubedev/bin/kustomize edit set image controller=registry.cn-shenzhen.aliyuncs.com/zisefeizhu-xm/application:v001 /Users/zisefeizhu/linkun/goproject/kubedev/bin/kustomize build config/default | kubectl apply -f - namespace/kubedev-system created customresourcedefinition.apiextensions.k8s.io/applications.apps.zise.feizhu configured serviceaccount/kubedev-controller-manager created role.rbac.authorization.k8s.io/kubedev-leader-election-role created clusterrole.rbac.authorization.k8s.io/kubedev-manager-role created clusterrole.rbac.authorization.k8s.io/kubedev-metrics-reader created clusterrole.rbac.authorization.k8s.io/kubedev-proxy-role created rolebinding.rbac.authorization.k8s.io/kubedev-leader-election-rolebinding created clusterrolebinding.rbac.authorization.k8s.io/kubedev-manager-rolebinding created clusterrolebinding.rbac.authorization.k8s.io/kubedev-proxy-rolebinding created configmap/kubedev-manager-config created service/kubedev-controller-manager-metrics-service created deployment.apps/kubedev-controller-manager created # kubectl get pods -n kubedev-system -w NAME READY STATUS RESTARTS AGE kubedev-controller-manager-776899d98c-9xdfg 2/2 Running 0 9s

将kube-rbac-proxy 改为阿里云镜像地址

卸载和清理

把前面创建的资源和CRD全部清理掉,可以执行以下命令

# make uninstall 简单实现 Controller 定义 CR

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/zzzjfw.html