Skip to content

Latest commit

 

History

History

controller

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

Contributors Forks Stargazers Issues


Agones Minecraft DNS Controller

Custom Kubernetes controller for automating external DNS on Minecraft GameServers
Explore the docs »

View Example · Report Bug · Request Feature

Table of Contents

  1. About The Project
  2. Getting Started
  3. Usage
  4. Roadmap
  5. Contributing
  6. License
  7. Acknowledgements
  8. Author

About The Project

Custom Kubernetes controller for automating provisioning external DNS records for Minecraft GameServers using third-party cloud providers

Built With

Getting Started

To get the controller running:

docker run -it --rm saulmaldonado/agones-mc-dns-controller --gcp-project=<PROJECT_ID> --zone=<DNS_MANAGED_ZONE>

Prerequisites

You need a running GKE cluster running with Agones resources and controllers installed

  • GKE
gcloud container clusters create minecraft --cluster-version=1.18 \
  --tags=mc \
  --scopes=gke-default,"https://www.googleapis.com/auth/ndev.clouddns.readwrite" \
  --num-nodes=2 \
  --no-enable-autoupgrade \
  --machine-type=n2-standard-4
gcloud config set container/cluster minecraft
gcloud container clusters get-credentials minecraft
gcloud compute firewall-rules create mc-server-firewall \
  --allow tcp:7000-8000 \
  --target-tags mc \
  --description "Firewall rule to allow mc server tcp traffic"
  • Agones
kubectl create namespace agones-system
kubectl apply -f https://raw.githubusercontent.com/googleforgames/agones/release-1.13.0/install/yaml/install.yaml

Installation

kubectl apply -f https://raw.githubusercontent.com/saulmaldonado/agones-minecraft/main/k8s/agones-mc-dns-controller.yaml

apiVersion: v1
kind: ServiceAccount
metadata:
  name: agones-mc-dns
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: agones-mc-dns
rules:
  - apiGroups: ['agones.dev']
    resources: ['gameservers']
    verbs: ['get', 'watch', 'list', 'update']
  - apiGroups: ['']
    resources: ['nodes']
    verbs: ['get', 'watch', 'list', 'update']
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: agones-mc-dns-viewer
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: agones-mc-dns
subjects:
  - kind: ServiceAccount
    name: agones-mc-dns
    namespace: default
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: agones-mc-dns-controller
spec:
  strategy:
    type: Recreate
  selector:
    matchLabels:
      app: agones-mc-dns-controller
  template:
    metadata:
      labels:
        app: agones-mc-dns-controller
    spec:
      serviceAccountName: agones-mc-dns
      containers:
        - name: agones-mc-dns-controller
          image: saulmaldonado/agones-mc-dns-controller
          args:
            - --zone=<MANAGED_ZONE> # Replace with name of DNS managed zone
          imagePullPolicy: Always

Download from Docker Hub

docker pull saulmaldonado/agones-mc-dns-controller

Usage

This controller takes advantage of dynamic host port allocation that Agones provisions for GameServers. Instead of creating external DNS records for Kubernetes services and ingresses, DNS A and SRV are created to point to GameServer host nodes and the their GameServer ports.

Nodes

To provision an A record for Nodes, they need to contain a agones-mc/hostname: annotation that contains the domain for the current Managed Zone. This will indicate to the controller that the Node needs an A record.

This can be done using kubectl:

kubectl annotate node/<NODE_NAME> agones-mc/hostname=<DOMAIN>

The A record are generated with the name <NODE_NAME>.<DOMAIN>. New annotation with agones-mc/externalDNS will contain the new A record that points to the Node IP.

GameServer

To provision an SRV record for GameServers, they need to contain an agones-mc/hostname annotation that contains the domain for the current Managed Zone. This will indicate to the controller that the GameServer needs a SRV record.

GameServer Pod template example

template:
  metadata:
    annotations:
      agones-mc/hostname: <DOMAIN_NAME> # Domain name of the managed zone
      # agones-mc/externalDNS: <GAMESERVER_NAME>.<DOMAIN_NAME> # Will be added by the controller
  spec:
    containers:
      - name: mc-server
        image: itzg/minecraft-server # Minecraft server image
        imagePullPolicy: Always
        env: # Full list of ENV variables at https://github.com/itzg/docker-minecraft-server
          - name: EULA
            value: 'TRUE'

      - name: mc-monitor
        image: saulmaldonado/agones-mc-monitor # Agones monitor sidecar
        imagePullPolicy: Always

Once the pod has been created, a new SRV will be generated with the format _minecraft._tcp.<GAMESERVER_NAME>.<DOMAIN>. that points to the A record of the host Node 0 0 <PORT> <HOST_A_RECORD>.

A new annotation agones-mc/externalDNS will then be added to the GameServer containing the URL from which players can connect to.

For example: mc-server-cfwd7.saulmaldonado.me will connect to the Minecraft GameServer named mc-server-cfwd7 on its dynamically allocated port.

Run Locally with Docker

docker run -it --rm saulmaldonado/agones-mc-dns-controller --gcp-project=<PROJECT_ID> --zone=<DNS_MANAGED_ZONE> --kubeconfig=<KUBE_CONFIG_PATH>

Flags:

  --gcp-project string
        GCP project id
  --kubeconfig string
        Paths to a kubeconfig. Only required if out-of-cluster.
  --zone string
        DNS zone that the controller will manage

Roadmap

See the open issues for a list of proposed features (and known issues).

Contributing

Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are greatly appreciated.

  1. Fork the Project
  2. Clone the Project
  3. Create your Feature or Fix Branch (git checkout -b (feat|fix)/AmazingFeatureOrFix)
  4. Commit your Changes (git commit -m 'Add some AmazingFeatureOrFix')
  5. Push to the Branch (git push origin (feat|fix)/AmazingFeature)
  6. Open a Pull Request

Build from source

  1. Clone the repo

    git clone https://github.com/saulmaldonado/agones-minecraft.git
  2. Build

    make go-build

Build from Dockerfile

  1. Clone the repo

    git clone https://github.com/saulmaldonado/agones-minecraft.git
  2. Build

    docker build -t <hub-user>/agones-mc-dns-controller:latest ./controller
  3. Push to Docker repo

    docker push <hub-user>/agones-mc-dns-controller:latest

License

Distributed under the MIT License. See LICENSE for more information.

Acknowledgements

Author

Saul Maldonado

Show your support

Give a ⭐️ if this project helped you!