Skip to content

Instantly share code, notes, and snippets.

@bmaupin
Last active November 29, 2023 08:24
  • Star 23 You must be signed in to star a gist
  • Fork 11 You must be signed in to fork a gist
Star You must be signed in to star a gist
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

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