Convert Kubernetes YAML manifests into Helm charts automatically
Project description
yaml2helm
Convert Kubernetes YAML manifests into Helm charts automatically.
Features
- Multiple input formats: File, directory, stdin, or Kustomize with multi-document YAML support
- Smart value extraction: Automatically extracts common fields (image, replicas, resources, etc.)
- Resource-scoped values: Zero conflicts by organizing values per resource
- CRD support: Separate CRDs into crds/ directory per Helm best practices
- Namespace handling: Template namespaces or preserve originals
- Name templating: Preserve original names or add release name prefix
- Deterministic output: Stable ordering and idempotent reruns
- JSON Schema generation: Optional values.schema.json for validation
- Helm integration: Built-in helm lint and helm template validation
- Kustomize support: Direct integration with kustomize build
- Makefile generation: Optional Makefile with helm workflow targets
- Enhanced helpers: Comprehensive _helpers.tpl with apiVersion helpers
- Comprehensive reporting: Track conversions with detailed statistics
Installation
pip install -e .
For development:
pip install -e ".[dev]"
Usage
Basic conversion
yaml2helm --name myapp --in ./manifests --out ./charts
From stdin
kubectl get deployment nginx -o yaml | yaml2helm --name nginx --out ./charts
From Kustomize
yaml2helm --name myapp --kustomize ./overlays/production --out ./charts
With Makefile generation
yaml2helm --name myapp --in ./manifests --out ./charts --makefile
This creates a Makefile.helm with targets for building and managing your Helm chart:
make -f Makefile.helm help # Show available targets
make -f Makefile.helm helm # Generate chart
make -f Makefile.helm helm-lint # Lint the chart
With CRD separation
yaml2helm --name myapp --in ./manifests --out ./charts --crd-dir
This places CustomResourceDefinitions in crds/ directory per Helm best practices.
Preserve original namespaces
yaml2helm --name myapp --in ./manifests --out ./charts --preserve-ns
Keeps original namespaces instead of templating to {{ .Release.Namespace }}.
Add release name prefix
yaml2helm --name myapp --in ./manifests --out ./charts --prefix-release-name
Prefixes resource names with {{ include "myapp.fullname" . }}.
Advanced options
yaml2helm \
--name myapp \
--in ./manifests \
--out ./charts \
--resource-scoped \
--crd-dir \
--preserve-ns \
--schema \
--strict \
--makefile
CLI Options
| Option | Description | Default |
|---|---|---|
--name, -n |
Chart name (required) | - |
--in, -i |
Input file/directory (stdin if omitted) | stdin |
--kustomize, -k |
Run kustomize build on directory | - |
--out, -o |
Output directory | ./charts |
--resource-scoped/--field-scoped |
Scope values to resources (recommended) | true |
--crd-dir |
Place CRDs in separate crds/ directory | false |
--preserve-ns |
Preserve original namespaces (don't template) | false |
--original-name/--prefix-release-name |
Preserve names or add release prefix | true |
--include-cluster |
Include cluster-specific fields | false |
--schema/--no-schema |
Generate values.schema.json | true |
--lint/--no-lint |
Run helm lint | true |
--template/--no-template |
Run helm template | true |
--strict |
Fail on helm errors | false |
--makefile |
Generate Makefile.helm | false |
Output Structure
charts/
└── myapp/
├── Chart.yaml
├── values.yaml
├── values.schema.json
├── README.md
├── .helmignore
└── templates/
├── _helpers.tpl
├── NOTES.txt
├── 01-deployment-nginx.yaml
└── 02-service-nginx.yaml
Extracted Values
yaml2helm automatically extracts and templates:
- Image: repository and tag
- Replicas: for Deployments, StatefulSets
- Resources: CPU/memory limits and requests
- Service: type and ports
- Ingress: rules and TLS
- Environment variables: from containers
- Node affinity: nodeSelector, tolerations, affinity
- HPA: min/max replicas and target CPU
Examples
Convert a deployment
# Input: deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx
spec:
replicas: 3
template:
spec:
containers:
- name: nginx
image: nginx:1.19
# Run conversion
yaml2helm --name nginx --in deployment.yaml --out ./charts
# Output: charts/nginx/values.yaml
image:
repository: nginx
tag: "1.19"
replicas: 3
# Output: charts/nginx/templates/01-deployment-nginx.yaml (templated)
spec:
replicas: {{ .Values.replicas }}
template:
spec:
containers:
- image: {{ .Values.image.repository }}:{{ .Values.image.tag }}
Multi-document YAML
# Input file with multiple resources separated by ---
yaml2helm --name myapp --in multi.yaml --out ./charts
Directory of manifests
# Convert all YAML files in a directory
yaml2helm --name myapp --in ./k8s-manifests --out ./charts
Testing
Run tests:
pytest tests/ -v
With coverage:
pytest tests/ --cov=yaml2helm --cov-report=term-missing
Algorithm
- Discovery: Find YAML files, split multi-docs, parse with ruamel.yaml
- Validation: Check for apiVersion, kind, metadata.name
- Normalization: Sort maps and lists for deterministic output
- Extraction: Extract values per heuristics, replace with Helm templates
- Writing: Generate template files as
NN-<kind>-<name>.yaml - Schema: Create values.schema.json from extracted values
- Validation: Run helm lint and helm template if available
Requirements
- Python 3.11+
- Optional: helm CLI for validation
Dependencies
- typer: CLI framework
- ruamel.yaml: YAML parsing with comments preservation
- jinja2: Template rendering
- jsonschema: Schema validation
- rich: Terminal formatting
Development
# Install dev dependencies
pip install -e ".[dev]"
# Run tests
pytest
# Run with coverage
pytest --cov=yaml2helm
# Test with helm integration
yaml2helm --name demo --in tests/data/input --out /tmp/charts
helm lint /tmp/charts/demo
helm template test /tmp/charts/demo
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file yaml2helm-0.1.0.tar.gz.
File metadata
- Download URL: yaml2helm-0.1.0.tar.gz
- Upload date:
- Size: 27.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7bbbc6a58f9dd8cda4ae7d50eaf0523d7c38452a47502bb2bac090f5984ec643
|
|
| MD5 |
2c7239a576745a9fa2be0c0a00ad9764
|
|
| BLAKE2b-256 |
edeb2c8e3e13011bab3d250dd4fa3213b13fed2a39aa25292eb02eaae4cffe0b
|
File details
Details for the file yaml2helm-0.1.0-py3-none-any.whl.
File metadata
- Download URL: yaml2helm-0.1.0-py3-none-any.whl
- Upload date:
- Size: 29.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5c85c683fb719a4331cccab553d1df0de22868ffaa6cbd6370cc086257a3eab6
|
|
| MD5 |
c0a07044ca36c9703b58c1c77ca054c7
|
|
| BLAKE2b-256 |
dcb8d5bfdbb702030febff3d3889a9b57ad73b2efa1f98ecc70820bd1bd593d0
|