sparse-intern-71089
02/17/2022, 4:17 PMwonderful-portugal-96162
02/17/2022, 4:17 PMpulumi up (doing it manually). I have this sample code that deploys a Deployment with one replica.
pulumi up --stack dev -y --refresh=true does what's expected.
$ k get pods
NAME READY STATUS RESTARTS AGE
nginx-fsbqexby-6799fc88d8-ch2b8 1/1 Running 0 42m
I delete the deployment and run pulumi up --stack dev -y --refresh=true again and it creates the deployment as expected
$ k get pods
NAME READY STATUS RESTARTS AGE
nginx-w88w29hu-6799fc88d8-w4bvr 0/1 ContainerCreating 0 0s
Cool, let me scale the deployment (my cluster now has drift)
$ k scale deployment nginx-w88w29hu --replicas=3
deployment.apps/nginx-w88w29hu scaled
$ k get pods
NAME READY STATUS RESTARTS AGE
nginx-w88w29hu-6799fc88d8-fdhkh 0/1 ContainerCreating 0 2s
nginx-w88w29hu-6799fc88d8-kq4pp 1/1 Running 0 2s
nginx-w88w29hu-6799fc88d8-w4bvr 1/1 Running 0 63s
Running pulumi up --stack dev -y --refresh=true again, doesn't do anything. It gives me Resources: 3 unchanged and the 3 replicas are still there.
$ k get pods
NAME READY STATUS RESTARTS AGE
nginx-w88w29hu-6799fc88d8-fdhkh 1/1 Running 0 90s
nginx-w88w29hu-6799fc88d8-kq4pp 1/1 Running 0 90s
nginx-w88w29hu-6799fc88d8-w4bvr 1/1 Running 0 2m31s
My expectation, is that pulumi up would detect the drift and correct it for me.wonderful-portugal-96162
02/17/2022, 4:19 PMmain.go file with appDeploymentReplicas := 2 ... running pulumi up --stack dev -y --refresh=true actually DOES correct the drift
$ k get pods
NAME READY STATUS RESTARTS AGE
nginx-w88w29hu-6799fc88d8-kq4pp 1/1 Running 0 4m31s
nginx-w88w29hu-6799fc88d8-w4bvr 1/1 Running 0 5m32swonderful-portugal-96162
02/17/2022, 4:19 PMprehistoric-activity-61023
02/17/2022, 4:36 PMprehistoric-activity-61023
02/17/2022, 4:37 PMprehistoric-activity-61023
02/17/2022, 4:38 PMexpected state (source code)
• state (stored in Pulumi Service or custom backends)
• current state (actual state of your infrastructure)prehistoric-activity-61023
02/17/2022, 4:38 PMpulumi up = compare expected state with state and perform actions to sync them
pulumi refresh = compare state with current state and allow to overwrite state in case of differencesprehistoric-activity-61023
02/17/2022, 4:41 PMpulumi refresh can detect that deployment was removed but it doesn’t update replicaCount (so if the deployment is scaled, it doesn’t see any changes) - let me try to repro thisbusy-journalist-6936
02/17/2022, 4:44 PMwonderful-portugal-96162
02/17/2022, 4:45 PMpulumiprehistoric-activity-61023
02/17/2022, 4:46 PMprehistoric-activity-61023
02/17/2022, 4:48 PMpulumi new kubernetes-python
• pulumi up -> it created a new deployment with one replica
• I changed the source code (increased number of replicas to 2)
• pulumi up -> it scaled the deployment
• I manually descreased the number of replicas via: k scale deploy nginx-biohg2sj --replicas=1
• pulumi up -> nothing to do here (expected)
• pulumi refresh -> it properly detects that the actual state differs from what it thinks it should be 🤔prehistoric-activity-61023
02/17/2022, 4:49 PMType Name Plan Info
pulumi:pulumi:Stack pulumi_playground-dev
~ └─ kubernetes:apps/v1:Deployment nginx update [diff: ~metadata,spec,status]prehistoric-activity-61023
02/17/2022, 4:49 PM...
~ spec : {
progressDeadlineSeconds: 600
~ replicas : 2 => 1
...prehistoric-activity-61023
02/17/2022, 4:50 PMrefresh action and do pulumi up , it’s gonna correct the drift.prehistoric-activity-61023
02/17/2022, 4:50 PMprehistoric-activity-61023
02/17/2022, 4:51 PMprehistoric-activity-61023
02/17/2022, 4:56 PMwonderful-portugal-96162
02/17/2022, 4:59 PMprehistoric-activity-61023
02/17/2022, 5:00 PMprehistoric-activity-61023
02/17/2022, 5:00 PMprehistoric-activity-61023
02/17/2022, 5:02 PMpulumi up with additional env var?
PULUMI_K8S_ENABLE_DRY_RUN=true pulumi upwonderful-portugal-96162
02/17/2022, 5:10 PMprehistoric-activity-61023
02/17/2022, 5:12 PMprehistoric-activity-61023
02/17/2022, 5:14 PMkubectly apply, via kubectl edit, via kubectl patch).wonderful-portugal-96162
02/17/2022, 5:16 PMprehistoric-activity-61023
02/17/2022, 5:16 PMPULUMI_K8S_ENABLE_DRY_RUN enables so called server-side diff and that’s why it can detect changes introduced locally (at least some of them?). AFAIK before that, a “magic annotation” <http://kubectl.kubernetes.io/last-applied-configuration|kubectl.kubernetes.io/last-applied-configuration> was used and that’s why some changes remain undetected (because they didn’t update this annotation).wonderful-portugal-96162
02/17/2022, 5:17 PMPULUMI_K8S_ENABLE_DRY_RUN on the Pulumi Kubrentes Operator?prehistoric-activity-61023
02/17/2022, 5:17 PMprehistoric-activity-61023
02/17/2022, 5:18 PMbusy-journalist-6936
02/17/2022, 5:18 PMbusy-journalist-6936
02/17/2022, 5:18 PMenableDryRunbusy-journalist-6936
02/17/2022, 5:19 PMBETA FEATURE - If present and set to true, enable server-side diff calculationswonderful-portugal-96162
02/17/2022, 5:20 PMpulumi config set kubernetes:enableDryRunbusy-journalist-6936
02/17/2022, 5:23 PMpulumi config set \
--stack dev kubernetes:enableDryRun truebusy-journalist-6936
02/17/2022, 5:29 PMwonderful-portugal-96162
02/17/2022, 5:52 PM