DEV Community

Cover image for Deploying Our Multiplayer Game Server to Red Hat OpenShift | Creating a Multiplayer Game Server - Part 6
Bradston Henry for IBM Developer

Posted on • Updated on

Deploying Our Multiplayer Game Server to Red Hat OpenShift | Creating a Multiplayer Game Server - Part 6

In this entry of "Creating a Multiplayer Game Server" we will be deploying our multiplayer game server into the cloud using Red Hat OpenShift (RHOS).

In our previous blog, we built our game application and connected it to our game server on our local machine. Now it's time to see how it feels to have our multiplayer game server running remotely and how we most likely desire it to run in the "real-world". Using Red Hat OpenShift, we can easily deploy our server with a few simple steps and quickly connect our game application to our server. But before we get deep into the process of deploying our game server, let's make sure we have everything we need to get started.

Prerequisites

  1. IBM Cloud Account (Sign up for Free here)
  2. Game Server Source Code in Git Repo (Feel free to use my repo)

The only requirements we really have is to have an IBM Cloud account and to have the source code for our multiplayer game server hosted in a Git-based repository. As I shared above, you can sign-up for a Free IBM Cloud account using this link and you can use my git repo if you don't want to host the source code yourself in your repo.

Now that we have all that we need to get started.... lets get started!

What is Red Hat OpenShift

So if you have not had the opportunity to read my RedHat OpenShift 1001 blog post, I will give a very brief overview of what Red Hat OpenShift is so we'll have a basic understanding of the platform.

In short, Red Hat OpenShift is a platform that allows you to easily manage, deploy and orchestrate containerized applications in the cloud. RHOS hopes to be the answer to one of the biggest problems that derives from developing and deploying microservice-based applications in the world. Its goal is to deliver a consistent and standardized approach to overseeing containerized application deployment.

OpenShift also provides features like continuous monitoring, logging, and continuous integration and deployment out-of-the-box. It's a great place of operations engineers and developers to deploy and monitor complex and simple applications in the cloud.

Overview Image of some Red Hat OpenShift features

If you would like a more in-depth look into Red Hat OpenShift, please check out my Red Hat OpenShift 1001 blog where I go into detail about what Red Hat OpenShift is and some of it's functionalities and capabilities.

Deploying Our Game Server to RHOS


Step 1: Provisioning our RHOS Environment

Note: If you already have access to an Instance of Red Hat OpenShift, you can just skip straight to Step 2.

So one tricky thing about working with Red Hat OpenShift is that it can sometimes be tough to get hands-on with the tools since in general RHOS has a cost associated to it to deploy it on the web.

But luckily IBM has some resources that allows anybody to get hands-on time with Red Hat OpenShift for πŸ”₯FreeπŸ”₯!

One of those resources is IBM Open Labs Red Hat OpenShift on IBM Cloud.

The only thing you will need to access the resources is a FREE IBM Cloud account. If you do not have an account, you can sign-up for your account here: IBM Cloud Account Sign-up

Once we have an IBM Cloud account, Using Open Labs we are able to get a provisioning of RHOS environment for 4 hours at No Charge. All you need to do is navigate to website link and Launch the Lab and you have access to Red Hat Open Shift for limited period of time.

Just to make these steps consistent, I will go through the steps using IBM Open Labs. If you have access to your own RHOS instance, you can skip to the portion of these steps and head to Step 5.

So let's first navigate to IBM Cloud Labs: Red Hat OpenShift On IBM Cloud Website.

5 - open labs homepage

Scroll down slightly until we see the "Hands On Labs" section and select the "Launch Labs" button in the "Bring Your Own Application" Box:

6 - Launch Lab

Once we select Launch Labs, we will be prompted to sign-in to IBM Open Labs using our IBM Cloud Account. NOTE: If you do not have an IBM Cloud account, feel free to register on this page or via this sign-up link:

7 - lbm sign up open labs

Once we've signed-in, we will be brought back to Open Labs page. Wait a few moments. We will likely see a message saying "Please wait..provisioning the lab" and then followed by a pop-up titled "Launch Lab":

8 - provisioning lab

9 - launch lab

In the "Launch Lab" pop-up, select "No" to the "Do you have an Opportunity Id" and then select the "Launch Lab" Button.

Once we select "Launch Lab" we will see a few messages saying that the Lab is provisioning and that the lab is being setup. This normally takes about 30 seconds to a minute.

Once it's finished loading, we should be presented with this page:

10 - Open Labs Landing Page

NOTE: Once you launch the lab, your 1 hour time limit for using the RHOS instance has begun. You can always re-launch the lab later but be aware that this instance will be de-provisioned after that time allotted expires.

Once on this page, select the "Exercise 1" option on the left sidebar, then select "Red Hat OpenShift on IBM Cloud Basics":

11 - Select Quick Links

Once on the next page, select the link next to the third bullet point under the "Quick Links":

12 - Access IBM Cloud Portal

This will navigate us to our IBM Cloud account and our Free Red Hat OpenShift Instance that has been provisioned for us. Note: It may take a few seconds for the page to fully load as it pulls in our info.

Once on the page we should likely see that we are in a "DTE" Account and that our Red Hat Instance name is something starting with "dte". Eg. "dte-abc12-ks8xyz":

12 - IBM Cloud Landing

Once on the page, let's launch our OpenShift instance using the RHOS web console. In the top-right corner page of the page select the button titled "OpenShift web console":

13 - Launch Web console

Once we select the "OpenShift web console" we should be presented with a page like this:

14 - OpenShift Dasboard

We now have an instance of Red Hat OpenShift running and can get ready to deploy our simple Node application.

REMINDER: Once you launch the lab, your 1 hour time limit for using the RHOS instance has begun. You can always re-launch the lab later but be aware that this instance will be de-provisioned after that time.

Step 2: Provisioning our RHOS Environment

Before we can deploy your Node application, we need to create a project that your Node.js game server application will be associated with. This is a very simple process that should only take a minute or two.

First, we must change our OpenShift dashboard view to be the Developer perspective. (The default view for the OpenShift web console is the Administrator perspective.) To do this, go to the navigation panel, open the Perspective Switcher drop-down menu (where Administrator is currently highlighted), and select Developer, as demonstrated in the following screen capture image:

Perspective Switcher menu

When we switch to the Developer perspective, we might be presented with a Welcome to Dev Perspective pop-up window that looks similar to the following image. We can select Skip tour for now, but feel free to select Get Started to get an overview of the Developer perspective.

Developer perspective welcome message window

Now let's create the project. From the navigation panel, click Topology. Then open the Project: all projects drop-down menu and select the Create Project option, as illustrated in the following screen capture.

Topology page with Create Project menu option highlighted

After we select that option, we should be presented with a Create Project pop-up window. Enter any name you like in the Name field. I used multiplayer-game-server-app (note that the name must be in lowercase letters). All the other fields are optional.

After we enter this information, select the Create button.

Create Project window with Create button highlighted

Now that the project is created, we should be presented with the Topology page where a No Resources Found message is displayed. In the next step, we will deploy your Node app β€” your first resource.

Step 4. Deploy your game server to OpenShift

It's time to deploy our multiplayer game server. Just a few more steps and our app will be live!

Now that you have our OpenShift instance and our project created, we can now use OpenShift's source-to-image (S2I) method to quickly and easily deploy your application. This functionality takes the code from your Git repo, builds a container image, and deploys it into your OpenShift environment. It does most of the hard work for us.

To build and deploy your application, we will use the "From Git" method to build and deploy out the application. With this method, you initiate the S2I process, watch our application get deployed, and view the results. Essentially, OpenShift automatically identifies what type of code base is being used and then uses the appropriate containerization process to create a container image. We only need to do a few small things.

On the Topology page, select the From Git option.

From Git selection

On the Import from Git page, enter the URL for our Git repo in the Git Repo URL text box.

Import from Git page

Close up view of the Git Repo URL input field

After we insert our Git repo link, it should automatically identify that you are using a Node.js builder image for our application. If it is not selected automatically, select the Node.js option in this section.

Builder page with the Node.js builder image highlighted

The nice thing about S2I is that it can save us a lot of time by automatically identifying the language we are using to build your application.

As you move down the page, we will see the Builder Image version drop-down menu. In this case, the default version selected should be fine.

Default option highlighted within the Builder Image Version menu

All that's left is to give your app a unique application name and component name. I used multiplayer-game-server-node-app and multiplayer-game-server-node, respectively.

As we move down the page, we should see the Resources and Advanced Options sections. Under Resources, ensure that the Deployment option is selected. Under Advanced Options, ensure that the Create a route to the Application checkbox is selected. This ensures that a public URL is created for your newly created application.

Application name, Resources, and Advanced options sections

After we confirm all of those options, click Create. This will take us back to Topology page where we should see that your application now exists.

During the next few minutes, we should see your application go through the process of being built. As demonstrated in the following image, a small icon near our resource/application should change. It may take a few minutes, but when the green checkmark appears, it means that our application successfully deployed.

Icons that indicate a pod status change

If we select our application in the Topology view, a details panel opens that shows you more build, services, routes, and monitoring information.

Pod application details panel

Now that our application is up and running, we can either select New window (there is an icon located just above the Node logo) on our resource in the Topology view to open our server, or navigate to the bottom of our details panel under the Resources tab and select our URL under the Routes section.

New window icon to open the application URL

Either option will open our application URL and only the words Upgrade Required should appear on the page, as demonstrated in the following screen capture.

Upgrade Required message

Sometimes, we may see an error page with the words Application is not available even after the application indicates that it was built and successful deployed.

Error message example

There are a few reasons why this might happen. The two main ones are:

  1. The application is still in the process of starting, Although it finished building, the app and needs a bit more time to be ready (about 1-2 minutes). Feel free to check the logs for your application deployment to make sure everything looks fine by selecting the View logs button in the application details panel. It is located in the Pods section under the Resources tab.

View logs button

  1. The hosting port that we selected in your server application does not match what OpenShift is expecting. By default, OpenShift exposes the app at the 8080 host port. If we identify a different port in our application code, that can cause deployment issues. To fix this, just ensure that the port selected to be hosted in your code is 8080. After we make that change, push the new code to our same repo and select Start build from the application details panel under the Resources tab. This automatically rebuilds the application from our repo by using the updated code.

Connecting our Multiplayer Game to our RHOS Game Server

So this step is very very simple. Since we have already set up our multiplayer game to connect appropriately to our WebSocket game server based on it web url, we just need to update that in our game code.

Using the code we created in our previous blog, navigate to the Unity C# script titled "Socket Manager" and change the code on line 20 from :

socket = new WebSocket("ws://localhost:8080")
Enter fullscreen mode Exit fullscreen mode

to

socket = new WebSocket("ws://<your-red-hat-openshift-server-url>")
Enter fullscreen mode Exit fullscreen mode

Once you have changed that line of code, open up our Multiplayer Game Project using our Unity game editor and play our game.

But how do we know that our Game server is working in Red Hat OpenShift? Well it's fairly simple! All we need to do is check our logs of our server in Red Hat Open Shift Server.

Let's go ahead and navigate back to our RHOS topology view and select our pod as we did before. With our Pod selected, let's the View logs button in the application details panel:

View logs button

Once selected, we should be presented with a page that shows our current logs for our server. On this page, we should be able to see, just like when we tested locally, that our players movement data is being sent to our server:

Logs for Game Server in RHOS

An Just Like that, we have successfully deployed our Game server to Red Hat OpenShift!


In the next part of the series, we will be adding code to our multiplayer game that allows for us to view multiple players within our game application. At this point, we have only shown the process of connecting our multiplayer game to our game server and proving that the data is correctly being received. But now it's time to truly take our application to the next level and to actually allow players to play together in the same gaming space! You don't want to miss it!

As always, Thank you for reading and excited to continue this journey with you all!

All the Best!

Bradston Henry

==== FOLLOW ME ON SOCIAL MEDIA ====

Twitter: Bradston Dev
Dev.to: @bradstondev
Youtube: Bradston YT
LinkedIn: Bradston Henry

Top comments (3)

Collapse
 
tmhntr profile image
Tim Hunter

I’m just getting into multiplayer game development and this series was super helpful! Thanks :)

Collapse
 
bradstondev profile image
Bradston Henry

Thanks so much Tim! I'm happy it's been helpful.

If you are looking for more multiplayer game dev tutorial content I have recently been working on a YouTube series about Unity's MLAPI multiplayer framework. Might be something you are interested in as well. Figured I'd drop a link for you:

youtube.com/playlist?list=PLMygHu9...

Thanks again for checking out my blog! Means a lot!

Collapse
 
doronin0208 profile image
Codemaster • Edited

I’m just getting into multiplayer game development like Tim and this series was super helpful! Thanks :)
Could you post next step this article continuously?