BadRequest (400)
KubernetesERRORCriticalAPI ErrorHIGH confidence

Malformed API request body rejected by the server

Production Risk

Deployment pipeline failures; objects cannot be created or updated.

What this means

HTTP 400 Bad Request from the Kubernetes API server means the submitted object or request body is syntactically invalid or fails validation rules. The server could parse the request but determined the content violates the API schema or admission webhook requirements. The error message from the server usually pinpoints the specific field.

Why it happens
  1. 1YAML or JSON manifest has an invalid field value or type mismatch
  2. 2Required field is missing from the resource spec
  3. 3Admission webhook rejected the object with a custom validation error
  4. 4Immutable field (like a Job selector) was modified on an update request
How to reproduce

kubectl apply or kubectl create returns a 400 error with a specific validation message.

trigger — this will error
trigger — this will error
kubectl apply -f deployment.yaml
# Error from server (BadRequest): error when creating "deployment.yaml":
# Deployment.apps "myapp" is invalid: spec.replicas: Invalid value: -1:
# must be greater than or equal to 0

expected output

Error from server (BadRequest): ...invalid: spec.replicas: Invalid value: -1

Fix 1

Validate manifest before applying

WHEN Schema validation errors

Validate manifest before applying
kubectl apply -f deployment.yaml --dry-run=server
# Use kubeval or kube-score for offline validation
kubeval deployment.yaml

Why this works

Server-side dry-run runs all validation and admission webhooks without persisting the object.

Fix 2

Read the full error message for the specific field

WHEN Error message identifies a specific invalid field

Read the full error message for the specific field
kubectl apply -f deployment.yaml 2>&1 | grep -A 5 "is invalid"

Why this works

The API server error message always names the exact field that failed validation.

Sources
Official documentation ↗

Kubernetes Documentation

Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev

← All Kubernetes errors