Added factorio

This commit is contained in:
Jonathan Ervine 2020-08-12 12:32:21 +08:00
parent a51dd0615b
commit 56d66cf204
13 changed files with 433 additions and 2 deletions

View File

@ -14,10 +14,10 @@ type: application
# This is the chart version. This version number should be incremented each time you make changes # This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version. # to the chart and its templates, including the app version.
version: 0.1.4 version: 0.1.5
# This is the version number of the application being deployed. This version number should be # This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. # incremented each time you make changes to the application.
appVersion: 1.16.1.02 appVersion: 1.16.20.03
icon: https://git.ervine.org/jonny/x86_64-debian-bedrock/raw/branch/master/bedrock.jpg icon: https://git.ervine.org/jonny/x86_64-debian-bedrock/raw/branch/master/bedrock.jpg

21
factorio/.helmignore Executable file
View File

@ -0,0 +1,21 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*~
# Various IDEs
.project
.idea/
*.tmproj

15
factorio/Chart.yaml Executable file
View File

@ -0,0 +1,15 @@
apiVersion: v1
appVersion: 0.17.79
description: Factorio dedicated server.
home: https://www.factorio.com/
icon: https://us1.factorio.com/assets/img/factorio-logo.png
keywords:
- game
- server
maintainers:
- email: docker@ervine.org
name: Jonathan
name: factorio
sources:
- https://git.ervine.org/jonny/x86_64-suse-factorio
version: 1.0.0

71
factorio/README.md Executable file
View File

@ -0,0 +1,71 @@
# Factorio
[Factorio](https://www.factorio.com/) is a game in which you build and maintain factories.
## Introduction
This chart creates a single [Factorio Headless](https://www.factorio.com/download-headless) Pod, plus Services for the Factorio server and RCON.
## Prerequisites
- Kubernetes 1.4+ with Beta APIs enabled
- PV provisioner support in the underlying infrastructure
## Provider-specific Prerequisites
Amazon's Elastic Loadbalancer lacks support for UDP. You'll need to set `factorioServer.ServiceType` to `NodePort` and expose the port that gets selected (see `kubectl describe svc <servicename>`) via a security group. You may need to do something similar for certain bare metal deployments.
You need not worry about this on Google Cloud Platform.
## Installing the Chart
To install the chart with the release name `my-release`:
```bash
$ helm install --name my-release stable/factorio
```
This command deploys a Factorio dedicated server with sane defaults.
> **Tip**: List all releases using `helm list`
## Uninstalling the Chart
To uninstall/delete the `my-release` deployment:
```bash
$ helm delete my-release
```
The command removes all the Kubernetes components associated with the chart and deletes the release.
## Configuration
Refer to [values.yaml](values.yaml) for the full run-down on defaults. These are a mixture of Kubernetes and Factorio-related directives that map to environment variables in [docker-factorio](https://github.com/games-on-k8s/docker-factorio).
Specify each parameter using the `--set key=value[,key=value]` argument to `helm install`. For example,
```bash
$ helm install --name my-release \
--set factorioServer.factorioServer=My Server,ImageTag=0.15.39 \
stable/factorio
```
The above command deploys Factorio dedicated with a server name of `My Server` and docker-factorio image version `0.15.39`.
Alternatively, a YAML file that specifies the values for the parameters can be provided while installing the chart. For example,
```bash
$ helm install --name my-release -f values.yaml stable/factorio
```
> **Tip**: You can use the default [values.yaml](values.yaml)
## Persistence
The [docker-factorio](https://github.com/games-on-k8s/docker-factorio) image stores the saved games and mods under /opt/factorio.
By default a PersistentVolumeClaim is created and mounted for saves but not mods. In order to disable this functionality
you can change the values.yaml to disable persistence under the sub-sections under `Persistence`.
> *"An emptyDir volume is first created when a Pod is assigned to a Node, and exists as long as that Pod is running on that node. When a Pod is removed from a node for any reason, the data in the emptyDir is deleted forever."*

40
factorio/templates/NOTES.txt Executable file
View File

@ -0,0 +1,40 @@
Get the IP address of your Factorio server by running these commands in the
same shell:
{{- if contains "NodePort" .Values.factorioServer.serviceType }}
export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} \
-o jsonpath="{.spec.ports[0].nodePort}" services {{ template "factorio.fullname" . }})
export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} \
-o jsonpath="{.items[0].status.addresses[0].address}")
echo "You'll need to expose this node through your security groups/firewall"
echo "for it to be world-accessible."
echo $NODE_IP:$NODE_PORT
{{- else if contains "LoadBalancer" .Values.factorioServer.serviceType }}
!! NOTE: It may take a few minutes for the LoadBalancer IP to be available.
!! NOTE: If you installed this on an AWS cluster, your game will be
un-reachable. AWS ELB does not support UDP. You'll need to use a NodePort
value for factorioServer.serviceType. See the README.md for more info.
You can watch for EXTERNAL-IP to populate by running:
kubectl get svc --namespace {{ .Release.Namespace }} -w {{ template "factorio.fullname" . }}
{{- else if contains "ClusterIP" .Values.factorioServer.serviceType }}
export POD_NAME=$(kubectl get pods \
--namespace {{ .Release.Namespace }} \
-l "component={{ template "factorio.fullname" . }}" \
-o jsonpath="{.items[0].metadata.name}")
kubectl port-forward $POD_NAME 34197:34197
echo "Point your Minecraft client at 127.0.0.1:34197"
{{- end }}
{{- if .Values.persistence.savedGames.enabled }}
{{- else }}
############################################################################
### WARNING: Persistence is disabled!!! You will lose your game state ###
### when the Factorio pod is terminated. ###
### See values.yaml's Persistence.SavedGames.Enabled directive. ###
############################################################################
{{- end }}

16
factorio/templates/_helpers.tpl Executable file
View File

@ -0,0 +1,16 @@
{{/* vim: set filetype=mustache: */}}
{{/*
Expand the name of the chart.
*/}}
{{- define "factorio.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}}
{{- end -}}
{{/*
Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
*/}}
{{- define "factorio.fullname" -}}
{{- $name := default .Chart.Name .Values.nameOverride -}}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}}
{{- end -}}

View File

@ -0,0 +1,101 @@
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: {{ template "factorio.fullname" . }}
labels:
app: {{ template "factorio.fullname" . }}
chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
release: "{{ .Release.Name }}"
heritage: "{{ .Release.Service }}"
spec:
template:
metadata:
labels:
app: {{ template "factorio.fullname" . }}
spec:
containers:
- name: {{ template "factorio.fullname" . }}
image: "{{ .Values.image }}:{{ .Values.imageTag }}"
imagePullPolicy: Always
resources:
{{ toYaml .Values.resources | indent 10 }}
env:
- name: FACTORIO_SERVER_NAME
value: {{ .Values.factorioServer.name | quote }}
- name: FACTORIO_DESCRIPTION
value: {{ .Values.factorioServer.description | quote }}
- name: FACTORIO_PORT
value: {{ .Values.factorioServer.port | quote }}
- name: FACTORIO_MAX_PLAYERS
value: {{ .Values.factorioServer.maxPlayers | quote }}
- name: FACTORIO_IS_PUBLIC
value: {{ .Values.factorioServer.isPublic | quote }}
- name: FACTORIO_REQUIRE_USER_VERIFICATION
value: {{ .Values.factorioServer.verifyIdentity | quote }}
- name: FACTORIO_ALLOW_COMMANDS
value: {{ .Values.factorioServer.allowCommands | quote }}
- name: FACTORIO_NO_AUTO_PAUSE
value: {{ .Values.factorioServer.noAutoPause | quote }}
- name: FACTORIO_AUTOSAVE_INTERVAL
value: {{ .Values.factorioServer.autosave.interval | quote }}
- name: FACTORIO_AUTOSAVE_SLOTS
value: {{ .Values.factorioServer.autosave.slots | quote }}
{{- if .Values.factorioServer.password }}
- name: FACTORIO_GAME_PASSWORD
valueFrom:
secretKeyRef:
name: {{ template "factorio.fullname" . }}
key: server-password
{{- end }}
{{- if .Values.factorioServer.isPublic }}
- name: FACTORIO_USER_USERNAME
valueFrom:
secretKeyRef:
name: {{ template "factorio.fullname" . }}
key: factorio-username
- name: FACTORIO_USER_PASSWORD
valueFrom:
secretKeyRef:
name: {{ template "factorio.fullname" . }}
key: factorio-password
{{- end }}
{{- if .Values.factorioServer.rcon.enabled }}
- name: FACTORIO_RCON_PASSWORD
valueFrom:
secretKeyRef:
name: {{ template "factorio.fullname" . }}
key: rcon-password
{{- end }}
ports:
- name: factorio
containerPort: 34197
protocol: UDP
{{- if .Values.factorioServer.rcon.enabled }}
- name: rcon
containerPort: {{ .Values.factorioServer.rcon.port }}
protocol: TCP
{{- end }}
volumeMounts:
- name: saves
mountPath: /opt/factorio/saves
- name: mods
mountPath: /opt/factorio/mods
volumes:
- name: saves
{{- if .Values.persistence.savedGames.enabled }}
persistentVolumeClaim:
claimName: {{ template "factorio.fullname" . }}-savedgames
{{- else }}
emptyDir: {}
{{- end }}
- name: mods
{{- if .Values.persistence.mods.enabled }}
persistentVolumeClaim:
claimName: {{ template "factorio.fullname" . }}-mods
{{- else }}
emptyDir: {}
{{- end }}

View File

@ -0,0 +1,18 @@
apiVersion: v1
kind: Service
metadata:
name: {{ template "factorio.fullname" . }}
labels:
app: {{ template "factorio.fullname" . }}
chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
release: "{{ .Release.Name }}"
heritage: "{{ .Release.Service }}"
spec:
type: {{ .Values.factorioServer.serviceType }}
ports:
- name: factorio
port: {{ .Values.factorioServer.port | int }}
targetPort: factorio
protocol: UDP
selector:
app: {{ template "factorio.fullname" . }}

View File

@ -0,0 +1,24 @@
{{- if .Values.persistence.mods.enabled -}}
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: {{ template "factorio.fullname" . }}-mods
labels:
app: {{ template "factorio.fullname" . }}
chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
release: "{{ .Release.Name }}"
heritage: "{{ .Release.Service }}"
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: {{ .Values.persistence.mods.size | quote }}
{{- if .Values.persistence.storageClass }}
{{- if (eq "-" .Values.persistence.storageClass) }}
storageClassName: ""
{{- else }}
storageClassName: "{{ .Values.persistence.storageClass }}"
{{- end }}
{{- end }}
{{- end -}}

View File

@ -0,0 +1,20 @@
{{- if default "" .Values.factorioServer.rcon.enabled }}
apiVersion: v1
kind: Service
metadata:
name: "{{ template "factorio.fullname" . }}-rcon"
labels:
app: {{ template "factorio.fullname" . }}
chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
release: "{{ .Release.Name }}"
heritage: "{{ .Release.Service }}"
spec:
type: {{ .Values.factorioServer.rcon.serviceType }}
ports:
- name: rcon
port: {{ .Values.factorioServer.rcon.port }}
targetPort: rcon
protocol: TCP
selector:
app: {{ template "factorio.fullname" . }}
{{- end }}

View File

@ -0,0 +1,24 @@
{{- if .Values.persistence.savedGames.enabled -}}
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: {{ template "factorio.fullname" . }}-savedgames
labels:
app: {{ template "factorio.fullname" . }}
chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
release: "{{ .Release.Name }}"
heritage: "{{ .Release.Service }}"
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: {{ .Values.persistence.savedGames.size | quote }}
{{- if .Values.persistence.storageClass }}
{{- if (eq "-" .Values.persistence.storageClass) }}
storageClassName: ""
{{- else }}
storageClassName: "{{ .Values.persistence.storageClass }}"
{{- end }}
{{- end }}
{{- end -}}

15
factorio/templates/secrets.yaml Executable file
View File

@ -0,0 +1,15 @@
apiVersion: v1
kind: Secret
metadata:
name: {{ template "factorio.fullname" . }}
labels:
app: {{ template "factorio.fullname" . }}
chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
release: "{{ .Release.Name }}"
heritage: "{{ .Release.Service }}"
type: Opaque
data:
server-password: {{ default "" .Values.factorioServer.password | b64enc | quote }}
rcon-password: {{ default "" .Values.factorioServer.rcon.password | b64enc | quote }}
factorio-username: {{ default "" .Values.factorio.user.username | b64enc | quote }}
factorio-password: {{ default "" .Values.factorio.user.password | b64enc | quote }}

66
factorio/values.yaml Executable file
View File

@ -0,0 +1,66 @@
# Factorio image version
# ref: https://quay.io/repository/games_on_k8s/factorio?tab=tags
image: harbor.ervine.dev/public/x86_64/suse/factorio
imageTag: 0.17.79
# Configure resource requests and limits
# ref: http://kubernetes.io/docs/user-guide/compute-resources/
resources:
requests:
memory: 512Mi
cpu: 500m
# Most of these map to environment variables. See docker-factorio for details:
# https://github.com/games-on-k8s/docker-factorio/blob/master/README.md#environment-variable-reference
factorioServer:
name: Kubernetes Server
description: Factorio running on Kubernetes
port: 34197
# Lock this server down with a password.
# password: change.me
maxPlayers: 255
# Publishes this server in the server browser if true.
# You'll want to set Factorio.User below if true, as it becomes required.
isPublic: false
verifyIdentity: false
# Allows or disallows console commands. Must be one of: `true`, `false`, or `admins-only`.
allowCommands: admins-only
# Pause the server when nobody is connected?
noAutoPause: "false"
# You'll want to change this to NodePort if you are on AWS.
serviceType: ClusterIP
autosave:
# Auto-save interval in minutes.
interval: 2
slots: 3
rcon:
enabled: false
port: 27015
# Empty value here enables an auto-generated password.
password: ""
serviceType: ClusterIP
factorio:
# Your factorio.com User/pass is needed if factorioServer.IsPublic is true.
user:
username: your.username
password: your.password
persistence:
## factorio data Persistent Volume Storage Class
## If defined, storageClassName: <storageClass>
## If set to "-", storageClassName: "", which disables dynamic provisioning
## If undefined (the default) or set to null, no storageClassName spec is
## set, choosing the default provisioner. (gp2 on AWS, standard on
## GKE, AWS & OpenStack)
##
storageClass: "nfs-client-hestia"
savedGames:
# Set this to false if you don't care to persist saved games between restarts.
enabled: true
size: 1Gi
mods:
enabled: true
size: 128Mi