diff --git a/charts/minecraft/Chart.yaml b/charts/minecraft/Chart.yaml index aeb459dd..b73c38cf 100755 --- a/charts/minecraft/Chart.yaml +++ b/charts/minecraft/Chart.yaml @@ -1,6 +1,6 @@ apiVersion: v1 name: minecraft -version: 2.0.8 +version: 2.0.9 appVersion: SeeValues home: https://minecraft.net/ description: Minecraft server diff --git a/charts/minecraft/templates/deployment.yaml b/charts/minecraft/templates/deployment.yaml index 73801e70..f22bc86f 100644 --- a/charts/minecraft/templates/deployment.yaml +++ b/charts/minecraft/templates/deployment.yaml @@ -35,7 +35,57 @@ spec: runAsUser: {{ .Values.securityContext.runAsUser }} fsGroup: {{ .Values.securityContext.fsGroup }} containers: - - name: {{ template "minecraft.fullname" . }} + {{- if .Values.monitor.enabled }} + - name: mc-monitor + image: "{{ .Values.monitor.image }}:{{ .Values.monitor.imageTag }}" + imagePullPolicy: Always + resources: +{{ toYaml .Values.monitor.resources | indent 10 }} + args: + - {{ .Values.monitor.command }} + env: + {{- if eq .Values.monitor.command "gather-for-telegraf" }} + - name: GATHER_INTERVAL + value: {{ default "10s" .Values.monitor.gather_interval | quote }} + + - name: GATHER_TELEGRAF_ADDRESS + value: {{ .Values.monitor.gather_telegraf_address }} + + - name: GATHER_SERVERS + value: {{ default ":25565" .Values.monitor.gather_servers | quote }} + {{- end }} + {{- if eq .Values.monitor.command "export-for-prometheus" }} + - name: EXPORT_PORT + value: "9225" + + - name: EXPORT_SERVERS + value: |- + {{ range $index, $host := .Values.monitor.prometheus.export_servers }} + {{- if $index }},{{ end }}{{ $host }} + {{- end }} + + - name: EXPORT_BEDROCK_SERVERS + value: |- + {{ range $index, $host := .Values.monitor.prometheus.export_bedrock_servers }} + {{- if $index }},{{ end }}{{ $host }} + {{- end }} + - name: DEBUG + value: {{ default "false" .Values.monitor.prometheus.debug | quote }} + {{- end }} + + {{- range $key, $value := .Values.monitor.extraEnv }} + - name: {{ $key }} + value: {{ $value | quote }} + {{- end }} + + {{- if eq .Values.monitor.command "export-for-prometheus" }} + ports: + - name: monitor + containerPort: 9225 + protocol: TCP + {{- end }} + {{- end }} + - name: minecraft-server image: "{{ .Values.image }}:{{ .Values.imageTag }}" imagePullPolicy: Always resources: @@ -192,6 +242,11 @@ spec: containerPort: {{ .Values.minecraftServer.rcon.port }} protocol: TCP {{- end }} + {{- if .Values.prometheus_exporter.enabled }} + - name: monitor + containerPort: {{ .Values.prometheus_exporter.port }} + protocol: TCP + {{- end }} volumeMounts: - name: datadir mountPath: /data diff --git a/charts/minecraft/templates/minecraft-svc.yaml b/charts/minecraft/templates/minecraft-svc.yaml index 166cc6be..67edb0c8 100644 --- a/charts/minecraft/templates/minecraft-svc.yaml +++ b/charts/minecraft/templates/minecraft-svc.yaml @@ -7,6 +7,8 @@ metadata: chart: "{{ .Chart.Name }}-{{ .Chart.Version }}" release: "{{ .Release.Name }}" heritage: "{{ .Release.Service }}" + annotations: +{{ toYaml .Values.minecraftServer.serviceAnnotations | indent 4 }} spec: {{- if (or (eq .Values.minecraftServer.serviceType "ClusterIP") (empty .Values.minecraftServer.serviceType)) }} type: ClusterIP diff --git a/charts/minecraft/templates/servicemonitor.yml b/charts/minecraft/templates/servicemonitor.yml new file mode 100644 index 00000000..f69cd6f9 --- /dev/null +++ b/charts/minecraft/templates/servicemonitor.yml @@ -0,0 +1,40 @@ +{{- if .Values.servicemonitor.enabled }} +apiVersion: monitoring.coreos.com/v1 +kind: ServiceMonitor +metadata: + name: {{ template "minecraft.fullname" . }} +{{- if .Values.servicemonitor.namespace }} + namespace: {{ .Values.servicemonitor.namespace }} +{{- else }} + namespace: {{ .Release.Namespace | quote }} +{{- end }} + labels: + app: {{ template "minecraft.fullname" . }} + chart: "{{ .Chart.Name }}-{{ .Chart.Version }}" + release: "{{ .Release.Name }}" + heritage: "{{ .Release.Service }}" + prometheus: {{ .Values.servicemonitor.prometheusInstance }} +{{- if .Values.servicemonitor.labels }} +{{ toYaml .Values.servicemonitor.labels | indent 4}} +{{- end }} +spec: + jobLabel: {{ template "minecraft.fullname" . }} + selector: + matchLabels: + app: {{ template "minecraft.fullname" . }} + chart: "{{ .Chart.Name }}-{{ .Chart.Version }}" + release: "{{ .Release.Name }}" + heritage: "{{ .Release.Service }}" + namespaceSelector: + matchNames: + - {{ .Release.Namespace }} + endpoints: + - targetPort: {{ .Values.servicemonitor.targetPort }} + path: {{ .Values.servicemonitor.path }} + interval: {{ .Values.servicemonitor.interval }} + scrapeTimeout: {{ .Values.servicemonitor.scrapeTimeout }} + relabelings: + - sourceLabels: ['__address__'] + targetLabel: 'server_name' + replacement: '{{ template "minecraft.fullname" . }}' +{{- end }} diff --git a/charts/minecraft/values.yaml b/charts/minecraft/values.yaml index 9430e9ff..ea812f9d 100644 --- a/charts/minecraft/values.yaml +++ b/charts/minecraft/values.yaml @@ -127,6 +127,11 @@ minecraftServer: # Options like -X that need to proceed general JVM options jvmXXOpts: "" serviceAnnotations: {} + # Routes Minecraft client connections to backend servers + # https://github.com/itzg/mc-router + # "mc-router.itzg.me/externalServerName": "mc-stable.example.com" + # Let External DNS auto create DNS record + # "external-dns.alpha.kubernetes.io/hostname": "mc-stable.example.com" serviceType: ClusterIP loadBalancerIP: # loadBalancerSourceRanges: [] @@ -151,6 +156,57 @@ minecraftServer: enabled: false port: 25565 +prometheus_exporter: + # If you enable this, make SURE to install Prometheus Exporter. + # Plugin for bukkit server + # and change plugin's config to listen on 0.0.0.0 + # https://dev.bukkit.org/projects/prometheus-exporter + # Mod for Forge server + # https://www.curseforge.com/minecraft/mc-mods/prometheus-exporter + enabled: false + # Prometheus Exporter Plugin: 9225 + # Prometheus Exporter Mod: 19125 + port: 9225 + +# If you enable this, make SURE to install Prometheus Operator. +# https://github.com/prometheus-operator/prometheus-operator +servicemonitor: + enabled: false + prometheusInstance: default + labels: {} + # Prometheus Exporter Plugin: 9225 + # Prometheus Exporter Mod: 19125 + targetPort: 9225 + path: /metrics + interval: 15s + scrapeTimeout: 10s + +monitor: + enabled: false + image: itzg/mc-monitor + imageTag: latest + # Command: export-for-prometheus or gather-for-telegraf + command: export-for-prometheus + telegraf: + gather_interval: 10s + gather_telegraf_address: telegraf:8094 + prometheus: + port: 9225 + # List of Java edition servers + export_servers: + - localhost:25565 + export_bedrock_servers: [] + debug: false + resources: + requests: + cpu: 100m + memory: 200Mi + limits: + cpu: 300m + memory: 400Mi + + + ## Additional minecraft container environment variables ## extraEnv: {}