Kubernetes and MC Server Hosting
MC Server Hosting is a beast. I built it. I should know. I can’t tell you the number of times I’ve built up and tore down a Kubernetes cluster before getting to it. It’s fast given its I7's, efficient given its containerization, and intelligent given the orchestration system in place.
You might be here because you made a purchase or just want to hear about it. Either way, let me help you, or show you what it’s like to get started.
When being presented with this headless service you’ll have 3 attachments in a welcome email of sorts. A key, and two certificates. Let me explain.
The key and certificate named after your email (example, firstname.lastname@example.org, and email@example.com). These, for all intents and purposes, will be used as your keys to your future Minecraft castle. That is, your console, your server files, our backup system, your raw IP/Port info, everything. It will also contain another file called ca.crt. That’s our cluster cert. I had the intention of not needing that be distributed that's…another story. For now, you’ll need that to have that to enter the cluster securely.
With these item’s download and placed anywhere, let’s get started. I’d recommend making a folder called “mcsh” in your documents folder and putting them in there. I’ll be using “C:\Users\ExampleUser\Documents\mcsh” as the path for commands I’ll be showing moving forward. So if you’re following along, you’ll need to change “ExampleUser” to your actual username on your Windows Machine.
If you’re using Mac or Linux, you’ll need to adjust the entire path. Use “/home/ExampleUser/mcsh” as a base.
So now, lets…
Kubectl is the program that is required to communicate with the cluster. Think of it as the Minecraft Server UI that talks to the actual program in the background running the server. Except here it’s remote, and you’re going to talk to the cluster running the container that has more than that.
Installing on Windows
We’re gonna use PowerShell! It’s very nice and blue. Go ahead and go into your start menu. In your search bar type in “PowerShell”. A program named Windows Powershell should open. Go ahead and click on it.
To install kubectl, we’re going to use PSGallery. It’s a nice library of available programs that PowerShell knows where and how to install. So let’s get started.
Note, each command is one line. Not two!
First, we’re going to get the install script from Microsoft.
Install-Script -Name install-kubectl -Scope CurrentUser -Force
Now, if this is your first time running
Install-Script you’ll see a notice like this.
NuGet provider is required to continue PowerShellGet requires NuGet provider version ‘22.214.171.124’ or newer to interact with NuGet-based repositories. The NuGet provider must be available in ‘C:\Program Files\PackageManagement\ProviderAssemblies’ or ‘C:\Users\ExampleUser\AppData\Local\PackageManagement\ProviderAssemblies’. You can also install the NuGet provider by running ‘Install-PackageProvider -Name NuGet -MinimumVersion 126.96.36.199 -Force’. Do you want PowerShellGet to install and import the NuGet provider now? [Y] Yes [N] No [S] Suspend [?] Help (default is “Y”):
It’s telling you that it needs a program called NuGet to continue and wants to get it for you. Go ahead and hit enter. The default option is yes. It’s a very light program too.
After that, we’re just going to run it. Here, I’m going to tell PowerShell to put it all in my mcsh folder. If you don’t do this, it will just install in your temporary directory.
install-kubectl.ps1 -DownloadLocation "C:\Users\ExampleUser\Documents\mcsh"
And just like that, we’ve got it installed!
Installing on Mac or Linux
There are different flavors of each system. You’ll have to go to the official documentation to install kubectl. Choose it based on your operating system. Once you’re back, we’ll continue.
Connecting to The Cluster
Alright, you’ve got it installed. Now let’s get you set up. Be sure to have all the certificates and your key in your mcsh folder before moving forward!
So, what we’ll do here is pass our key and certs to kubectl so it can use them every time we need to get something from the cluster. Like a file or a stream to/from the console. So let’s tell kubectl where everything is.
Be sure to replace anything with the word example with your own information!
Also note, each section is still 1 command. Now two or more! So use them line by line.
First, we’ll set our credentials.
kubectl config set-credentials <your-email> --client-certificate=
Then we’ll set our context. This will include our namespace. A namespace is essentially an area that all your servers and data can reside securely without being accessible to others. By default, with MC Server Hosting, your user is set as your email you specified. The same goes with your namespace except for all symbols including “@” and “.”. They’re replaced with dashes.
kubectl config set-context firstname.lastname@example.org --cluster=mcserverhosting --namespace=new-user-example-com --email@example.com
Alright, halfway done. Let’s tell it where the cluster is! Fun fact, we use CloudFlare’s Load Balancers to support (currently two) endpoints just in case one of them were to go down. We also pass in our cluster’s cert here.
kubectl config set-cluster mcserverhosting --server=https://cluster.mcserverhosting.net:6443 --certificate-authority="C:\Users\ExampleUser\Documents\mcsh\ca.crt"
Finally, let's tell kubectl to use the information we provided every time we run a command.
kubectl config firstname.lastname@example.org
And that’s it. Let’s see your server!
Go ahead and run the following.
kubectl get pods
Your server is inside a pod. You’ll see something like this.
NAME READY STATUS RESTARTS AGE
example-server-xxxx 1/1 Running 0 5d
newer-server-xxxxxx 1/1 Running 0 1h
You can see all your servers with this command! In this example, you’d be able to go to example-server.mcserverhosting.net in the appropriate Minecraft Launcher to join your server. However, let’s go over some quick commands.
Some Basic Commands
Now that you have the server’s name (technically the PodID) let's go ahead and get to know some common command you’ll need to manage it.
We’ll use example-server-xxxx as the server that we want to access.
To access console
kubectl attach -it example-server-xxxx -c mc-server
To access shell (otherwise known as root access for you VPS admin users)
kubectl exec -it example-server-xxxx -c mc-server -- /bin/sh
Your Minecraft Server files are located in /root/minecraft. Let’s say you want copy a file from your computer to the server. Let’s also say it’s in a local folder called C:\Users\ExampleUser\Documents\my-local-minecraft-server. In this example, we’re going to bring ops.json over to the server.
kubectl cp C:\Users\ExampleUser\Documents\my-local-minecraft-server\ops.json example-server-xxxx:/root/minecraft/
Finally, let’s say we want to get a folder from the server. Let's say the log folder so we can study it here.
kubectl cp example-server-xxxx:/root/minecraft/logs C:\Users\ExampleUser\Documents\my-local-minecraft-server\
You now know the basics!
You’re ready to get started with your Minecraft server! More advanced tutorials and detailed walkthroughs will be coming soon. The next article will be how to install a Modpack. Essentially, we’d just be using
kubectl cp but I’d like to walk you through it in the future just in case ;).