$npx -y skills add wshaddix/dotnet-skills --skill dotnet-container-deploymentDeploying .NET containers. Kubernetes probes, Docker Compose for local dev, CI/CD integration.
| 1 | # dotnet-container-deployment |
| 2 | |
| 3 | Deploying .NET containers to Kubernetes and local development environments. Covers Kubernetes Deployment + Service + probe YAML, Docker Compose for local dev workflows, and CI/CD integration for building and pushing container images. |
| 4 | |
| 5 | **Out of scope:** Dockerfile authoring, multi-stage builds, base image selection, and `dotnet publish` container images are covered in [skill:dotnet-containers]. Advanced CI/CD pipeline patterns (matrix builds, deploy pipelines, environment promotion) -- see [skill:dotnet-gha-deploy] and [skill:dotnet-ado-patterns]. DI and async patterns -- see [skill:dotnet-csharp-dependency-injection] and [skill:dotnet-csharp-async-patterns]. Testing container deployments -- see [skill:dotnet-integration-testing] for Testcontainers patterns and [skill:dotnet-playwright] for E2E testing against deployed containers. |
| 6 | |
| 7 | Cross-references: [skill:dotnet-containers] for Dockerfile and image best practices, [skill:dotnet-observability] for health check endpoint patterns used by Kubernetes probes. |
| 8 | |
| 9 | --- |
| 10 | |
| 11 | ## Kubernetes Deployment |
| 12 | |
| 13 | ### Deployment Manifest |
| 14 | |
| 15 | A production-ready Kubernetes Deployment for a .NET API: |
| 16 | |
| 17 | ```yaml |
| 18 | apiVersion: apps/v1 |
| 19 | kind: Deployment |
| 20 | metadata: |
| 21 | name: order-api |
| 22 | labels: |
| 23 | app: order-api |
| 24 | app.kubernetes.io/name: order-api |
| 25 | app.kubernetes.io/version: "1.0.0" |
| 26 | app.kubernetes.io/component: api |
| 27 | spec: |
| 28 | replicas: 3 |
| 29 | selector: |
| 30 | matchLabels: |
| 31 | app: order-api |
| 32 | template: |
| 33 | metadata: |
| 34 | labels: |
| 35 | app: order-api |
| 36 | spec: |
| 37 | containers: |
| 38 | - name: order-api |
| 39 | image: ghcr.io/myorg/order-api:1.0.0 |
| 40 | ports: |
| 41 | - containerPort: 8080 |
| 42 | protocol: TCP |
| 43 | env: |
| 44 | - name: ASPNETCORE_ENVIRONMENT |
| 45 | value: "Production" |
| 46 | - name: OTEL_EXPORTER_OTLP_ENDPOINT |
| 47 | value: "http://otel-collector.monitoring:4317" |
| 48 | - name: OTEL_SERVICE_NAME |
| 49 | value: "order-api" |
| 50 | - name: ConnectionStrings__DefaultConnection |
| 51 | valueFrom: |
| 52 | secretKeyRef: |
| 53 | name: order-api-secrets |
| 54 | key: connection-string |
| 55 | resources: |
| 56 | requests: |
| 57 | cpu: "100m" |
| 58 | memory: "128Mi" |
| 59 | limits: |
| 60 | cpu: "500m" |
| 61 | memory: "512Mi" |
| 62 | livenessProbe: |
| 63 | httpGet: |
| 64 | path: /health/live |
| 65 | port: 8080 |
| 66 | initialDelaySeconds: 10 |
| 67 | periodSeconds: 15 |
| 68 | timeoutSeconds: 3 |
| 69 | failureThreshold: 3 |
| 70 | readinessProbe: |
| 71 | httpGet: |
| 72 | path: /health/ready |
| 73 | port: 8080 |
| 74 | initialDelaySeconds: 5 |
| 75 | periodSeconds: 10 |
| 76 | timeoutSeconds: 3 |
| 77 | failureThreshold: 3 |
| 78 | startupProbe: |
| 79 | httpGet: |
| 80 | path: /health/live |
| 81 | port: 8080 |
| 82 | initialDelaySeconds: 0 |
| 83 | periodSeconds: 5 |
| 84 | failureThreshold: 30 |
| 85 | securityContext: |
| 86 | runAsNonRoot: true |
| 87 | runAsUser: 1654 |
| 88 | fsGroup: 1654 |
| 89 | terminationGracePeriodSeconds: 30 |
| 90 | ``` |
| 91 | |
| 92 | ### Service Manifest |
| 93 | |
| 94 | Expose the Deployment within the cluster: |
| 95 | |
| 96 | ```yaml |
| 97 | apiVersion: v1 |
| 98 | kind: Service |
| 99 | metadata: |
| 100 | name: order-api |
| 101 | labels: |
| 102 | app: order-api |
| 103 | spec: |
| 104 | type: ClusterIP |
| 105 | selector: |
| 106 | app: order-api |
| 107 | ports: |
| 108 | - port: 80 |
| 109 | targetPort: 8080 |
| 110 | protocol: TCP |
| 111 | name: http |
| 112 | ``` |
| 113 | |
| 114 | ### ConfigMap for Non-Sensitive Configuration |
| 115 | |
| 116 | ```yaml |
| 117 | apiVersion: v1 |
| 118 | kind: ConfigMap |
| 119 | metadata: |
| 120 | name: order-api-config |
| 121 | data: |
| 122 | ASPNETCORE_ENVIRONMENT: "Production" |
| 123 | Logging__LogLevel__Default: "Information" |
| 124 | Logging__LogLevel__Microsoft.AspNetCore: "Warning" |
| 125 | ``` |
| 126 | |
| 127 | Reference in the Deployment: |
| 128 | |
| 129 | ```yaml |
| 130 | envFrom: |
| 131 | - configMapRef: |
| 132 | name: order-api-config |
| 133 | ``` |
| 134 | |
| 135 | ### Secrets for Sensitive Configuration |
| 136 | |
| 137 | ```yaml |
| 138 | apiVersion: v1 |
| 139 | kind: Secret |
| 140 | metadata: |
| 141 | name: order-api-secrets |
| 142 | type: Opaque |
| 143 | stringData: |
| 144 | connection-string: "Host=postgres;Database=orders;Username=app;Password=secret" |
| 145 | ``` |
| 146 | |
| 147 | In production, use an external secrets operator (e.g., External Secrets Operator, Sealed Secrets) rather than plain Kubernetes Secrets stored in source control. |
| 148 | |
| 149 | --- |
| 150 | |
| 151 | ## Kubernetes Probes |
| 152 | |
| 153 | Probes tell Kubernetes how to check application health. They map to the health check endpoints defined in your .NET application (see [skill:dotnet-observability]). |
| 154 | |
| 155 | ### Probe Types |
| 156 | |
| 157 | | Probe | Purpose | Endpoint | Failure Action | |
| 158 | |-------|---------|----------|---------------| |
| 159 | | **Startup** | Has the app finished initializing? | `/health/live` | Keep waiting (up to `failureThreshold * periodSeconds`) | |
| 160 | | **Liveness** | Is the process healthy? | `/health/live` | Restart the pod | |
| 161 | | **Readiness** | Can the process serve traffic? | `/health/ready` | Remove from Service endpoints | |
| 162 | |
| 163 | ### Probe Configuration Guidelines |