Common causes
1. A setting added again lower in the block
Long service definitions make it easy to add image: again instead of editing the existing line. Keep one key with the value you want.
web:
image: nginx:1.25
ports:
- "80:80"
image: nginx:1.27web:
image: nginx:1.27
ports:
- "80:80"2. Two blocks for the same list
Writing env: twice, once for each group of variables, defines the key twice instead of extending the list. Merge the items under one key.
env:
- name: LOG_LEVEL
value: info
env:
- name: REGION
value: eu-west-1env:
- name: LOG_LEVEL
value: info
- name: REGION
value: eu-west-13. Keys that look different but are the same
Quoting does not change a key: "port" and port are identical. Keys are case-sensitive, though, so Port and port are different keys and will not be reported.
port: 8080
"port": 9090port: 90904. Templated keys colliding with literal ones
A Helm {{- toYaml .Values.labels | nindent 4 }} that also emits app: collides with an app: written in the template. Remove the literal key or the value from the values file.
labels:
app: web
app: web-canary
tier: frontendlabels:
app: web-canary
tier: frontendFrequently asked questions
Why does my file load fine in Python?
PyYAML does not check for duplicate keys and silently keeps the last value. The same file fails in kubectl, Helm, GitHub Actions or any tool built on a strict parser.
Is the merge key <<: allowed to repeat keys?
Yes. Keys pulled in with <<: *anchor can be overridden by keys written directly in the mapping; that is how merge keys are meant to work and is not a duplicate.
How do I find every duplicate in a large file?
Paste it into PasteKit: every repeated key is reported with its line and column. yamllint’s key-duplicates rule does the same in CI.