A helm v3 plugin to adopt existing k8s resources into a new generated helm chart
[]() [
]()
helm-adopt
Overview
helm-adopt is a helm plugin to adopt existing k8s resources into a new generated helm chart, the idea behind the plugin was inspired by issue 2730.
adopt plugin allows you to :
- adopt existing k8s resources by generating a helm chart
- migrate adopted resources to be controlled by helm
- create a helm release using secret as driver
- perform a dry-run/debug-mode (optional)
adopt does not re-create resources.
Getting started
Installation
To install the plugin:
$ helm plugin install https://github.com/HamzaZo/helm-adopt Update to latest $ helm plugin update adopt Install a specific version $ helm plugin install https://github.com/HamzaZo/helm-adopt --version 0.3.1 You can also verify it's been installed using $ helm plugin list
Usage
$ helm adopt
Adopt k8s resources into a new helm chart. It's expected to match plural resources kinds.
Usage: adopt [command]
Available Commands: help Help about any command resources adopt k8s resources into a new generated helm chart
Flags: -h, --help help for adopt
Use "adopt [command] --help" for more information about a command.
Adopt k8s resources
$ helm adopt resources -h
Adopt k8s resources into a new generated helm chart
Examples: $ helm adopt resources deployments:nginx services:my-svc -o/--output frontend
$ helm adopt resources deployments:nginx clusterrolebindings:binding-rbac -o/--output frontend -n/--namespace <ns>
$ helm adopt resources statefulsets:nginx services:my-svc -r/--release RELEASE-NAME -o/--output frontend -c/--kube-context <ctx>
$ helm adopt resources deployments:nginx services:my-svc -r/--release RELEASE-NAME -o/--output frontend -k/--kubeconfig <kcfg>
Usage: adopt resources <pluralKind>:<name> [flags]
Flags: --debug-mode Show the generated manifests on STDOUT --dry-run Print what resources will be adopted -h, --help help for resources -c, --kube-context string name of the kubeconfig context to use -k, --kubeconfig string path to the kubeconfig file -n, --namespace string namespace scope for this request -o, --output string Specify the chart directory of loaded yaml files -r, --release string Specify the name for the generated release
Example User case
In the following example theadopt plugin will :
- Generate a chart directory called
example - adopt
frontend,backenddeployments and generatedeployments-0.yamldeployments-1.yamlfiles. - adopt
frontend,backendservices and generateservices-0.yamlservices-1.yamlfiles. - adopt
default-lrlimitranges and generatelimitranges-0.yamlfile. - migrate adopted resources control to
Helm - create
examplerelease with version1using secret as driver.
$ helm adopt resources deployments:frontend,backend services:frontend,backend limitranges:default-lr --output example --release example
INFO[0000] Adopting resources..
INFO[0000] Generating chart example
INFO[0000] Added resource as file deployments-0 into example chart
INFO[0000] Added resource as file deployments-1 into example chart
INFO[0000] Added resource as file limitranges-0 into example chart
INFO[0000] Added resource as file services-0 into example chart
INFO[0000] Added resource as file services-1 into example chart
INFO[0000] Chart example is released as example.1
Note: You must use a semicolon after each name <pluralKind>:<name>,<name>,<name> if you need to adopt a bunch of resources under a specific pluralKind as shown in the example above.
check the release status
$ helm ls NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION example default 1 2021-05-18 12:04:53.171943 +0200 CEST deployed example-0.1.0 0.1.0
$ kubectl get secret
NAME TYPE DATA AGE
sh.helm.release.v1.example.v1 helm.sh/release.v1 1 51s
check generated chart directory.
$ tree example
example
โโโ Chart.yaml
โโโ charts
โโโ templates
โ โโโ _helpers.tpl
โ โโโ deployments-0.yaml
โ โโโ deployments-1.yaml
โ โโโ limitranges-0.yaml
โ โโโ services-0.yaml
โ โโโ services-1.yaml
โโโ values.yaml
2 directories, 8 files
Afterwards, you can edit the manifests in example/templates and turn them into templates and/or rework the generated chart into subcharts and then do a helm upgrade to fully transform the release.
Hints: To find out the pluralKind for a specific kind use kubectl api-resources