Skip to content
Latchkey

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 context

Common 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.yaml

Quote colon values and fix indentation

  1. Wrap any value containing a colon in quotes.
  2. Align indentation consistently under each key (no off-by-one spaces).
  3. Validate with yamllint or kubectl apply --dry-run=client before 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

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →