A helm v3 plugin to adopt existing k8s resources into a new generated helm chart

Licence Helm

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.

the 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)

Note: 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.1.0

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 the adopt plugin will :

  • Generate a chart directory called example
  • adopt frontend,backend deployments and generate deployments-0.yaml deployments-1.yaml files.
  • adopt frontend,backend services and generate services-0.yaml services-1.yaml files.
  • adopt default-lr limitranges and generate limitranges-0.yaml file.
  • migrate adopted resources control to Helm
  • create example release with version 1 using 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

Owner
Hamza ZOUHAIR
DevOps Engineer
Hamza ZOUHAIR
Similar Resources

The k8s-generic-webhook is a library to simplify the implementation of webhooks for arbitrary customer resources (CR) in the operator-sdk or controller-runtime.

k8s-generic-webhook The k8s-generic-webhook is a library to simplify the implementation of webhooks for arbitrary customer resources (CR) in the opera

Nov 24, 2022

Poc rsa - A simple golang scaffolding to help me to create new api projects or workers with golang on k8s

go-scaffold A simple golang scaffolding to help me to create new api projects or

Feb 3, 2022

A helm v3 plugin to get values from a previous release

helm-val helm-val is a helm plugin to fetch values from a previous release. Getting started Installation To install the plugin: $ helm plugin install

Dec 11, 2022

Plugin for Helm to integrate the sigstore ecosystem

helm-sigstore Plugin for Helm to integrate the sigstore ecosystem. Search, upload and verify signed Helm Charts in the Rekor Transparency Log. Info he

Dec 21, 2022

Application open new tab in chrome when your favourite youtuber add new video.

youtube-opener This application open new tab in Chrome when your favourite youtuber add new video. It checks channel every one minute. How to run go r

Jan 16, 2022

CoreDNS plugin implementing K8s multi-cluster services DNS spec.

corends-multicluster Name multicluster - implementation of Multicluster DNS Description This plugin implements the Kubernetes DNS-Based Multicluster S

Dec 3, 2022

K8s-socketcan - Virtual SocketCAN Kubernetes device plugin

Virtual SocketCAN Kubernetes device plugin This plugins enables you to create vi

Feb 15, 2022

A kubectl plugin for easier query and operate k8s cluster.

A kubectl plugin for easier query and operate k8s cluster.

kube-query A kubectl plug-in that makes it easier to query and manipulate K8S clusters. (what is kubectl plug-in ?) Kube-query support some resource s

Jun 9, 2022

A kubernetes plugin which enables dynamically add or remove GPU resources for a running Pod

A kubernetes plugin which enables dynamically add or remove GPU resources for a running Pod

GPU Mounter GPU Mounter is a kubernetes plugin which enables add or remove GPU resources for running Pods. This Introduction(In Chinese) is recommende

Jan 5, 2023
Comments
  • Multiple matches for plural api resources causes issues

    Multiple matches for plural api resources causes issues

    When pointing to for example 'networkpolicies' in the helm adopt command, its matching against the first one it finds, however many of my objects use the second api group instead.

    networkpolicies crd.projectcalico.org true NetworkPolicy networkpolicies netpol networking.k8s.io true NetworkPolicy

    I think the helm adopt command needs to possibly allow to (or make it mandatory) to specific explicitly the api group, in the case above I would give 'networkpolicies:networking.k8s.io:object1,object2', or something equivalent.

  • Not currently possible to adopt objects into an existing release

    Not currently possible to adopt objects into an existing release

    Is it possible to allow the possibility to adopt resources from one old release in to an already existing, new release without an error, before that new release is upgraded with a new chart containing that service.

    eg a service moving from one release to another. I guess this use case might benefit greatly from helm adopt being able to gather its resource list from a rendered target chart/ helm template yaml. For me a great use case to fulfill would be to hook into the existing helm install/upgrade commands, and by passing some argument --adopt-objects we could adopt objects where we previously would have seen an error that the objects already exist.

  • good job 2233333333323333333

    good job 2233333333323333333

    $ helm adopt resources gateways:nginx-gateway virtualservices:nginx-virtual  --output test --release test
    INFO[0000] Adopting resources..
    INFO[0000] Generating chart test
    INFO[0000] Added resource as file gateways-0 into test chart
    INFO[0000] Added resource as file virtualservices-0 into test chart
    INFO[0000] Chart test is released as test.1
    
    $ cat templates/gateways-0.yaml
    apiVersion: networking.istio.io/v1beta1
    kind: Gateway
    metadata:
      name: nginx-gateway
      namespace: default
    spec:
      selector:
        istio: ingressgateway
      servers:
      - hosts:
        - nginx.google.com
        port:
          name: https
          number: 443
          protocol: HTTPS
        tls:
          credentialName: secret-tls
          mode: SIMPLE
    $ cat templates/virtualservices-0.yaml
    apiVersion: networking.istio.io/v1beta1
    kind: VirtualService
    metadata:
      name: nginx-virtual
      namespace: default
    spec:
      gateways:
      - nginx-gateway
      hosts:
      - nginx.google.com
      http:
      - route:
        - destination:
            host: nginx.default.svc.cluster.local
            port:
              number: 80
    
Katenary - Convert docker-compose to a configurable helm chart
Katenary - Convert docker-compose to a configurable helm chart

Katenary is a tool to help transforming docker-compose files to a working Helm C

Dec 23, 2022
K8s-cinder-csi-plugin - K8s Pod Use Openstack Cinder Volume

k8s-cinder-csi-plugin K8s Pod Use Openstack Cinder Volume openstack volume list

Jul 18, 2022
A k8s vault webhook is a Kubernetes webhook that can inject secrets into Kubernetes resources by connecting to multiple secret managers
A k8s vault webhook is a Kubernetes webhook that can inject secrets into Kubernetes resources by connecting to multiple secret managers

k8s-vault-webhook is a Kubernetes admission webhook which listen for the events related to Kubernetes resources for injecting secret directly from sec

Oct 15, 2022
A tool to bring existing Azure resources under Terraform's management

Azure Terrafy A tool to bring your existing Azure resources under the management of Terraform. Install go install github.com/magodo/aztfy@latest Usage

Dec 9, 2021
A tool to bring existing Azure resources under Terraform's management

Azure Terrafy A tool to bring your existing Azure resources under the management of Terraform. Goal Azure Terrafy imports the resources inside a resou

Jan 1, 2023
Helm Operator is designed to managed the full lifecycle of Helm charts with Kubernetes CRD resource.

Helm Operator Helm Operator is designed to install and manage Helm charts with Kubernetes CRD resource. Helm Operator does not create the Helm release

Aug 25, 2022
helm-lint-ls is helm lint language server protocol LSP.

helm-lint-ls is helm lint language server protocol LSP.

Dec 27, 2022
Write controller-runtime based k8s controllers that read/write to git, not k8s

Git Backed Controller The basic idea is to write a k8s controller that runs against git and not k8s apiserver. So the controller is reading and writin

Dec 10, 2021
K8s-ingress-health-bot - A K8s Ingress Health Bot is a lightweight application to check the health of the ingress endpoints for a given kubernetes namespace.

k8s-ingress-health-bot A K8s Ingress Health Bot is a lightweight application to check the health of qualified ingress endpoints for a given kubernetes

Jan 2, 2022
K8s-go-structs - All k8s API Go structs

k8s-api go types Why? Its nice to have it all in a single package. . |-- pkg |

Jul 17, 2022