kubectl "mapping values are not allowed in this context" in CI
This YAML error means the parser found a key: value mapping where it expected something else - usually a stray colon, a misindented line, or an unquoted value that itself contains a colon.
What this error means
kubectl apply fails with error converting YAML to JSON: yaml: line N: mapping values are not allowed in this context. The structure around line N is ambiguous to the parser.
kubectl output
error converting YAML to JSON: yaml: line 9: mapping values are not allowed
in this contextCommon causes
Unquoted value containing a colon
A value like note: see http://x or time: 12:30 reads as a nested mapping because of the colon. It must be quoted: "see http://x".
Misindented or duplicated key
A line indented one space off, or a second key: where a scalar was expected, makes the parser see a mapping in the wrong place.
How to fix it
Inspect the structure around the line
Terminal
sed -n '6,11p' deploy.yaml | cat -A
yamllint deploy.yamlQuote colon values and fix indentation
- Wrap any value containing a colon in quotes.
- Align indentation consistently under each key (no off-by-one spaces).
- Validate with
yamllintorkubectl apply --dry-run=clientbefore deploying.
How to prevent it
- Quote values that contain colons, URLs, or times.
- Keep indentation strictly consistent with spaces.
- Lint manifests in CI before apply.
Related guides
kubectl "error converting YAML to JSON" - Fix Manifest YAML in CIFix kubectl "error converting YAML to JSON" on apply in CI - malformed YAML (tabs, bad indentation, unquoted…
kubectl "error validating data" - Fix Manifest Validation in CIFix kubectl "error validating data: ValidationError" on apply in CI - an unknown field, wrong type, or typo i…
kubectl "metadata.labels: Invalid value" - Fix Bad Label Values in CIFix kubectl "metadata.labels: Invalid value" / "metadata.annotations" errors in CI - a label value with illeg…