Skip to content

Commit 624dddd

Browse files
authored
Add dotnet counters & prometheus service monitor to k8s example (#849)
2 parents 340e260 + 8d4caea commit 624dddd

5 files changed

Lines changed: 74 additions & 6 deletions

File tree

kube/db.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ spec:
77
- ReadWriteOnce
88
resources:
99
requests:
10-
storage: 4Gi
10+
storage: 1Gi
1111
---
1212
apiVersion: v1
1313
kind: ConfigMap

kube/deployment.yaml

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ spec:
1414
spec:
1515
containers:
1616
- name: refresh-gameserver
17-
image: ghcr.io/littlebigrefresh/refresh-postgres-beta:main
17+
image: ghcr.io/littlebigrefresh/refresh:latest
1818
imagePullPolicy: Always
1919
ports:
2020
- containerPort: 10061
@@ -23,9 +23,13 @@ spec:
2323
value: /refresh/data
2424
- name: POSTGRES_CONNECTION_STRING
2525
value: Database=refresh;Username=refresh;Password=refresh;Host=refresh-db;Port=5432
26+
- name: DOTNET_DiagnosticPorts
27+
value: "/diag/dotnet-monitor.sock,connect,suspend"
2628
volumeMounts:
2729
- name: gameserver-data
2830
mountPath: /refresh/data
31+
- name: diagvol
32+
mountPath: /diag
2933
livenessProbe:
3034
httpGet:
3135
path: /_health
@@ -34,7 +38,43 @@ spec:
3438
periodSeconds: 5
3539
timeoutSeconds: 3
3640
failureThreshold: 5
41+
- name: monitor
42+
image: mcr.microsoft.com/dotnet/monitor:9.0
43+
ports:
44+
- containerPort: 52323
45+
- containerPort: 52325
46+
securityContext:
47+
runAsUser: 1001
48+
# DO NOT use the --no-auth argument for deployments in production; this argument is used for demonstration
49+
# purposes only in this example. Please continue reading after this example for further details.
50+
args: [ "collect", "--no-auth" ]
51+
imagePullPolicy: Always
52+
env:
53+
- name: DOTNETMONITOR_DiagnosticPort__ConnectionMode
54+
value: Listen
55+
- name: DOTNETMONITOR_Storage__DefaultSharedPath
56+
value: /diag
57+
# ALWAYS use the HTTPS form of the URL for deployments in production; the removal of HTTPS is done for
58+
# demonstration purposes only in this example. Please continue reading after this example for further details.
59+
- name: DOTNETMONITOR_Urls
60+
value: http://localhost:52323
61+
# The metrics URL is set in the CMD instruction of the image by default. However, this deployment overrides that with the args setting; manually set the URL to the same value using configuration.
62+
- name: DOTNETMONITOR_Metrics__Endpoints
63+
value: http://+:52325
64+
volumeMounts:
65+
- mountPath: /diag
66+
name: diagvol
67+
resources:
68+
requests:
69+
cpu: 50m
70+
memory: 32Mi
71+
limits:
72+
cpu: 250m
73+
memory: 256Mi
3774
volumes:
3875
- name: gameserver-data
3976
persistentVolumeClaim:
4077
claimName: gameserver-pvc
78+
- name: diagvol
79+
emptyDir:
80+
medium: "Memory"

kube/pvc.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ spec:
77
- ReadWriteOnce
88
resources:
99
requests:
10-
storage: 25Gi
10+
storage: 10Gi

kube/service.yaml

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,20 @@
22
kind: Service
33
metadata:
44
name: refresh-gameserver
5+
namespace: refresh
6+
labels:
7+
app: refresh-gameserver
58
spec:
69
selector:
710
app: refresh-gameserver
811
ports:
9-
- protocol: TCP
12+
- name: refresh-gameserver
1013
port: 10061
11-
targetPort: 10061
12-
type: ClusterIP
14+
protocol: TCP
15+
- name: monitor
16+
protocol: TCP
17+
port: 52323
18+
- name: monitor-metrics
19+
protocol: TCP
20+
port: 52325
21+
type: ClusterIP

kube/servicemonitor.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
apiVersion: monitoring.coreos.com/v1
2+
kind: ServiceMonitor
3+
metadata:
4+
name: refresh-gameserver-monitor
5+
namespace: monitoring
6+
labels:
7+
app: refresh-gameserver
8+
release: kube-prometheus-stack
9+
spec:
10+
endpoints:
11+
- interval: 5s
12+
port: monitor-metrics
13+
path: /metrics
14+
namespaceSelector:
15+
matchNames:
16+
- refresh
17+
selector:
18+
matchLabels:
19+
app: refresh-gameserver

0 commit comments

Comments
 (0)