https://pulumi.com logo
#kubernetes
Title
# kubernetes
g

glamorous-island-48142

07/18/2023, 7:19 AM
Hello, I had a Pulumi script for rolling a bunch of K8s resources for an app. App is stateful so I use a deployment and a PVC to persist the volume. I'm in a situation that I have to update the Deployment resource, change its containers, mountPaths of volumes and spec.selector fields. With server-side apply enabled on my k8s provider, and
replaceOnChanges: ['*'], deleteBeforeReplace: true
, I can't replace the deployment, the update goes crazy and deletes everything. How can I troubleshoot this?
b

bitter-father-26598

07/18/2023, 11:09 AM
Isn’t that doing exactly what replaceOnChange and deleteBeforeReplace has asked it to do? Honestly I never did understand why anyone would set those to true for stateful assets.
Best bet is to disable those settings so statefuls persist, then migrate state to newly created asset. For the stateless stuff, it should be easy to blow away and recreate anytime so long as your customers hit you through static domain names.
g

glamorous-island-48142

07/18/2023, 3:06 PM
@bitter-father-26598 thanks for the answers, you are right. My PVC was configured to not to be replaced unless the size is changed, but the flags were there for deployment. So I expected the PVC to persist and deployment to be replaced. I'm currently renovating a script that uses automation API, in the old version there were lots of classes extended from ComponentResource, each having type names. Say below is the new version:
Copy code
TYPE                                            NAME
companyname:productType:product                 instance-name
  kubernetes:core/v1:Namespace                  instance-name
  companyname:productType:product:disk          instance-name
    kubernetes:core/v1:PersistentVolumeClaim.   instance-name
  companyname:productType:product:deployment.   instance-name
    kubernetes:core/v1:Deployment               instance-name
And new version is like:
Copy code
TYPE                                            NAME
companyname:product                             instance-name
  kubernetes:core/v1:Namespace                  instance-name
  kubernetes:core/v1:PersistentVolumeClaim.     instance-name
  kubernetes:core/v1:Deployment                 instance-name
So what happens is Pulumi first creates the resources needed on new version (things mostly already exists on the cluster) and deletes the resources from old version, causing resources that already exist to get deleted. Is there a way to rename the types and shuffle the tree by keeping at least PVC the same?