You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

YAML文件报错‘end of the stream or a document separator is expected’的排查求助

Troubleshooting YAML Error: "end of the stream or a document separator is expected"

Hey there! I’ve run into this exact YAML hiccup with Kubernetes configs before, so let’s break down what’s going wrong and fix it step by step.

First: The Real Issue (It’s Not Line 2!)

Even though your error points to line 2 (apiVersion: v1), the actual problem lies elsewhere. Let’s look at your certificate-authority-data field:

certificate-authority-data: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUN5RENDQWJDZ0F3SUJBZ0lCQURBTkJna3Foa2lHOXcwQkFRc0ZBREFWTVJNd0VRWURWUVFERXdwcmRXSmwKY201bGRHVnpNQjR>

Two critical problems jump out here:

  • The Base64 string is truncated — EKS cluster CA data is a long, complete Base64 blob, and yours cuts off mid-sequence.
  • There’s an extra > at the end. In YAML, > is a special character for folded block scalars, so sticking it in the middle of a plain string completely breaks the parser.

This broken field confuses the YAML parser so much that it reports an error at the wrong line (line 2) because it can’t make sense of the rest of the document after hitting this invalid syntax.

Step-by-Step Fixes

1. Replace the truncated CA data with the full, valid string

Grab the complete certificate authority data for your EKS cluster using the AWS CLI:

aws eks describe-cluster --name terraform-eks-demo --query "cluster.certificateAuthority.data" --output text

Copy the full output of this command and paste it into your certificate-authority-data field — make sure there are no extra characters (like the stray >) at the end.

2. Double-check YAML indentation

YAML is ruthless about indentation. Confirm:

  • You’re using 2 spaces for each indent level (never mix tabs and spaces)
  • All nested fields (like cluster under clusters, exec under user) are perfectly aligned with their parent fields

3. Validate the fixed YAML

Once you’ve made changes, test the config directly with Kubectl:

kubectl config view --kubeconfig path/to/your/config-file

If this command outputs your config without errors, you’re set! You can also use a local linter like yamllint to catch any remaining syntax slips.

Quick Newbie Tips for YAML Troubleshooting

  • When parsers report errors in unexpected spots, always check the fields right before the reported line — broken long strings or invalid special characters often throw off the error location.
  • Never manually edit or truncate Base64-encoded fields (like CA data, tokens) — always copy them directly from the source (CLI, cloud console) to avoid corruption.
  • Use a syntax-highlighting editor (like VS Code with the YAML extension) — it’ll often flag invalid syntax before you even run the file.

内容的提问来源于stack exchange,提问作者Mick8695

火山引擎 最新活动