Skip to content

Commit 0fc3c00

Browse files
authored
Update to match sample app user (dotnet#5313)
* Update to match sample app * PR Feedback * Fix aks deployment tutorial * Fixup kubernetes.md
1 parent 2deca98 commit 0fc3c00

File tree

2 files changed

+91
-6
lines changed

2 files changed

+91
-6
lines changed

documentation/kubernetes.md

+87-4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ In addition to its availability as a .NET CLI tool, the `dotnet monitor` tool is
77

88
For Dockerfiles and repository information, see [Running in Docker](./docker.md)
99

10+
## Non-root considerations
11+
12+
Starting with .NET 8.0, both the sample ASP.NET application and dotnet-monitor run as non-root. If both the application and dotnet-monitor are 8+, no additional configuration is required. Otherwise, a [security context](https://kubernetes.io/docs/tasks/configure-pod-container/security-context/) configuration may need to be added to the application, dotnet-monitor, or both.
13+
1014
## Example Deployment
1115

1216
The following examples demonstrate a deployment of the dotnet-monitor container image monitoring an application container within the same pod.
@@ -37,7 +41,7 @@ spec:
3741
imagePullPolicy: Always
3842
env:
3943
- name: ASPNETCORE_URLS
40-
value: http://+:80
44+
value: http://+:8080
4145
- name: DOTNET_DiagnosticPorts
4246
value: /diag/dotnet-monitor.sock
4347
volumeMounts:
@@ -49,6 +53,11 @@ spec:
4953
memory: 512Mi
5054
- name: monitor
5155
image: mcr.microsoft.com/dotnet/monitor:6
56+
securityContext:
57+
# Default APP_UID for non-root dotnet application images
58+
runAsUser: 1654
59+
runAsGroup: 1654
60+
runAsNonRoot: true
5261
# DO NOT use the --no-auth argument for deployments in production; this argument is used for demonstration
5362
# purposes only in this example. Please continue reading after this example for further details.
5463
args: [ "--no-auth" ]
@@ -82,7 +91,7 @@ spec:
8291
</details>
8392
8493
<details>
85-
<summary>.NET Monitor 7+</summary>
94+
<summary>.NET Monitor 7</summary>
8695
8796
```yaml
8897
# Tell us about your experience using dotnet monitor: https://aka.ms/dotnet-monitor-survey
@@ -107,7 +116,7 @@ spec:
107116
imagePullPolicy: Always
108117
env:
109118
- name: ASPNETCORE_URLS
110-
value: http://+:80
119+
value: http://+:8080
111120
- name: DOTNET_DiagnosticPorts
112121
value: /diag/dotnet-monitor.sock
113122
volumeMounts:
@@ -118,7 +127,12 @@ spec:
118127
cpu: 250m
119128
memory: 512Mi
120129
- name: monitor
121-
image: mcr.microsoft.com/dotnet/monitor
130+
image: mcr.microsoft.com/dotnet/monitor:7
131+
securityContext:
132+
# Default APP_UID for non-root dotnet application images
133+
runAsUser: 1654
134+
runAsGroup: 1654
135+
runAsNonRoot: true
122136
# DO NOT use the --no-auth argument for deployments in production; this argument is used for demonstration
123137
# purposes only in this example. Please continue reading after this example for further details.
124138
args: [ "collect", "--no-auth" ]
@@ -152,6 +166,75 @@ spec:
152166
153167
</details>
154168
169+
<details>
170+
<summary>.NET Monitor 8+</summary>
171+
172+
```yaml
173+
# Tell us about your experience using dotnet monitor: https://aka.ms/dotnet-monitor-survey
174+
apiVersion: apps/v1
175+
kind: Deployment
176+
metadata:
177+
name: deploy-exampleapp
178+
spec:
179+
replicas: 1
180+
selector:
181+
matchLabels:
182+
app: exampleapp
183+
template:
184+
metadata:
185+
labels:
186+
app: exampleapp
187+
spec:
188+
restartPolicy: Always
189+
containers:
190+
- name: app
191+
image: mcr.microsoft.com/dotnet/samples:aspnetapp
192+
imagePullPolicy: Always
193+
env:
194+
- name: ASPNETCORE_URLS
195+
value: http://+:8080
196+
- name: DOTNET_DiagnosticPorts
197+
value: /diag/dotnet-monitor.sock
198+
volumeMounts:
199+
- mountPath: /diag
200+
name: diagvol
201+
resources:
202+
limits:
203+
cpu: 250m
204+
memory: 512Mi
205+
- name: monitor
206+
image: mcr.microsoft.com/dotnet/monitor:8
207+
# DO NOT use the --no-auth argument for deployments in production; this argument is used for demonstration
208+
# purposes only in this example. Please continue reading after this example for further details.
209+
args: [ "collect", "--no-auth" ]
210+
imagePullPolicy: Always
211+
env:
212+
- name: DOTNETMONITOR_DiagnosticPort__ConnectionMode
213+
value: Listen
214+
- name: DOTNETMONITOR_Storage__DefaultSharedPath
215+
value: /diag
216+
# ALWAYS use the HTTPS form of the URL for deployments in production; the removal of HTTPS is done for
217+
# demonstration purposes only in this example. Please continue reading after this example for further details.
218+
- name: DOTNETMONITOR_Urls
219+
value: http://localhost:52323
220+
# 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.
221+
- name: DOTNETMONITOR_Metrics__Endpoints
222+
value: http://+:52325
223+
volumeMounts:
224+
- mountPath: /diag
225+
name: diagvol
226+
resources:
227+
requests:
228+
cpu: 50m
229+
memory: 32Mi
230+
limits:
231+
cpu: 250m
232+
memory: 256Mi
233+
volumes:
234+
- name: diagvol
235+
emptyDir: {}
236+
```
237+
155238
## Example Details
156239
157240
* __Listen Mode__: The `dotnet monitor` tool is configured to run in `listen` mode. The tool establishes a diagnostic communication channel at the specified Unix Domain Socket path by the `DOTNETMONITOR_DiagnosticPort__EndpointName` environment variable. The application container has a `DOTNET_DiagnosticPorts` environment variable specified so that the application's runtime will communicate with the `dotnet monitor` instance at the specified Unix Domain Socket path. The application runtime will be suspended (e.g. no managed code execution) until it establishes communication with `dotnet monitor`. Application startup time will depend on how long it takes for the `dotnet monitor` container to run, but this should be quick.

samples/AKS_Tutorial/deploy.yaml

+4-2
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@ spec:
1313
app: akstest
1414
spec:
1515
restartPolicy: Always
16+
securityContext:
17+
fsGroup: 1654 # Default APP_ID for the aspnetapp image
1618
containers:
1719
- name: publishedapp
1820
image: mcr.microsoft.com/dotnet/samples:aspnetapp
1921
imagePullPolicy: Always
2022
env:
2123
- name: ASPNETCORE_URLS
22-
value: http://+:80
24+
value: http://+:8080
2325
- name: DOTNET_DiagnosticPorts
2426
value: /diag/port.sock
2527
volumeMounts:
@@ -30,7 +32,7 @@ spec:
3032
cpu: 250m
3133
memory: 512Mi
3234
- name: monitor
33-
image: mcr.microsoft.com/dotnet/monitor:6
35+
image: mcr.microsoft.com/dotnet/monitor:8
3436
imagePullPolicy: Always
3537
env:
3638
- name: DotnetMonitor_DiagnosticPort__ConnectionMode

0 commit comments

Comments
 (0)