Containers are the new way of deploying applications. They provide an efficient mechanism to deploy self-contained applications in a portable way across clouds and OS distributions. In this blog post we'll look at what OpenShift brings for .NET Core specifically.
Kubernetes and OpenShift
Kubernetes is the de facto orchestrator for managing containerized applications. Google open-sourced Kubernetes in 2014 and Red Hat was one of the first companies to work with Google on Kubernetes. Red Hat is the 2nd leading contributor to the Kubernetes upstream project.
OpenShift is an open-source DevOps platform that is built on top of Kubernetes. It integrates directly with your application’s source code. This enables continuous integration/continuous deployment (CI/CD) workflows. Tools are available to scale and monitor your applications. The OpenShift Catalog makes it easy to setup middleware and databases. OpenShift comes with comprehensive documentation to install and manage your installation. It can run on-prem and on public clouds such as AWS, GCP and Azure.
.NET Core on OpenShift
.NET Core is an open-source, cross-platform .NET implementation. It was open-sourced in 2015 by Microsoft. Like with Kubernetes and OpenShift, this permits anyone to build, maintain and support .NET Core. Red Hat is doing this since the 1.0 release and, in tandem with Microsoft, Red Hat provides services releases and new .NET Core releases for Red Hat Enterprise Linux (RHEL) and OpenShift. Recently, Red Hat announced availability of .Net Core 2.1.
For RHEL, this means the .NET Core SDK and runtime are available for building and running applications. For OpenShift, it means there is a source-to-image (s2i) builder for .NET Core which makes OpenShift understand how to build .NET Core applications.
The s2i-builder can be tuned with variables and it supports many typical workflows. If more control is required, a custom script (.s2i/bin/assemble
) can be versioned with the source code that directly controls the build. Even more advanced scenarios are possible using Jenkins on OpenShift, which also supports .NET Core.
Getting Started
You can run OpenShift on your development machine using minishift. minishift comes as part of the Red Hat Container Development Kit (CDK). The CDK documentation describes how to install and start minishift. CDK is available as part of the no-cost development subscription. It runs on Windows and macOS too!
For a production installation, you need to follow the OpenShift and cloud-vendor specific documentation. If you want to try OpenShift on the public cloud without installing it yourself, you can create a free account at OpenShift Online.
Once you have your OpenShift instance running, deploying an application can be done via the OpenShift web UI (called 'Console') or the OpenShift cli (oc
). The cli comes as part of the CDK installation, you can also download it from the openshift/origin GitHub project. To deploy the application we use the oc new-app
command:
$ oc new-app --name=exampleapp dotnet:2.1~https://github.com/redhat-developer/s2i-dotnetcore-ex#dotnetcore-2.1 --build-env DOTNET_STARTUP_PROJECT=app
This tells OpenShift to deploy a .NET Core application and name it exampleapp. dotnet:2.1 is the name of the s2i-builder for .NET Core 2.1. https://github.com/redhat-developer/s2i-dotnetcore-ex and dotnetcore-2.1 are the git repo and branch respectively. We set DOTNET_STARTUP_PROJECT to tell the s2i-builder our application is in the app directory.
The Console shows the status of the build and deployment:
Note that we didn't have to write a Dockerfile and use it to build an image locally. OpenShift fetched our sources from git and built them in a contained, controlled environment!
When new service releases of .NET Core become available, the application will automatically be rebuilt and redeployed to use the latest patch version. To enable a CI/CD workflow, OpenShift can be configured to rebuild and redeploy on source branch changes as well.
Conclusion
In this blog post, we've looked at the differences between Kubernetes and OpenShift. We've also looked at how OpenShift supports .NET Core. The .NET Core Getting Started Guide has more info about running .NET Core on RHEL and OpenShift.
To get started with development, download Red Hat Container Development Kit. You'll get an OpenShift (and Kubernetes) development environment in a VM that you can run on your Windows, Mac, or Linux laptop.
OpenShift documentation is available at https://docs.openshift.com/. You can also download the free ebook, Deploying to OpenShift.
Last updated: November 2, 2023