0

I have in openshift a deployment-config that will poll changes in the image stream & starts a new deployment whenever a new image is available. I have a requirement where I need to restart/redeploy same tag from the imagestream. I can achieve this by the deploy tab in the deployments section of the project in the openshift web console. Was checking for the cli version of the same. I am new to openshift & I couldn't find it out. I checked out the oc rollout option but it basically deploys the latest tag, but I need the existing tag itself to be redeployed.

user2700022
  • 489
  • 3
  • 19
  • Try changing the value of an annotation on the deployment config. See https://cookbook.openshift.org/application-lifecycle-management/how-can-i-trigger-a-new-deployment-of-an-application.html – Graham Dumpleton Dec 26 '18 at 20:36

2 Answers2

1

Actually, you had the right answer from the start. The correct way to do this is oc rollout latest dc/dcname. This is equivalent to hitting the 'deploy' button in the UI. You don't need to modify the deployment to 'trick' it into redeploying.

When it says 'latest', it means the latest version of your deploy config, and not the latest version of whatever image is being deployed.

From the man page for oc rollout latest: "Start a new rollout for a deployment config with the latest state from its triggers"

Kurt Koller
  • 334
  • 1
  • 3
  • 14
  • I used OC patch as well as oc rollout & both served the purpose. Finally I settled with oc rollout as I believe it is the better approach. – user2700022 Nov 27 '19 at 06:58
0

If I properly understood the question, you want to re-deploy and restart the pod(s) using an image from the image stream that has a specific image tag.

A way to achieve that can be to update the image tag for the image in the DeploymentConfig by setting it to the desired tag. The update will trigger an automatic re-deploy and pod(s) restart if the DeploymentConfig has trigger of type "ConfigChange" defined. To update the DeploymentConfig, edit it (oc edit dc/<deployment_config>) or patch it.

Otherwise, just like in the OpenShift web console, to roll back to a specific deployment revision, run:

oc rollout undo dc/<deployment-name> --to-revision=<revision-number>

Obviously, you would need to know the revision number. Type in oc rollout undo --help to read about some intricacies of the command.

EDIT: The "OpenShift way" to have the pod(s) automatically restarted when the image they are based on changes in the image stream, is to use ImageChange trigger. An example from the docs is [here][3].

This may be convenient during development but in general, though, it is a best practice to tag each image version differently and not to use latest when referencing an image by its tag.

apisim
  • 4,036
  • 1
  • 10
  • 16
  • What I'm trying to achieve is, in layman's terms simply restart the pod – user2700022 Dec 27 '18 at 09:31
  • If you had to do it that way for some reason, you can use ``oc set image`` instead of needing to edit the ``dc``. – Graham Dumpleton Dec 27 '18 at 10:12
  • Good suggestion by @GrahamDumpleton - OpenShift's `oc` makes it easier to change the image in a DeploymentConfig instead of using the generic `patch` command. – apisim Dec 30 '18 at 16:56
  • @apisim & @GrahamDumpleton Thanks for suggestions, actually as I have already mention in the question - I am already using the `Trigger: Image Change` for normal deployments. What I am looking for is typically a pod restart /redeployment of the same image that the pod is currently running on. The closest I have came is oc edit dc if I simply increment the value of latestVersion In the DC it will redeploy the same image. But the oc edit dc is interactive, I would like to automate this. Any idea? or any better way to achieve this? Thanks again!! – user2700022 Jan 02 '19 at 09:53
  • @user2700022 Did you read the link provided as comment to your original question. You can use the ``oc patch`` command using the example in it. – Graham Dumpleton Jan 02 '19 at 10:18
  • @GrahamDumpleton interestingly, I tried this `oc patch dc/dc-deployment --patch "{\"spec\":{\"template\":{\"metadata\":{\"annotations\":{\"last-restart\":\"`date +'%s'`\"}}}}}"` & I get the patched output sadly the deployment doesn't happen :( – user2700022 Jan 02 '19 at 12:39
  • @apisim Any thoughts on https://stackoverflow.com/questions/58421160 ? – Peque Oct 18 '19 at 00:22