Setting up a minecraft server in kubernetes because it seemed like the first logical thing to do. Here is the setup:
Create the namespace first:
kind: Namespace
apiVersion: v1
metadata:
name: minecraft
labels:
name: minecraft
Then create the pvc for the pod to use (in this case I am using an openebs-hostpath storage class):
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: local-hostpath-mc-pvc
namespace: minecraft
spec:
storageClassName: openebs-hostpath
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 5G
After the pvc is created, create deployment using the pvc:
apiVersion: apps/v1
kind: Deployment
metadata:
name: minecraft-server-world0
namespace: minecraft
labels:
app: minecraft-server
spec:
strategy:
type: Recreate
replicas: 1
selector:
matchLabels:
app: minecraft-server
template:
metadata:
labels:
app: minecraft-server
spec:
volumes:
- name: minecraft-pv-world0
persistentVolumeClaim:
claimName: local-hostpath-mc-pvc
containers:
- name: minecraft-server
image: itzg/minecraft-server:latest
resources:
limits:
memory: 4Gi
requests:
memory: 2Gi
env:
- name: EULA
value: 'TRUE'
- name: MODE
value: creative
- name: MOTD
value: Welcome to Jack's Minecraft server
- name: ALLOW_FLIGHT
value: 'TRUE'
ports:
- containerPort: 25565
name: minecraft
volumeMounts:
- name: minecraft-pv-world0
mountPath: /data
#readinessProbe:
# exec:
# command:
# - mcstatus
# - 127.0.0.1
# - ping
# initialDelaySeconds: 30
# periodSeconds: 30
#livenessProbe:
# exec:
# command:
# - mcstatus
# - 127.0.0.1
# - ping
# initialDelaySeconds: 30
# periodSeconds: 30
After the deployment is created, create the service:
- note in this service I was thinking of using the load balancer at first, however switched to just using a normal service
- I go back to use a tcp gateway and use this as the service
apiVersion: v1
kind: Service
metadata:
name: mc-service
namespace: minecraft
spec:
selector:
app: minecraft-server
ports:
- protocol: TCP
port: 25565
targetPort: 25565
#type: LoadBalancer
#loadBalancerIP: 10.0.1.242
This is the gateway I used:
- Note in this I believe the TCPRoute kind is a CRD which possibly needs to be installed
apiVersion: gateway.networking.k8s.io/v1alpha2
kind: TCPRoute
metadata:
name: tcp-app-1
namespace: minecraft
labels:
gateway: my-gateway-class
spec:
parentRefs:
- name: my-gateway-class
sectionName: foo
rules:
- backendRefs:
- name: mc-service
port: 25565
From here I was able to apply all the files and open up a port from HAProxy to allow users to connect via tcp.
Links
- https://www.olivercoding.com/2021-04-24-kubernetes-minecraft/
- https://github.com/solarhess/kubernetes-minecraft-server
- https://kubernetes.io/docs/concepts/storage/persistent-volumes/
- https://cloud.google.com/blog/products/containers-kubernetes/kubernetes-best-practices-organizing-with-namespaces
- https://kubernetes.io/docs/concepts/services-networking/service/