Containerize applications and run them in the cloud with OpenShift
OpenShift uses Kubernetes orchestration to manage a variety of container runtimes inside pods, and run them in a public or dedicated cloud environment. It includes support for Docker containers, which we'll be using in this example. Applications can be made HA (High Availability) by running multiple instances of your application in parallel connected by an OpenShift service, and can scale up or down appropriately in response to changing traffic loads. In this case, our container will be running independently, but applications can be integrated with other services, persistent storage such as databases, which I will be covering in a future post.
The golang http package is great for simple websites with static pages, but is pretty light on routing functionality out of the box. I was looking at adding dynamic routing while still keeping things as efficient as possible, and add only what functionality I needed for this particular website project. I took an interest in echo after comparing benchmarks of various go-based web frameworks and routers. It's built for speed with radix tree based route lookup, but it doesn't have built-in regexp support. That can be worked around with its match-any and adding your regexp checking in the route's handler, as I'll detail in the examples.
OpenShift Cron Jobs provide a way to run programs and scripts on a fixed schedule, without having to rely on services in long lived containers. A new container gets created to execute code for each run of the cron job, and the container gets removed after the code inside of it reports it has finished running and exited successfully.
Abstract sockets are a great way for multiple containers in the same OpenShift or Kubernetes pod to communicate with each other, without using any additional storage volumes or network configuration. Since all the containers in a single OpenShift and Kubernetes pod will share the same IPC namespace by default, you can reference a Unix Domain Socket in your program like '@my-abstract-socket', without having to create and keep track of mounth paths.
OpenShift secrets allow you to load private data into your pods and containers without baking them into your container images for all to see and use. This allows you to separate your prave data from your code, and securely host your images in public registries. In this example, we'll be using OpenShift secrets to store a set of API key credentials for an AWS (Amazon Web Services) IAM (Identity and Access Management) account, which we'll be using to send emails with Amazon SES (Simple Email Service).
In this example we'll be exploring some use cases for Daemonsets on OpenShift. We'll leverage several neat features in Kubernetes to achieve what can essentially be used as a system container that runs in an OpenShift pod on every master in a cluster, and each container will mount its host's filesystem into the container itself.