Skip to content

Instantly share code, notes, and snippets.

@bmaupin
Last active October 8, 2024 19:38
Show Gist options
  • Save bmaupin/d5be3ca882345ff92e8336698230dae0 to your computer and use it in GitHub Desktop.
Save bmaupin/d5be3ca882345ff92e8336698230dae0 to your computer and use it in GitHub Desktop.
Convert OpenShift DeploymentConfig to Kubernetes Deployment
  1. Change apiVersion from:

    - apiVersion: v1

    (or apiVersion: apps.openshift.io/v1)

    to:

    - apiVersion: apps/v1
  2. Change kind from:

      kind: DeploymentConfig

    to:

      kind: Deployment
  3. Change spec.selectors from:

        selector:
          name: ...

    to:

        selector:
          matchLabels:
            name: ...
  4. Make sure spec.template.spec.containers.image is set, e.g.

            image: registry.access.redhat.com/rhscl/postgresql-${POSTGRESQL_VERSION}-rhel7
            imagePullPolicy: Always
    
  5. Remove spec.triggers section entirely

@kvaps
Copy link

kvaps commented Jan 25, 2022

Hehe, I got parsed template using oc process --local, then replaced DeploymentConfig to Deployment with jq:

jq '.items = [(.items[] | select(.kind == "DeploymentConfig") | .apiVersion="apps/v1" | .kind = "Deployment" | .spec.selector.matchLabels=.spec.template.metadata.labels | .spec.template.spec.containers[0].image=(.spec.triggers[] | select(.type=="ImageChange").imageChangeParams.from.name) | del(.spec.triggers) | del(.spec.strategy) | del(.spec.template.name)), (.items[] | select(.kind != "DeploymentConfig"))]'

@SimonGolms
Copy link

I also had to remove spec.strategy and spec.test section entirely

@bomboclat
Copy link

If could be useful I wrote down a little script to automate the conversion https://gist.github.com/bomboclat/1c53b7e692b1df58af67598337cc2b88

@lsloan
Copy link

lsloan commented Jul 15, 2024

Similar to what @kvaps wrote, I thought the DeploymentConfig to Deployment conversion could be done with yq, if working with YAML.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment