使用 Pulumi 将 helloworld docker 图像部署到 GKE

Deploying helloworld docker images to GKE with Pulumi

我正在尝试使用 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 推送错误:

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

您似乎在尝试从承诺而不是解决方案中提取存储库 URL。
按照 Pulumi 文档中的这个 example,它看起来像是将你的代码从

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

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

可能会给您想要的结果。