From bd53c6b7f7045746f6638a07a2765be55db96d34 Mon Sep 17 00:00:00 2001 From: Caspar Chou Date: Mon, 2 Nov 2020 11:49:33 +0800 Subject: [PATCH 1/4] add prometheus exporter for minecraft --- charts/minecraft/templates/deployment.yaml | 7 ++++ charts/minecraft/templates/servicemonitor.yml | 36 +++++++++++++++++++ charts/minecraft/values.yaml | 17 +++++++++ 3 files changed, 60 insertions(+) create mode 100644 charts/minecraft/templates/servicemonitor.yml diff --git a/charts/minecraft/templates/deployment.yaml b/charts/minecraft/templates/deployment.yaml index 73801e70..e3329c8f 100644 --- a/charts/minecraft/templates/deployment.yaml +++ b/charts/minecraft/templates/deployment.yaml @@ -161,6 +161,13 @@ spec: - name: JVM_XX_OPTS value: {{ .Values.minecraftServer.jvmXXOpts | quote }} + + {{- if .Values.minecraftServer.monitor.enabled }} + - name: monitor + containerPort: {{ .Values.minecraftServer.monitor.port }} + protocol: TCP + {{- end }} + {{- if .Values.minecraftServer.rcon.enabled }} - name: ENABLE_RCON value: "true" diff --git a/charts/minecraft/templates/servicemonitor.yml b/charts/minecraft/templates/servicemonitor.yml new file mode 100644 index 00000000..c271848f --- /dev/null +++ b/charts/minecraft/templates/servicemonitor.yml @@ -0,0 +1,36 @@ +{{- if and .Values.minecraftServer.monitor.enabled .Values.minecraftServer.monitor.servicemonitor.enabled }} +apiVersion: monitoring.coreos.com/v1 +kind: ServiceMonitor +metadata: + name: {{ template "minecraft.fullname" . }} +{{- if .Values.minecraftServer.monitor.servicemonitor.namespace }} + namespace: {{ .Values.minecraftServer.monitor.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.minecraftServer.monitor.servicemonitor.prometheusInstance }} +{{- if .Values.minecraftServer.monitor.servicemonitor.labels }} +{{ toYaml .Values.minecraftServer.monitor.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.minecraftServer.monitor.servicemonitor.targetPort }} + path: {{ .Values.minecraftServer.monitor.servicemonitor.path }} + interval: {{ .Values.minecraftServer.monitor.servicemonitor.interval }} + scrapeTimeout: {{ .Values.minecraftServer.monitor.servicemonitor.scrapeTimeout }} +{{- end }} \ No newline at end of file diff --git a/charts/minecraft/values.yaml b/charts/minecraft/values.yaml index 9430e9ff..9aabff31 100644 --- a/charts/minecraft/values.yaml +++ b/charts/minecraft/values.yaml @@ -134,6 +134,23 @@ minecraftServer: # externalTrafficPolicy: Cluster externalIPs: + monitor: + # If you enable this, make SURE to install Prometheus Exporter. + # and change plugin's config to listen on 0.0.0.0 + # https://dev.bukkit.org/projects/prometheus-exporter + enabled: false + 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: {} + targetPort: 9225 + path: /metrics + interval: 15s + scrapeTimeout: 10s + rcon: # If you enable this, make SURE to change your password below. enabled: false From 3cdf17974d53fcb5f8d0d69d61b4caa0f6517484 Mon Sep 17 00:00:00 2001 From: Caspar Chou Date: Mon, 2 Nov 2020 12:40:57 +0800 Subject: [PATCH 2/4] add server_name label fullfill grafana dashboard --- charts/minecraft/templates/servicemonitor.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/charts/minecraft/templates/servicemonitor.yml b/charts/minecraft/templates/servicemonitor.yml index c271848f..acfd24e8 100644 --- a/charts/minecraft/templates/servicemonitor.yml +++ b/charts/minecraft/templates/servicemonitor.yml @@ -33,4 +33,8 @@ spec: path: {{ .Values.minecraftServer.monitor.servicemonitor.path }} interval: {{ .Values.minecraftServer.monitor.servicemonitor.interval }} scrapeTimeout: {{ .Values.minecraftServer.monitor.servicemonitor.scrapeTimeout }} + relabelings: + - sourceLabels: ['__address__'] + targetLabel: 'server_name' + replacement: '{{ template "minecraft.fullname" . }}' {{- end }} \ No newline at end of file From e7d33026279beb36eb36c48b054e8df92379c20d Mon Sep 17 00:00:00 2001 From: Caspar Chou Date: Mon, 2 Nov 2020 12:48:29 +0800 Subject: [PATCH 3/4] fix chart version for lint: CheckVersionIncrement --- charts/minecraft/Chart.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From a26775f82de750f7dbc8428a177e14aba6ccce28 Mon Sep 17 00:00:00 2001 From: Caspar Chou Date: Mon, 9 Nov 2020 12:50:27 +0800 Subject: [PATCH 4/4] add mc-monitor, forge prom --- charts/minecraft/templates/deployment.yaml | 64 ++++++++++++++-- charts/minecraft/templates/minecraft-svc.yaml | 2 + charts/minecraft/templates/servicemonitor.yml | 22 +++--- charts/minecraft/values.yaml | 73 ++++++++++++++----- 4 files changed, 125 insertions(+), 36 deletions(-) diff --git a/charts/minecraft/templates/deployment.yaml b/charts/minecraft/templates/deployment.yaml index e3329c8f..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: @@ -161,13 +211,6 @@ spec: - name: JVM_XX_OPTS value: {{ .Values.minecraftServer.jvmXXOpts | quote }} - - {{- if .Values.minecraftServer.monitor.enabled }} - - name: monitor - containerPort: {{ .Values.minecraftServer.monitor.port }} - protocol: TCP - {{- end }} - {{- if .Values.minecraftServer.rcon.enabled }} - name: ENABLE_RCON value: "true" @@ -199,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 index acfd24e8..f69cd6f9 100644 --- a/charts/minecraft/templates/servicemonitor.yml +++ b/charts/minecraft/templates/servicemonitor.yml @@ -1,10 +1,10 @@ -{{- if and .Values.minecraftServer.monitor.enabled .Values.minecraftServer.monitor.servicemonitor.enabled }} +{{- if .Values.servicemonitor.enabled }} apiVersion: monitoring.coreos.com/v1 kind: ServiceMonitor metadata: name: {{ template "minecraft.fullname" . }} -{{- if .Values.minecraftServer.monitor.servicemonitor.namespace }} - namespace: {{ .Values.minecraftServer.monitor.servicemonitor.namespace }} +{{- if .Values.servicemonitor.namespace }} + namespace: {{ .Values.servicemonitor.namespace }} {{- else }} namespace: {{ .Release.Namespace | quote }} {{- end }} @@ -13,9 +13,9 @@ metadata: chart: "{{ .Chart.Name }}-{{ .Chart.Version }}" release: "{{ .Release.Name }}" heritage: "{{ .Release.Service }}" - prometheus: {{ .Values.minecraftServer.monitor.servicemonitor.prometheusInstance }} -{{- if .Values.minecraftServer.monitor.servicemonitor.labels }} -{{ toYaml .Values.minecraftServer.monitor.servicemonitor.labels | indent 4}} + prometheus: {{ .Values.servicemonitor.prometheusInstance }} +{{- if .Values.servicemonitor.labels }} +{{ toYaml .Values.servicemonitor.labels | indent 4}} {{- end }} spec: jobLabel: {{ template "minecraft.fullname" . }} @@ -29,12 +29,12 @@ spec: matchNames: - {{ .Release.Namespace }} endpoints: - - targetPort: {{ .Values.minecraftServer.monitor.servicemonitor.targetPort }} - path: {{ .Values.minecraftServer.monitor.servicemonitor.path }} - interval: {{ .Values.minecraftServer.monitor.servicemonitor.interval }} - scrapeTimeout: {{ .Values.minecraftServer.monitor.servicemonitor.scrapeTimeout }} + - 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 }} \ No newline at end of file +{{- end }} diff --git a/charts/minecraft/values.yaml b/charts/minecraft/values.yaml index 9aabff31..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: [] @@ -134,23 +139,6 @@ minecraftServer: # externalTrafficPolicy: Cluster externalIPs: - monitor: - # If you enable this, make SURE to install Prometheus Exporter. - # and change plugin's config to listen on 0.0.0.0 - # https://dev.bukkit.org/projects/prometheus-exporter - enabled: false - 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: {} - targetPort: 9225 - path: /metrics - interval: 15s - scrapeTimeout: 10s - rcon: # If you enable this, make SURE to change your password below. enabled: false @@ -168,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: {}