|
| 1 | +--- |
| 2 | +audience: developer |
| 3 | +components: |
| 4 | + - serving |
| 5 | +function: how-to |
| 6 | +--- |
| 7 | + |
| 8 | +# Validating Resource Using Server-Side Dry Run |
| 9 | + |
| 10 | +Kubernetes dry run lets you ask the API server to admit, default, and validate your object without persisting it to etcd. This is useful to verify that your Knative `Service`, `Configuration`, or `Route` specs are valid and to preview defaults before creating or updating resources. |
| 11 | + |
| 12 | +Use server-side dry run (`--dry-run=server`), which sends the request to the API server with the `dryRun=All` flag. The API server executes admission, defaulting, and validation (including Knative Serving webhooks) but does not persist the object. |
| 13 | + |
| 14 | +What gets validated in server-side dry run |
| 15 | + |
| 16 | +- Knative Serving schema validation for `Service`, `Configuration`, `Route`, and related objects. |
| 17 | +- Knative defaulting webhooks apply defaults (for example, missing fields in `spec.template` are defaulted). You can see these defaults with `-o yaml`. |
| 18 | +- Kubernetes admission and validation (quotas, RBAC, OpenAPI validation, etc.). |
| 19 | + |
| 20 | +Limitations and notes |
| 21 | + |
| 22 | +- No resources are created or modified. Controllers do not reconcile and no Pods are started. |
| 23 | +- External systems are not contacted. For example, image digest resolution by the queue/reconciler and runtime readiness checks do not occur during a dry run. |
| 24 | +- Feature gates and validations are the same as for a real request against your current cluster version/configuration. |
| 25 | +- Server-side dry run requires a Kubernetes version that supports it (GA since v1.18). |
| 26 | + |
| 27 | +Example |
| 28 | + |
| 29 | +```bash |
| 30 | +# Validate the inline manifest above without creating it |
| 31 | +kubectl apply --dry-run=server -o yaml -f - <<EOF |
| 32 | +apiVersion: serving.knative.dev/v1 |
| 33 | +kind: Service |
| 34 | +metadata: |
| 35 | + name: helloworld-go |
| 36 | + namespace: default |
| 37 | +spec: |
| 38 | + template: |
| 39 | + spec: |
| 40 | + containers: |
| 41 | + - image: ghcr.io/knative/helloworld-go:latest |
| 42 | + env: |
| 43 | + - name: TARGET |
| 44 | + value: "Knative" |
| 45 | +EOF |
| 46 | +``` |
| 47 | + |
| 48 | +Troubleshooting |
| 49 | + |
| 50 | +- If server-side dry run fails with validation errors, fix the reported fields in your manifest and retry. |
| 51 | +- If you see RBAC errors, ensure your user has permission to create/update the indicated resource kind in the target namespace. |
| 52 | + |
0 commit comments