I am attempting to deploy a hello world container in Kubernetes using Pulumi and GCP.
Essentially, I want to deploy this local helloworld container into an existing k8s cluster on GCP following the tutorial found here.
Deploying local images is showcased in this other example, but I encounter an error by adding registry information:
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 });
By just using
imageName: "mydockerimg",
without a registry, Pulumi accepts the upgrade, but then I face 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 guidance would be appreciated.
UPDATE: After implementing Yaron Idan's suggestion below, running pulumi up
works, but still cannot export the app due to 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 encountered error:
Error: ' docker push gcr.io/XXX' failed with exit code 1
Further investigation has led me to encounter error: name unknown: Buckets(projectID,artifacts.napoleongamesassignment.appspot.com)
after trying to
docker push gcr.io/myprojectID/myrstudio:latest
,
I have posted another question regarding this issue.