Patch a DeploymentConfig’s Container Image in OpenShift Using the CLI

I’ve been using Kubernetes and OpenShift for the past 2+ years but only recently needed a different way to update the tags on container images found in the deploymentConfig.  Usually I use a json string in the CI/CD pipeline and then apply it that way.  But I also want to use a single-line method as well.  There didn’t seem to be much reference on the Internet to exactly how this should look.

Here’s how I usually do it – which works fine but is a tiny bit verbose.  It does have very nice readability.

oc patch dc some-app -n ns  -p '
        - name: some-app-container
          image: docker-registry.default.svc:5000/ns/some-app-image:test

If there’s more than one container in the config, simply add another “-name: some-other-app” and “image: docker-registry.default.svc:5000/ns/some-other-image:tag”

The below oc command will update the deploymentConfig named some-app to use the image at docker-registry.default.svc:5000/ns/some-app-image with the tag named test.  I use this to simply change the tag that the deploymentConfig uses.  From there, if triggers are appropriately set in the deploymentConfig, it will kick off a new deployment.

oc patch dc some-app -p '{"spec":{"template":{"spec":{"containers":[{"name":"some-app-container","image":"docker-registry.default.svc:5000/ns/some-app-image:test"}]}}}}'

I never use the built-in triggers in OpenShift as I control all that through the CI/CD suite (Bamboo in my case).  So in my case I then perform an oc rollout and use the watch flag so that Bamboo has a copy of the deployment status and is the single source of truth. (example: oc rollout latest dc/some-app –show-all=true –namespace ns && oc rollout status dc/some-app –watch –namespace ns)

Tags: , ,

Leave a Reply

Your email address will not be published. Required fields are marked *