sparse-intern-71089
08/26/2021, 6:19 PMsteep-toddler-94095
08/26/2021, 6:24 PMbillowy-vr-96461
08/26/2021, 7:44 PMbillowy-vr-96461
08/26/2021, 7:46 PMconst pulumi = require('@pulumi/pulumi')
const docker = require('@pulumi/docker')
const k8s = require('@pulumi/kubernetes')
const stack = pulumi.getStack()
const env = stack.split('-').slice(-1)[0]
const backend = new pulumi.StackReference(`backend-cluster-${env}`)
const registry = backend.getOutput('registry')
const imageName = pulumi.interpolate`${registry.server}/foobar:latest`
const image = new docker.Image(imageName, {
imageName,
build: {
context: '../../',
dockerfile: '../Dockerfile',
extraOptions: ['--no-cache'],
},
registry: {
server: registry.server,
username: registry.username,
password: registry.password,
},
})
const kubeconfig = backend.getOutput('kubeconfig')
const coreProvider = new k8s.Provider('provider', { kubeconfig })
// eslint-disable-next-line no-unused-vars
const depl = new k8s.apps.v1.Deployment('foobar', {
metadata: { name: 'foobar' },
spec: {
replicas: 3,
selector: { matchLabels: { app: 'foobar' } },
template: {
metadata: {
labels: {
app: 'foobar',
},
annotations: {
'<http://dapr.io/enabled|dapr.io/enabled>': 'true',
'<http://dapr.io/app-id|dapr.io/app-id>': 'foobar',
'<http://dapr.io/app-port|dapr.io/app-port>': '3000',
'<http://dapr.io/config|dapr.io/config>': 'tracing',
},
},
spec: {
terminationGracePeriodSeconds: 30,
hostname: 'foobar',
securityContext: { fsGroup: 10001 },
containers: [
{
name: 'foobar',
image: imageName,
imagePullPolicy: 'Always',
ports: [
{ containerPort: 3000 }],
env: [
{
name: 'MSSQL_USER',
value: 'appportal',
},
],
}],
},
},
},
}, { provider: coreProvider, parent: image })
// eslint-disable-next-line no-unused-vars
const svc = new k8s.core.v1.Service('foobar-svc', {
metadata: { name: 'foobar' },
spec: {
selector: { app: 'foobar' },
ports: [
{
protocol: 'TCP',
port: 30001,
targetPort: 3000,
}],
type: 'LoadBalancer',
},
}, { provider: coreProvider, dependsOn: [depl] })
steep-toddler-94095
08/26/2021, 7:50 PMlatest
so kubernetes doesn't see a change in the deployment spec.
//in the deployment:
image: image.imageName
steep-toddler-94095
08/26/2021, 8:04 PMlatest-<uniquestring>
.
side note: if you want to reference the tag you explicitly set, you'd do: image`.imageName.apply((_) => image.baseImageName)`billowy-vr-96461
08/26/2021, 8:21 PMbillowy-vr-96461
08/26/2021, 8:21 PMbillowy-vr-96461
08/26/2021, 8:21 PMbillowy-vr-96461
08/26/2021, 8:26 PMbillowy-vr-96461
08/26/2021, 8:27 PMbillowy-vr-96461
08/26/2021, 8:27 PMsteep-toddler-94095
08/27/2021, 1:19 AMimage.imageName
property in your deployment, so it won't update the deployment until the image is built and pushed. For some reason this doesn't happen with baseImageName
which is why I gave that other example above if you wanted to use that in the future