Welcome!

Join our community of MMO enthusiasts and game developers! By registering, you'll gain access to discussions on the latest developments in MMO server files and collaborate with like-minded individuals. Join us today and unlock the potential of MMO server development!

Join Today!

Attempting to port GBS2 to Kubernetes

Initiate Mage
Joined
Aug 24, 2019
Messages
4
Reaction score
1
Hello everyone,

I'm going to attempt to build a fairly resilient, low-lag, and high availability GBS2 server. I don't have much going on right now so I figured this would be a fun project that could have a cool outcome.

Project name: Gunbound Clasic Cloud (GBCC)

Thanks to musashi076 as I'm referencing most of the files for this project from your tutorial.

--------------

I've rebuilt a beat-up old MacBook Pro to use as my dedicated Kubernetes compute/control (etcd) node. To accomplish this I will be using the minikube software for UNIX based machines.

Node specs: 8Gi Memory, 2 CPU cores, and 750Gi HDD

Considering most packages available to stand up GB servers are compressed into RAR archives I've installed the unrar package.

-------------

I've set-up a new directory on the server and called it GBCC and created a sub-directory called mysql_server - I'll UnRAR the Gb_Serv.rar archive in the GBCC directory and move all the .sql files to the mysql_server sub-directory.

Code:
mv Gb_Serv.rar ../Desktop/GBCC/
cd ../Desktop/GBCC
unrar x Gb_Serv.rar
mv Gb_Serv/DB/ mysql_server/

Now that I've isolated all the SQL files I want to be in my database I've create a deployment.yaml file and service.yaml for describing all the resources to be deployed to Kubernetes.

Code:
apiVersion: apps/v1
kind: Deployment
metadata:
  name: phpmyadmin-deployment
  labels:
    app: phpmyadmin
spec:
  replicas: 1
  selector:
    matchLabels:
      app: phpmyadmin
  template:
    metadata:
      labels:
        app: phpmyadmin
    spec:
      containers:
        - name: phpmyadmin
          image: phpmyadmin/phpmyadmin
          ports:
            - containerPort: 80
          env:
            - name: PMA_HOST
              value: mysql-service
            - name: PMA_PORT
              value: "3306"
            - name: MYSQL_ROOT_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: mysql-secrets
                  key: ROOT_PASSWORD

Code:
apiVersion: v1
kind: Service
metadata:
  name: phpmyadmin-service
spec:
  type: NodePort
  selector:
    app: phpmyadmin
  ports:
  - protocol: TCP
    port: 80
    targetPort: 80

I also needed to create a generic key,value secret Kubernetes resource to hold the MySQL password

Code:
kubectl create secret generic mysql-secrets \
--from-literal ROOT_PASSWORD=alpine

Code:
minikube start
kubectl create namespace gbcc
kubens gbcc
kubectl create -f mysql_server/deployment.yaml
kubectl create -f mysql_server/service.yaml

For now Minikube has an odd way of managin NodePort type ingress so the "External-IP" shows pending.

How to get phpMyAdmin URL
Code:
minikube service --url phpmyadmin-service -n gbcc

Here is a snapshot of our GBCC in the cloud so far!
Code:
NAME                                         READY   STATUS    RESTARTS   AGE
pod/phpmyadmin-deployment-55594bcfb5-tmfx5   1/1     Running   0          20s


NAME                         TYPE       CLUSTER-IP      EXTERNAL-IP   PORT(S)        AGE
service/phpmyadmin-service   NodePort   10.97.198.225   <none>        80:31043/TCP   10s


NAME                                    READY   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/phpmyadmin-deployment   1/1     1            1           20s

NAME                                               DESIRED   CURRENT   READY   AGE
replicaset.apps/phpmyadmin-deployment-55594bcfb5   1         1         1       20s

If you notice I can up the replicas of phpMyAdmin/MySQL server instances greatly increasing the volume of traffic I can handle to that service.

Here is what we have so far...Stay tuned for more to come...This was the easy part (I think)

screnshots:
magicparty - Attempting to port GBS2 to Kubernetes - RaGEZONE Forums

magicparty - Attempting to port GBS2 to Kubernetes - RaGEZONE Forums

magicparty - Attempting to port GBS2 to Kubernetes - RaGEZONE Forums
 
Last edited:
Initiate Mage
Joined
Aug 24, 2019
Messages
4
Reaction score
1
Update:

I was under the impression that the phpMyAdmin images I was using had a MySQL server built into them as well...apparently not...

To fix this I had to deploy a separate MySQL server pod with service - also I've created a PersistentVolume for the database. Everything is working fine now and all Gunbound SQL databases and tables have been created/imported!

updated YAML files:

deployment.yaml
Code:
apiVersion: apps/v1
kind: Deployment
metadata:
  name: phpmyadmin-deployment
  labels:
    app: phpmyadmin
spec:
  replicas: 1
  selector:
    matchLabels:
      app: phpmyadmin
  template:
    metadata:
      labels:
        app: phpmyadmin
    spec:
      containers:
        - name: phpmyadmin
          image: phpmyadmin/phpmyadmin
          ports:
            - containerPort: 80
          env:
            - name: PMA_HOST
              value: mysql
            - name: PMA_PORT
              value: "3306"
            - name: MYSQL_ROOT_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: mysql-secrets
                  key: alpine
---
apiVersion: apps/v1 # for versions before 1.9.0 use apps/v1beta2
kind: Deployment
metadata:
  name: mysql
spec:
  selector:
    matchLabels:
      app: mysql
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: mysql
    spec:
      containers:
      - image: mysql:5.6
        name: mysql
        env:
        - name: MYSQL_ROOT_PASSWORD
          valueFrom:
                secretKeyRef:
                  name: mysql-secrets
                  key: alpine
        ports:
        - containerPort: 3306
          name: mysql
        volumeMounts:
        - name: mysql-persistent-storage
          mountPath: /var/lib/mysql
      volumes:
      - name: mysql-persistent-storage
        persistentVolumeClaim:
          claimName: mysql-pv-claim

service.yaml
Code:
apiVersion: v1
kind: Service
metadata:
  name: phpmyadmin-service
spec:
  type: NodePort
  selector:
    app: phpmyadmin
  ports:
  - protocol: TCP
    port: 80
    targetPort: 80
---
apiVersion: v1
kind: Service
metadata:
  name: mysql
spec:
  ports:
  - port: 3306
  selector:
    app: mysql
  clusterIP: None
---
apiVersion: v1
kind: Service
metadata:
  name: mysql-service
spec:
  type: NodePort
  selector:
    app: mysql
  ports:
  - protocol: TCP
    port: 3306
    targetPort: 3306

pv.yaml
Code:
apiVersion: v1
kind: PersistentVolume
metadata:
  name: mysql-pv-volume
  labels:
    type: local
spec:
  storageClassName: manual
  capacity:
    storage: 20Gi
  accessModes:
    - ReadWriteOnce
  hostPath:
    path: "/mnt/data"
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: mysql-pv-claim
spec:
  storageClassName: manual
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 20Gi

---

I'm now attempting to containerize the webfiles with the registration page etc. I've successfully done this via. building my own Apache2 Dockerfile/image. I've created a directory called registration and a subdirectory webfiles.

In the registration directory I've created this Dockerfile
Code:
FROM php:7.1-apache

MAINTAINER magicparty
WORKDIR gbcc

COPY ./webfiles/ gb/

RUN sed -i "s/Listen 80/Listen ${PORT:-80}/g" /etc/apache2/ports.conf; \
    sed -i "s/:80/:${PORT:-80}/g" /etc/apache2/sites-enabled/*;

RUN mv gb/ /var/www/html/

EXPOSE 80

CMD apache2-foreground

and built/deployed the image gb_registration:latest

Code:
docker build -t gb_registration .
docker run -d -p 80:80 gb_registration:latest

PHP works fine from here but there is one issue with the MySQL connection call on the registration.php page...I will have to debug this part and probably modify it slightly to get it to connect to my Kubernetes instance of the MySQL server.

Great progress so far!

---

Thinking ahead at the challenge of running the windows applications for the actual server itself within a container. Should be interesting and quite difficult to get working just right.



Small update:

I've ported all the mysql_* functions to mysqli_* functions in both the online.php and registration.php

Also I've identified the external IP/PORT from Kubernetes for the MySQL database server. (In my case this was 192.168.64.2:30594)

Lastly the container needed an extra dependency to enable the mysqli extension for Apache2 PHP7

The registration form works just fine now and I can see the data inserted into the gunbound database in the user table.

Final Dockerfile:
Code:
FROM php:7.1-apache

MAINTAINER magicparty
WORKDIR gbcc

COPY ./webfiles/ gb/

RUN sed -i "s/Listen 80/Listen ${PORT:-80}/g" /etc/apache2/ports.conf; \
    sed -i "s/:80/:${PORT:-80}/g" /etc/apache2/sites-enabled/*; \
    docker-php-ext-install mysqli; \
    docker-php-ext-enable mysqli;

RUN mv gb/ /var/www/html/

EXPOSE 80

CMD apache2-foreground

For some reason I get thrown a mysqli_fetch error and a mysqli_query empty error but these don't seem to cause any issues (so far). I will debug these minor problems soon...

some screenshots
magicparty - Attempting to port GBS2 to Kubernetes - RaGEZONE Forums
magicparty - Attempting to port GBS2 to Kubernetes - RaGEZONE Forums
magicparty - Attempting to port GBS2 to Kubernetes - RaGEZONE Forums
 
Initiate Mage
Joined
Aug 24, 2019
Messages
4
Reaction score
1
Update: Issues resolved with mysql_query / mysql_fetch!

For fetch we changed MYSQL_ASSOC to MYSQLI_ASSOC and the empty query fail was due to superuser set to false...no more warnings/errors and I can create super user accounts no problem!



The toughest challenge is here - I need to run the install/server .exe's within a container...issue is that docker containers are micro-sized Linux machines. There is such thing as Windows containers that can be spun up using Docker (I'm not sure about Kubernetes) but we are building this on a linux-amd64 machine (Mac OSX).

I will have to either build a VirtualMachine in vBox running a Windows Server just to run the gunbound server container...which would also require me to probably do some tricky network configurations to get all these pieces talking to each other properly...OR...build a completely custom image with wine installed to run the applications which will probably also be fairly tricky...BUT...if successful it will allow me to deploy it to the Kubernetes cluster with all the other resources built so far in the same namespace - also saves me greatly on compute resources since I wont have to run a full blown Windows Server VM.

- update from here might be a little while!
 
Back
Top