Is there an easy way to create a Kubernetes deployment from a replicaset?

9/25/2018

So I already have a replicaset up and running and I want to add a deployment that'll manage that replicaset. I expect to go through this process repeatedly, so a programmatic solution is desired.

Right now my best solution is to run

JSON=kubectl get replicasets myreplicaset -o json
IMAGE=...
REPLICAS=...
LABELS=...
kubectl run --image=$IMAGE --replicas=$REPLICAS --labels=$LABELS

where ... is json-chopping code.

I'm worried about the reliability of this code. Perhaps I am forgetting important parameters in the replicaset. I definitely want to avoid accidentally altering the replicaset (or having the deployment scale it down and launch a new one). Is there a simpler way to achieve the same effect?

-- Sebastian Oberhoff
kubectl
kubernetes

1 Answer

9/25/2018

You can try it with this command:

sed 's/ReplicaSet/Deployment/g' /tmp/replicaset.yaml | sed -n '/status:/q;p'> Deployment.yaml

it worked for me. but i would always recommend to apply deployments in the first place and not replicasets.

-- Louis Baumann
Source: StackOverflow