Previous Post: Create a Kubernetes Cluster on Oracle Cloud for free using Terraform
Credit: This guy is the man, https://github.com/itzg . He maintains https://github.com/itzg/minecraft-server-charts/tree/master/charts/minecraft which is just an epic Minecraft Helm chart.
If you already have a Kubernetes cluster that’s perfect, if not you can follow the previous post to get one for free on Oracle Cloud.
If you are not using Oracle cloud you will need to modify the minecraft/_terraform.tf file slightly to use whatever storage backend you want for the terraform state file.
So change:
backend "oci" {}
to something like
backend "s3" {}
Or whatever your preference might be. See https://developer.hashicorp.com/terraform/language/backend if you need guidance on how to choose and what it means.
Check out the repository https://github.com/saranicole/minecraft-oci-k8s with git. We will be using the minecraft directory.
git clone https://github.com/saranicole/minecraft-oci-k8s.git
cd oci-free-cloud-k8s/terraform/minecraft
You will need to create a backend.conf file, a general.auto.tfvars, a minecraft.auto.tfvars file and possibly an oracle.auto.tfvars file. Depending on how you want this to end up you will put different contents into these tfvars files.
backend.conf
namespace = "<<Storage Namespace>>"
bucket = "terraform-states"
key = "infra/minecraft.tfstate"
general.auto.tfvars
chart_version = "5.1.2"
If you are using Oracle Cloud, create the oracle.auto.tfvars file.
oracle.auto.tfars
compartment_id = << Tenancy OCID >>
region = << Region >>
ssh_public_key = << SSH Public Key >>
user_ocid = << User OCID >>
fingerprint = << API Key fingerprint >>
private_key_path = << Path to API Key Secret File >>
bucket_namespace = << Storage Namespace >>
If you want a vanilla Minecraft server, use the structure below and tweak as needed (making sure to change accept_eula to TRUE):
# Change this to TRUE
accept_eula = "FALSE"
world_version = "26.1.1"
server_type = "VANILLA"
fabric_loader_version = "0.18.6"
difficulty = "easy"
whitelist = "<< YOUR MINECRAFT USERNAME >>,<< SOME OTHER MINECRAFT USERNAME >>"
ops = "<< YOUR MINECRAFT USERNAME >>,<< SOME OTHER MINECRAFT USERNAME >>"
motd = "Welcome to Minecraft on Kubernetes!"
mod_urls = [
"<< MODRINTH JAR DIRECT DOWNLOAD URL >>",
"<< SOME OTHER JAR DIRECT DOWNLOAD URL >>"
]
download_world_url = "<< DIRECT DOWNLOAD LINK OF ZIP FILE CONTAINING WORLD DATA >>"
rclone_dest_dir = "<< OBJECT STORAGE BUCKET SUCH AS S3 OR OCI BUCKET NAME >>/<< OBJECT STORAGE BUCKET PREFIX SUCH AS 'worlds' >>"
enable_oci_backup_bucket = false
enable_oci_load_balancer = false
rcon_password = "<< SUPER SECRET PASSWORD >>"
If you want Cobblemon, particularly cobblemon on Meta Quest, you will need to use contents like the following:
minecraft.auto.tfvars
# Change this to TRUE
accept_eula = "FALSE"
world_version = "1.21.1"
server_type = "FABRIC"
fabric_loader_version = "0.18.6"
difficulty = "easy"
whitelist = "<< YOUR MINECRAFT USERNAME >>,<< SOME OTHER MINECRAFT USERNAME >>"
ops = "<< YOUR MINECRAFT USERNAME >>,<< SOME OTHER MINECRAFT USERNAME >>"
motd = "Welcome to Cobblemon on Kubernetes!"
mod_urls = [
"https://cdn.modrinth.com/data/MdwFAVRL/versions/Ygf8KJFC/Cobblemon-fabric-1.7.0%2B1.21.1.jar",
"https://cdn.modrinth.com/data/P7dR8mSH/versions/yGAe1owa/fabric-api-0.116.9%2B1.21.1.jar"
]
download_world_url = "<< DIRECT DOWNLOAD LINK OF ZIP FILE CONTAINING WORLD DATA >>"
rclone_dest_dir = "<< OBJECT STORAGE BUCKET SUCH AS S3 OR OCI BUCKET NAME >>/<< OBJECT STORAGE BUCKET PREFIX SUCH AS 'worlds' >>"
enable_oci_backup_bucket = false
enable_oci_load_balancer = false
rcon_password = "<< SUPER SECRET PASSWORD >>"
If you are using Oracle, you will want to change both enable_oci_backup_bucket and enable_oci_load_balancer to true.
In the case of Oracle the rclone_dest_dir will be “minecraft-backups/worlds”.
Run the init first to confirm that Terraform is working and make sure to inspect everything it will create.
terraform init -backend-config=backend.conf
Then run the plan
terraform plan
If there are any errors due to missing information, make sure your files are all filled out correctly.
Once the plan succeeds with no errors, you can apply the Terraform.
terraform apply
Enter “yes” when it prompts you.
It should finish like this:
Apply complete! Resources: xx added, 0 changed, 0 destroyed.
At the end you will see:
Outputs:
+ my_minecraft_server_ip = "xxx.xxx.xxx.xxx"
This is your Minecraft server ip address! Connect to port 25565 with this directly, or create a friendly DNS name in your preferred way.
If connecting with the ip address you can type in these numbers in this format:
xxx.xxx.xxx.xxx:25565
I recommend https://www.duckdns.org/ as a convenient way to give your Minecraft server a friendly url.
Way to go! You now have a Minecraft server in your preferred configuration set up on your Kubernetes cluster.
Interested in more? Take a look at the last blog post in this series:
