How do I force the Pulumi Kubernetes provider to a...
# general
n
How do I force the Pulumi Kubernetes provider to always run. At the moment, when I push my Node API Project to GitLab, a Docker file is built and push to Docker hub (I do this with some manual code in my CD/CD), however because the Pulumi state says that the Kubernetes Deployment already ran successfully, it does not run again. How can I force it to run even if the Pulumi code has not be changed?
Copy code
├── Dockerfile
├── index.js
├── package.json
├── package-lock.json
├── pulumi
│   ├── index.js
│   ├── nginx
│   ├── node_modules
│   ├── package.json
│   ├── package-lock.json
│   ├── Pulumi.dev.yaml
│   └── Pulumi.yaml
└── scripts
    ├── pulumi-preview.sh
    ├── run-pulumi.sh
    └── setup.sh
The only way I can think to do it is to run a pulumi destroy and then a pulumi up. It's not ideal as another app could have been deployed in the same namespace by someone else or another pulumi program. I suppose it just means that you have to have lots of different Pululmi Programs for each specific bit of state. In this case I would have to either created the Namespace manually or have a pulumi programme specifically for the namespace, which seems massive overkill.
l
There's probably some way to get the Docker image as a resource and have your K8s resource depend on it.
Maybe docker.RegistryImage.get() is what you need?
I've not used it though, so ymmv
n
Hi @little-cartoon-10569, thank you, let me take a look at that
@little-cartoon-10569 Thanks for the pointer, it got me over the line. Here is the code that worked in the end. I just had to set a new pod label with the sha256Digest of the Image.
Copy code
const image = docker.getRegistryImage({
  name: `simoncarr/sandpit-api:${pulumi.getStack()}`,
})


const deployment = new k8s.apps.v1.Deployment("sandpit-api", {
  metadata: { name: "sandpit-api", namespace: "sandpit"},
  spec: {
    selector: { matchLabels: { app: "sandpit-api" } },
    replicas: 2,
    template: {
      metadata: { labels: 
        { 
          app: "sandpit-api",
          imgid: image.then(image => image.sha256Digest.split(":")[1].substring(0,12))
        } 
      },
      spec: {
        containers: [{
          name: "sandpit-api",
          image: `simoncarr/sandpit-api:${pulumi.getStack()}`,
          imagePullPolicy: "Always",
          ports: [{ containerPort: 3000 }],
          resources: { requests: { cpu: "100m", memory: "100Mi" } }
        }]
      }
    }
  }
}, {
  dependsOn: [namespace]
})
s
Yeah, @little-cartoon-10569 is correct and you’re on the right approach---Pulumi needs to know the Docker image changed in order to know the Deployment needs to be updated.