【问题标题】:Deploying helloworld docker images to GKE with Pulumi使用 Pulumi 将 helloworld docker 镜像部署到 GKE
【发布时间】:2021-11-23 12:41:55
【问题描述】:

我正在尝试使用 Pulumi 和 GCP 在 kubernetes 中部署一个 hello world 容器

基本上,我只想将这个本地 helloworld 容器部署在 GCP 上的现有 k8s 集群中,遵循this tutorial。

部署本地镜像是在this other example中完成的,但是我需要添加导致错误的注册表信息:Property 'repositoryUrl' does not exist on type 'Promise<GetRegistryRepositoryResult>'.

const registry = gcp.container.getRegistryRepository();
// Build a Docker image from a local Dockerfile context in the
// './mydockerimg' directory, and push it to the registry.
//const registry = gcp.container.getRegistryRepository();
const customImage = "mydockerimg";
const appImage = new docker.Image(customImage, {
//    imageName: pulumi.interpolate`${registry.repositoryUrl}/${customImage}:v1.0.0`,
    imageName: "mydockerimg",
    build: {
        context: `./${customImage}`,
    },
});
// Create a k8s provider.
// NOT NEEDED
// Create a Deployment of the built container.
const appLabels_helloworld = { app: customImage };
const appDeployment = new k8s.apps.v1.Deployment("app", {
    spec: {
        selector: { matchLabels: appLabels_helloworld },
        replicas: 1,
        template: {
            metadata: { labels: appLabels_helloworld },
            spec: {
                containers: [{
                    name: customImage,
                    image: appImage.imageName,
                    ports: [{name: "http", containerPort: 80}],
                }],
            }
        },
    }
}, { provider: clusterProvider });

当我只使用imageName: "mydockerimg", 而不是注册表时,pulumi 接受升级,但随后出现 docker push 错误:

error: Error: ' docker push mydockerimg:4aff09801cccc271a8182a3eb3bc46a25764fdbb5332230c6aa707e3b90c4d4e' failed with exit code 1
    The push refers to repository [docker.io/library/mydockerimg]

有什么帮助吗?


编辑:在下面应用 Yaron Idan 的建议后,pulumi up 工作正常,但仍无法导出应用程序,无法推送。

const gcrLocation = registry.then(registry => registry.repositoryUrl);
...
imageName: pulumi.interpolate`${gcrLocation}/${customImage}:v1.0.0`,
...
export const appDeploymentName = appDeployment.metadata.apply(m => m.name);

错误:

 Error: ' docker push gcr.io/XXX' failed with exit code 1

经过更多调查,我有 错误:名称未知:Buckets(projectID,artifacts.napoleongamesassignment.appspot.com)

尝试docker push gcr.io/myprojectID/myrstudio:latest后,

创建another question

【问题讨论】:

    标签: typescript docker kubernetes google-cloud-platform pulumi


    【解决方案1】:

    您似乎正在尝试从 Promise 中提取存储库 URL,而不是从它的解析中提取。
    通过 Pulumi 文档中的 example,看起来就像更改您的代码一样

    imageName: pulumi.interpolate`${registry.repositoryUrl}/${customImage}:v1.0.0`,
    

    到

    imageName: pulumi.interpolate`${registry.then(foo => foo.repositoryUrl)}/${customImage}:v1.0.0`,
    

    可能会给你想要的结果。

    【讨论】:

    • 非常感谢。我还是有错误,你能检查一下修改吗?
    猜你喜欢
    • 2020-09-09
    • 2020-05-09
    • 2020-08-19
    • 1970-01-01
    • 2021-02-13
    • 2020-05-26
    • 2018-11-20
    • 1970-01-01
    相关资源
    最近更新 更多