One year of OpenShift and containers

Time to look back. I have used OpenShift since 2016. The old OpenShift PaaS was retired a year ago. Same time I wrote my first blog about ‘last minute’ migration of my crowdfunding app to new OpenShift v3 container application platform. The migration, as such, was relatively straightforward, resulting to two running containers: Dockerised Node.js app and Mongo database. Now, I have gained some more experience of the new platform.

OpenShift builds on top of Kubernetes and supports deployment from Docker images. When v3 was released, source-to-image builds were not well supported. Currently, building and deployment from hosted Git repositories is possible. I have used deployment from prebuilt and locally tested images. Initially, I used Dockerhub as an intermediary storage for my images. However, due to improved documentation, I finally managed to create the image-stream by pushing the image directly in the OpenShift internal registry. This is convenient, especially, if you want to tricker new deployment on image chance. Otherwise, you’ll need to define Webhooks to update your image-stream from the remote repository.

OpenShift supports different databases (e.g. Mongo, MySQL, and PostgreSQL) as a prebuilt images. However, database containers (pods) needs to be mounted to persisted volumes in order to survive from container crashes and recreation without data loss. The documentation is partly miss-leading here. Even if you deploy a ‘persisted’ database the data is not automatically persisted. Especially, when using the command line tool, you need to add create a separate persisted volume and mount your data directory. I should have known better.

OpenShift don’t have built-in support for database backups. For manual database backups and migrations, I have used SSH port-forwarding. It is nice, as it allows running Mongo maintenance tools from the local machine. After having some database hiccups with wrongly configured or non-existent (!) persisted volumes, I ended up running a cron job for nightly database backup. Yea, persisted volumes taught me a lesson.

After all, I have enjoyed working with OpenShift v3 and will continue the journey. Next, I’d like to learn about different Kubernetes update strategies. Keep it rolling!

Recommended brand new eBook from O’Reilly: Deploying to OpenShift

Advertisements

Experimenting with OpenShift container application platform

As a weekend exercise, I migrated my old MEAN stack app into new OpenShift 3.0 PaaS. OpenShift has been completely rewritten utilising Docker containers orchestrated via the Kubernetes. Namely, it is a platform for deploying and managing Docker containers.

In OpenShift, a project is a Kubernetes namespace, which is a cluster of resources used by an application. The basic unit of deployment is a poda container started form a Docker image. Scaling can be done by varying the number of pods running.

For my setup, I deployed two Docker containers, one for the Node.js app and one for Mongo DB. Deployment can be done from the local machine, a git repository, or from DockerHub. I uploaded my images first to DockerHub and used that as an image stream for my deployment. You can also set webhooks to trigger automatised deployment on code or image change. OpenShift support different deployment strategies e.g. automatised rolling deployments.

My biggest challenge was to get my Docker images run on OpenShift, as there are some restrictions on how to set up your Dockerfile, e.g. due to security reasons you should avoid running commands as sudo. And I couldn’t find much documentation or examples of compatible descriptions.

In addition to web console, OpenShift provides a command line tool. It can be used to create new applications and to manage containers. Surprisingly, yes, the command line tool seemed to be most convenient for making deployments. You can use it to run commands inside your containers e.g. for debugging and setting up you database. It is, as they say, “one tool to rule all”, no need to use SSH or such. Web console was nice for setting environment variables and setting up routes. Web console also provides handy view on runtime, build, and deployment logs, metrics on used resources, and even integrated terminal window.

OpenShift has a free start-plan, which allows setting up one project and two pods with limited amount resources. Pro-plan can occupy up to 10 projects and the basic cost is about 50€ per month.

I had some previous experience on Docker, but first time I deployed containers on PaaS. Finally, I have it all happily up and running. So, if you’re looking for a container application platform…

Oh, and there is a free ebook by O’Reilly OpenShift for Developers.