This section will guide you through an exemplary zero downtime deployment. Feel free to use our Sinatra example application for experimentation purposes. This guide assumes that you bind all needed services to both application instances so both deployments can access live data. The basic idea is to deploy a second application instance with another name and remap the routes on the fly to point to the newly updated instance.
1) Deploy your application as usual
At first you will have to push your application to anynines using the following command:
$> cf push <first_instance_name> -n <live_subdomain>
e.g.: $> cf push sinatra_a -n sinatralive
After finishing the deployment process your application will be available under <live_subdomain>.de.a9sapp.eu (sinatralive.de.a9sapp.eu).
2) Deploy an updated instance
When code changes have been commited and tested through your production pipeline you can start with the zero downtime deployment process.
You will have to push a second instance with a different application name to your current space by issuing the following command:
$> cf push <second_instance_name> -n <staging_subdomain>
e.g.: $> cf push sinatra_b -n sinatrastaging
After finishing the deployment process your updated application instance will be available under <staging_subdomain>.de.a9sapp.eu (sinatrastaging.de.a9sapp.eu). You can use this url to perform a last check on your new features and bugfixes.
3) Re-map the routes to the updated instance
At this time both application deployments are accessible via the urls <live_subdomain>.de.a9sapp.eu and <staging_subdomain>.de.a9sapp.eu .
It’s time to remap the live route to the updated application deployment:
$> cf map-route <second_instance_name> de.a9sapp.eu -n <live_subdomain>
e.g.: $> cf map-route sinatra_b de.a9sapp.eu -n sinatralive
Right now all traffic to <live_subdomain>.de.a9sapp.eu will be load balanced between the old and the new application versions.
4) Remove the live route from the outdated deployment
Now we can remove the route from the outdated application deployment:
$> cf unmap-route <first_instance_name> de.a9sapp.eu -n <live_subdomain>
e.g.: $> cf unmap-route sinatra_a de.a9sapp.eu -n sinatralive
From now on all requests to <live_subdomain>.de.a9sapp.eu will be routed to the updated application instance.
5) Remove the staging route
As we don’t need the staging route we can delete it from the updated deployment using the unmap-route command:
$> cf unmap-route <second_instance_name> de.a9sapp.eu -n <staging_subdomain>
e.g.: $> cf unmap-route sinatra_b de.a9sapp.eu -n sinatrastaging
6) Stop the outdated instance
Finally, let’s stop the outdated application version to save resources:
$> cf stop <first_instance_name>
e.g.: $> cf stop sinatra_a
If we run into any problems with the new application version we can easily fall back to the old state by starting up the deployment and remapping the live route to it again.
For more details on zero downtime deployments please refer to our blog post.
Please sign in to leave a comment.