OpenShift v2 to v3 migration

A few months ago I received a mail from OpenShift informing me that version 2 was coming to an end and that if I wanted my application to continue to be accessible I had to migrate it to the new shiny version 3. The interesting part though was this needed to happen within the next 30 days. I was quite shocked and disappointed, as were a lot of other v2 users judging by the comments on the announcement.

However, as I needed my applications to continue to exist and be available, I spent some time reading through their documentation and their migration guides and the process turned out to be quite smooth.

My application was developed in PHP Symfony framework 2.8 and was using MySQL for data storage.

I decided to start with the storage.

Following the migration guides I first exported my application’s data, saved them in a dump file and downloaded it to my local machine:

$ rhc ssh <v2_application_name>
$ mysqldump --skip-lock-tables -h $OPENSHIFT_MYSQL_DB_HOST -P ${OPENSHIFT_MYSQL_DB_PORT:-3306} -u ${OPENSHIFT_MYSQL_DB_USERNAME:-'admin'} \
--password="$OPENSHIFT_MYSQL_DB_PASSWORD" --all-databases > ~/app-root/data/all.sql
$ exit
$ mkdir mysqldumpdir
$ rhc scp -a <v2_application_name> download mysqldumpdir app-root/data/all.sql

Then I created a new MySQL pod on OpenShift v3 with:

$ oc new-app mysql-persistent -p \
MYSQL_USER=<your_V2_mysql_username> -p \
MYSQL_PASSWORD=<your_v2_mysql_password> -p MYSQL_DATABASE=<your_v2_database_name>

When the pod was up and running, I synced the database archive files to the v3 MySQL pod and restored the database:

$ oc rsh <mysql_pod>
$ cd /var/lib/mysql/data/mysqldumpdir
$ mysql -u root
$ source all.sql

My new MySQL pod was up and running, loaded with my latest data in persistent storage.

Next part was the PHP Symfony code. For this part I had to set up a new GitHub repository add it as a remote branch to the current, local v2 Git repository and push the local v2 source code to the new repository:

git remote add <remote-name> https://github.com/<github-id>/<repo-name>
git push -u <remote-name> master

I then used the oc command to launch a new PHP application from the builder image and source code:

$ oc new-app https://github.com/<github-id>/<repo-name>.git
--name=<app-name> -e <ENV_VAR_NAME>=<env_var_value>

And that was all. I had two new pods on OpenShift v3 up and running.

At the moment, the only limitation with the free account is that the user can’t push changes to the repo and get the pod updated as the rolling update uses two pods for that job and the max number of pods with a free account is sadly two. Therefore in my case I need to switch the MySQL pod down every time I need to updated my PHP pod.

Like what you read? Give Andrew Bsk a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.