Search code examples
deploymentkubernetesreplicaset

Is it possible to move the running pods from ReplicationController to a Deployment?


We are using RC to run our workload and want to migrate to Deployment. Is there a way to do that with out causing any impact to the running workload. I mean, can we move these running pods under Deployment?


Solution

  • Like, @matthew-l-daniel answered, the answer is yes. But I am more than 80% certain about it. Because I have tested it

    Now whats the process we need to follow

    Lets say I have a ReplicationController.

    apiVersion: v1
    kind: ReplicationController
    metadata:
      name: nginx
    spec:
      replicas: 3
      selector:
        app: nginx
      template:
        metadata:
          name: nginx
          labels:
            app: nginx
        spec:
          containers:
          - name: nginx
            image: nginx
            ports:
            - containerPort: 80
    

    Question: can we move these running pods under Deployment?

    Lets follow these step to see if we can.

    Step 1: Delete this RC with --cascade=false. This will leave Pods.

    Step 2: Create ReplicaSet first, with same label as ReplicationController

    apiVersion: apps/v1beta2
    kind: ReplicaSet
    metadata:
      name: nginx
      labels:
        app: nginx
    spec:
      replicas: 3
      selector:
        matchLabels:
          app: nginx
      template:
        metadata:
          labels:
            app: nginx
        spec:
          ---
    

    So, now these Pods are under ReplicaSet.

    Step 3: Create Deployment Now with same label.

    apiVersion: apps/v1beta2
    kind: Deployment
    metadata:
      name: nginx
      labels:
        app: nginx
    spec:
      replicas: 3
      selector:
        matchLabels:
          app: nginx
      template:
        metadata:
          labels:
            app: nginx
        spec:
          ----
    

    And Deployment will find one ReplicaSet already exists and our job is done.

    Now we can check increasing replicas to see if it works.

    And It works.

    Which way It doesn't work

    After deleting ReplicationController, do not create Deployment directly. This will not work. Because, Deployment will find no ReplicaSet, and will create new one with additional label which will not match with your existing Pods