kubebuilder实战之六:构建部署运行 (4)

最终,命令执行成功后输出如下:

zhaoqin@zhaoqindeMBP-2 elasticweb % make docker-build docker-push IMG=bolingcavalry/elasticweb:002 /Users/zhaoqin/go/bin/controller-gen object:headerFile="hack/boilerplate.go.txt" paths="./..." go fmt ./... go vet ./... /Users/zhaoqin/go/bin/controller-gen "crd:trivialVersions=true" rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases go test ./... -coverprofile cover.out ? elasticweb [no test files] ? elasticweb/api/v1 [no test files] ok elasticweb/controllers 8.287s coverage: 0.0% of statements docker build . -t bolingcavalry/elasticweb:002 [+] Building 146.8s (17/17) FINISHED => [internal] load build definition from Dockerfile 0.1s => => transferring dockerfile: 37B 0.0s => [internal] load .dockerignore 0.0s => => transferring context: 2B 0.0s => [internal] load metadata for gcr.io/distroless/static:nonroot 1.8s => [internal] load metadata for docker.io/library/golang:1.13 0.7s => [builder 1/9] FROM docker.io/library/golang:1.13@sha256:8ebb6d5a48deef738381b56b1d4cd33d99a5d608e0d03c5fe8dfa3f68d41a1f8 0.0s => [stage-1 1/3] FROM gcr.io/distroless/static:nonroot@sha256:b89b98ea1f5bc6e0b48c8be6803a155b2a3532ac6f1e9508a8bcbf99885a9152 0.0s => [internal] load build context 0.0s => => transferring context: 14.51kB 0.0s => CACHED [builder 2/9] WORKDIR /workspace 0.0s => CACHED [builder 3/9] COPY go.mod go.mod 0.0s => CACHED [builder 4/9] COPY go.sum go.sum 0.0s => CACHED [builder 5/9] RUN go mod download 0.0s => CACHED [builder 6/9] COPY main.go main.go 0.0s => CACHED [builder 7/9] COPY api/ api/ 0.0s => [builder 8/9] COPY controllers/ controllers/ 0.1s => [builder 9/9] RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -a -o manager main.go 144.5s => CACHED [stage-1 2/3] COPY --from=builder /workspace/manager . 0.0s => exporting to image 0.0s => => exporting layers 0.0s => => writing image sha256:622d30aa44c77d93db4093b005fce86b39d5ba5c6cd29f1fb2accb7e7f9b23b8 0.0s => => naming to docker.io/bolingcavalry/elasticweb:002 0.0s docker push bolingcavalry/elasticweb:002 The push refers to repository [docker.io/bolingcavalry/elasticweb] eea77d209b68: Layer already exists 8651333b21e7: Layer already exists 002: digest: sha256:c09ab87f6fce3d85f1fda0ffe75ead9db302a47729aefd3ef07967f2b99273c5 size: 739

去hub.docker.com网站看看,如下图,新镜像已经上传,这样只要任何机器只要能上网就能pull此镜像到本地使用了:

在这里插入图片描述

镜像准备好之后,执行以下命令即可在kubernetes环境部署controller:

make deploy IMG=bolingcavalry/elasticweb:002

接下来像之前那样创建elasticweb资源对象,验证所有资源是否创建成功:

zhaoqin@zhaoqindeMBP-2 elasticweb % make deploy IMG=bolingcavalry/elasticweb:002 /Users/zhaoqin/go/bin/controller-gen "crd:trivialVersions=true" rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases cd config/manager && kustomize edit set image controller=bolingcavalry/elasticweb:002 kustomize build config/default | kubectl apply -f - namespace/elasticweb-system created Warning: apiextensions.k8s.io/v1beta1 CustomResourceDefinition is deprecated in v1.16+, unavailable in v1.22+; use apiextensions.k8s.io/v1 CustomResourceDefinition customresourcedefinition.apiextensions.k8s.io/elasticwebs.elasticweb.com.bolingcavalry configured role.rbac.authorization.k8s.io/elasticweb-leader-election-role created clusterrole.rbac.authorization.k8s.io/elasticweb-manager-role created clusterrole.rbac.authorization.k8s.io/elasticweb-proxy-role created Warning: rbac.authorization.k8s.io/v1beta1 ClusterRole is deprecated in v1.17+, unavailable in v1.22+; use rbac.authorization.k8s.io/v1 ClusterRole clusterrole.rbac.authorization.k8s.io/elasticweb-metrics-reader created rolebinding.rbac.authorization.k8s.io/elasticweb-leader-election-rolebinding created clusterrolebinding.rbac.authorization.k8s.io/elasticweb-manager-rolebinding created clusterrolebinding.rbac.authorization.k8s.io/elasticweb-proxy-rolebinding created service/elasticweb-controller-manager-metrics-service created deployment.apps/elasticweb-controller-manager created zhaoqin@zhaoqindeMBP-2 elasticweb % zhaoqin@zhaoqindeMBP-2 elasticweb % zhaoqin@zhaoqindeMBP-2 elasticweb % zhaoqin@zhaoqindeMBP-2 elasticweb % zhaoqin@zhaoqindeMBP-2 elasticweb % kubectl apply -f config/samples/elasticweb_v1_elasticweb.yaml namespace/dev created elasticweb.elasticweb.com.bolingcavalry/elasticweb-sample created zhaoqin@zhaoqindeMBP-2 elasticweb % kubectl get service -n dev NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE elasticweb-sample NodePort 10.96.234.7 <none> 8080:30003/TCP 13s zhaoqin@zhaoqindeMBP-2 elasticweb % kubectl get deployment -n dev NAME READY UP-TO-DATE AVAILABLE AGE elasticweb-sample 2/2 2 2 18s zhaoqin@zhaoqindeMBP-2 elasticweb % kubectl get pod -n dev NAME READY STATUS RESTARTS AGE elasticweb-sample-56fc5848b7-559lw 1/1 Running 0 22s elasticweb-sample-56fc5848b7-hp4wv 1/1 Running 0 22s

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

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