FormatterHQ

YAML to Base64

Encode a YAML file as one line of Base64 — the usual way to store kubeconfigs and multi-line configs in CI secrets or environment variables.

Loading tool…
Ready.

How to use the YAML to Base64

  1. Type or paste into the YAML box, or click Sample. You can also drop a file on a box or use its Open file button.
  2. The Base64 box updates live as you type. It works both ways — edit the Base64 side to convert back, or click ⇄ Swap to exchange the sides.
  3. Adjust Alphabet and Wrap lines at 76 chars (MIME) in the options bar above the editors; the result refreshes immediately.
  4. Use Copy or Download on either box to take the result, or Clear to start again.

YAML to Base64 for secrets and variables

YAML depends on line breaks and indentation, which many places cannot store reliably: CI/CD secret fields, environment variables, single-line input boxes and some key–value stores. Converting YAML to Base64 turns the whole document into one line of safe characters that decodes back to the exact original, whitespace included.

Example

Input:

apiVersion: v1
kind: ConfigMap
data:
  mode: production
  replicas: "3"

Output:

YXBpVmVyc2lvbjogdjEKa2luZDogQ29uZmlnTWFwCmRhdGE6CiAgbW9kZTogcHJvZHVjdGlvbgogIHJlcGxpY2FzOiAiMyI=

Typical uses

  • Kubeconfig in CI. A common pattern is storing a kubeconfig as a Base64 secret in GitHub Actions or GitLab CI and decoding it in the pipeline with echo "$KUBECONFIG_B64" | base64 -d > ~/.kube/config.
  • Cloud-init user data. Cloud APIs such as EC2’s RunInstances expect user data (often a #cloud-config YAML) to be Base64 encoded; the AWS CLI and most SDKs do this for you.
  • Helm and Kustomize values passed through tools that only accept single-line strings.
  • Configuration inside JSON, such as API requests that carry a YAML definition in a string field.

Kubernetes Secrets: encode values, not files

In a Kubernetes Secret, each value under data: must be Base64 encoded individually — you do not encode the whole manifest. For example, the value production becomes cHJvZHVjdGlvbg==. Alternatively, use stringData: and let Kubernetes encode the values. Remember that Base64 is not encryption; enable encryption at rest or use a secrets manager for real protection.

Encoding on the command line

GNU base64 wraps its output every 76 characters by default, and a wrapped value pasted into a single-line secret often breaks. Use base64 -w 0 kubeconfig on Linux to get one line; the macOS base64 command does not wrap unless asked. This tool writes the Base64 on a single line unless you tick Wrap lines at 76 chars (MIME), so the result can be pasted directly.

Keeping encoded configs secret in CI

Storing a Base64 kubeconfig as a CI secret is common, but a few details decide whether it stays private:

  • Log masking only covers the exact secret. CI systems hide the Base64 string in logs, but not the decoded YAML. Never cat the decoded file or run a command with verbose output that prints it.
  • Size limits. GitHub Actions secrets can hold up to 48 KB. A kubeconfig with embedded certificates is usually far below that, even after the 33% Base64 overhead, but very large configs may need to be split or stored in a secrets manager.
  • Clean up. Write the decoded file to a temporary path with restrictive permissions (chmod 600) and delete it at the end of the job on self-hosted runners.

Watch the trailing newline

Encoding is byte-exact, so a trailing newline in your input becomes part of the Base64. That matters for passwords and tokens stored in secrets: echo "secret" | base64 includes a newline, while printf "secret" | base64 does not. Check that your input ends where you want it to.

Validate the YAML before encoding with the YAML Validator, and decode it again with Base64 to YAML. Everything runs in your browser, but avoid pasting live production credentials into any website.

Frequently asked questions

How do I store a kubeconfig as a CI secret?
Encode the kubeconfig file as Base64, save the result as a secret variable, and decode it in your pipeline with base64 -d before using kubectl.
Do I Base64 encode the whole Kubernetes Secret manifest?
No. Only the individual values under data: are Base64 encoded. The manifest itself stays plain YAML.
Why does my decoded secret have an extra newline?
The input contained a trailing newline, often added by echo or a text editor. Base64 preserves it; remove it before encoding if it should not be there.
Does Base64 protect my configuration?
No. Anyone with the string can decode it. Use encryption or a secrets manager to protect sensitive values.

Last updated October 3, 2026

Related tools