Home > Mobile >  Deploying helloworld docker images to GKE with Pulumi
Deploying helloworld docker images to GKE with Pulumi

Time:10-04

I'm trying to deploy a hello world container in kubernetes using Pulumi and GCP

Basically I just want this local helloworld container to be deployed in an existing k8s cluster on GCP made following this tutorial.

Deploying local images is what is done in this other example, however I need to add registry information which causes an error: 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 });

When I just use imageName: "mydockerimg", rather than a registry, pulumi accepts the upgrade, but then I have a docker push error:

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

Any help?


EDIT: After applying Yaron Idan's suggestion below, pulumi up is working, but still not exporting the app, being unable to push.

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

The error:

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

After some more investigation I have error: name unknown: Buckets(projectID,artifacts.napoleongamesassignment.appspot.com)

after trying to docker push gcr.io/myprojectID/myrstudio:latest,

created another question

CodePudding user response:

It looks like you're trying to extract the repository URL from the promise instead of it's resolution.
Going by this example from the Pulumi docs, it looks like changing your code from

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

to

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

Might give you the results you're looking for.

  • Related