首页 > 解决方案 > Ballerina:构建镜像并通过 k8s 插件推送到 gcr.io

问题描述

我正在使用一个简单的ballerina代码来构建我的带有ballerinax/kubernetes注释的程序(简单的 hello world)。该服务正在成功编译,并可通过本地主机的特定绑定端口访问。

在配置 kubernetes 部署时,我指定了映像构建和推送标志:

@kubernetes:Deployment {
    replicas: 2,
    name: "hello-deployment",
    image: "gcr.io/<gct-project-name>/hello-ballerina:0.0.2",
    imagePullPolicy: "always",
    buildImage: true,
    push: true
}

构建源代码时:

ballerina build hello.bal

这就是我得到的:

Compiling source
    hello.bal

Generating executable
    ./target/hello.balx
    @docker          - complete 3/3

    Run following command to start docker container:
    docker run -d -p 9090:9090 gcr.io/<gcr-project-name>/hello-ballerina:0.0.2

    @kubernetes:Service              - complete 1/1
    @kubernetes:Deployment           - complete 1/1
error [k8s plugin]: Unable to push docker image: unauthorized: You don't have the needed permissions to perform this operation, and you may have invalid credentials. To authenticate your request, follow the steps in: https://cloud.google.com/container-registry/docs/advanced-authentication

请注意,当在我的本地机器上通过 docker 手动推送它时,它可以找到并且新图像正在被推送。

我错过了什么?有没有办法通过kubernetes包告诉芭蕾舞演员有关 docker 注册表凭据的信息?

标签: dockerkubernetesballerina

解决方案


Ballerina 还不支持 gcloud docker registry,但它支持 dockerhub。有关更多信息,请参阅示例 6 。

基本上,您可以将 docker 注册表用户名和密码导出为环境变量。

请在https://github.com/ballerinax/kubernetes/issues创建一个问题以跟踪此问题。


推荐阅读