Is it possible to bind a new Deployment to an existing ReplicaSet?

6/10/2020

I have some older ReplicaSets that were manually created by me, so they are not bound to/managed by a Deployment.

Is it possible to create the Deployments now, in a way that no new ReplicaSets will be created and the Deployments will automatically pair with the existing Replicasets and Pods?

I know I could delete the existing ReplicaSets, but I'm trying to find another way. I tried to give the new Deployment the same selector and matchLables as the existing ReplicaSet, but that didn't work and the Deployment created a new ReplicaSet and Pod.

Thanks!

-- Daniel
azure-aks
kubernetes
kubernetes-pod

3 Answers

6/10/2020

The Deployment resource specification does not expose any fields for specifying the initial ReplicaSet. So, the logic of creating a new ReplicaSet seems to be hardcoded in the Deployment controller.

So, the answer is, you can't do it. If you really wanted to have a Deployment where you can specify the ReplicaSet, you could create a Custom Resource Definition (CRD) and operator.

-- weibeld
Source: StackOverflow

6/10/2020

ReplicaSets are not long lived so there is kind of no point. Just switch things over and kill the old ones.

-- coderanger
Source: StackOverflow

6/10/2020

I think its because of pod-template-hash added to the labels when kubernetes does deployment so it won't match with labels of ReplicaSet

enter image description here

you can check labels added to deployment, I am sure labels wont be same as existing ReplicaSets

-- Amit Naik
Source: StackOverflow