Deploy a .Net Core 2.1 Microservice API in OpenShift

.NET Core web api microservice deployed on Minishift 3.11

Getting Started

If you do not have OpenShift or Minishift setup with SonarQube inside then read the other blog post on setting up OpenShift and SonarQube as you will use these later. Now clone the repo linked above and look at the deployment.yaml file. THAT is what makes the OpenShift project look like the image above. I won’t go into breaking down the YAML file in explicit detail however, I will break down what it creates in OpenShift so you can do that yourself with some foundational knowledge. (Note: anywhere I put OpenShift you can test locally with Minishift.)

Minishift new deployment via YAML

Building the Images

This project has a pipeline. I want to show you how to do the steps the pipeline calls though. So click on Builds in the far left project screen in OpenShift and then click Builds on the popup menu. You should see two builds there with “No Builds” as the last build listed. And on the far right you see the type “Docker” and the link to the GitHub repo. Click on the database configuration (remember which is which?) and then click the Start Build button. Watch it fly and see all it does. You can also click Logs and see the logs just as if you ran a docker build -t xxxxxxx . type of command locally. (If the build fails because of a timeout or slow OpenShift setup you have, try again. Pulling the starting image definition to do this takes a while and sometimes makes it fail I have seen intermittently.)

PeopleAPI Database deployment configuration
Your PeopleAPI database is now operational!
PeopleAPI fully deployed microservice with Jenkins

Network connectivity within the project namespace

If you go to the actual deployment of the peopleapidb and click the Configuration tab one other thing you will notice is the Ports 1433/TCP listed. That means this container is listening on port 1433, the default MS SQL Server port as this DB is the Linux variant of that. You will also see there is NO ROUTE for the database as we do not want people going straight to the database. It is hidden behind Minishift.

PeopleAPI Environment settings for the deployment

Advanced: Go into the container through OpenShift

Let’s say you want to go into the container and see if something is set, permissions, files, or just to see how they made it. In Docker Community Edition you can do a docker exec -it name-of-container sh to get a command prompt. Well it is easier in OpenShift. Click the Applications menu and then Pods. You will see 2 completed pods (the builds you did) and then 3 running pods.

Active pods running inside the PeopleAPI project
PeopleAPI pod with Terminal access

So what did we just do?

We just deployed a microservice API in .NET Core 2.1 web api format inside Minishift with Jenkins. That is what we did! Pretty cool stuff unless you have been following k8s and OpenShift and Docker for a while. Even so, cool to have it templated and get rolling to test quickly. Now what?

Next Steps

Really the next steps are to link in the Jenkinsfile we have, add plugins to Jenkins for SonarQube and Aqua Microscanner and other items, and then run the pipeline. But that is in my other post. For now click around in the project and learn. And then read the deployment.yaml file again and match the setup to the actual running project in Minishift. That is how I learned this. Enjoy!

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Dale Bingham

Dale Bingham

CEO of Soteria Software. Developer on OpenRMF. Software Geek by trade. Father of three daughters. Husband. Love new tech where it fits. Follow at @soteriasoft