kubernetes/kops · error
error writing cluster yaml to stdout: %v
Error message
error writing cluster yaml to stdout: %v
What it means
In DryRun mode, RunCreateCluster serializes the cluster and objects to YAML via fullOutputYAML and writes them to stdout. This error means YAML marshaling or writing to the output writer failed. It wraps the underlying marshal/write error and only occurs with --dry-run --output yaml.
Source
Thrown at cmd/kops/create_cluster.go:811
Name: name,
Labels: map[string]string{
api.LabelClusterName: cluster.Name,
},
},
Spec: api.SSHCredentialSpec{
PublicKey: strings.TrimSpace(string(key)),
},
})
}
for _, o := range addons {
obj = append(obj, o.ToUnstructured())
}
switch c.Output {
case OutputYaml:
if err := fullOutputYAML(out, obj...); err != nil {
return fmt.Errorf("error writing cluster yaml to stdout: %v", err)
}
return nil
case OutputJSON:
if err := fullOutputJSON(out, true, obj...); err != nil {
return fmt.Errorf("error writing cluster json to stdout: %v", err)
}
return nil
default:
return fmt.Errorf("unsupported output type %q", c.Output)
}
}
// Note we perform as much validation as we can, before writing a bad config
err = registry.CreateClusterConfig(ctx, clientset, cluster, instanceGroups, addons)
if err != nil {
return fmt.Errorf("error writing updated configuration: %v", err)
}
View on GitHub (pinned to 4c8573c808)
Solutions
- Retry without piping stdout, or redirect to a writable file (e.g. > cluster.yaml).
- Check the wrapped error to distinguish marshal vs write failure.
- Re-run with a plain terminal to confirm it is an environment, not a spec, problem.
- Report a bug if marshaling a stock spec fails (likely a kops defect).
Example fix
// before kops create cluster ... --dry-run --output yaml | head -1 # broken pipe // after kops create cluster ... --dry-run --output yaml > cluster.yaml
Defensive patterns
Strategy: try-catch
Try / catch
out, err := os.Create("cluster.yaml")
if err != nil { return err }
defer out.Close()
if err := runCreateCluster(ctx, out, ...); err != nil {
if strings.Contains(err.Error(), "error writing cluster yaml") {
// marshal or write failed; retry with a fresh writer/file
}
return err
} Prevention
- Redirect dry-run output to a real file, not a fragile pipe.
- Ensure the output file's directory exists and has space.
- Keep kops updated; marshal failures on stock specs are usually bugs.
- Avoid `| head` style pipelines with kops output.
When it happens
Trigger: `kops create cluster --dry-run --output yaml` where fullOutputYAML fails to marshal the runtime.Objects or the underlying writer (e.g. a piped stdout) errors on write.
Common situations: Stdout piped to a closed/full pipe or unwritable file in scripts; an internal serialization bug on an unexpected object type attached via addons.
Related errors
- unable to execute --dry-run without setting --output
- error writing cluster json to stdout: %v
- unsupported output type %q
- error writing to output: %v
- error writing to output: %v
AI-assisted analysis of kubernetes/kops@4c8573c808 (2026-09-05).
Data as JSON: /api/errors/3c4db3a159bdfbad.
Report an issue: GitHub.