Helm re-install resources that already exist

10,065

Solution 1

I think your main question is:

I have some custom resources that already exist so I want to re-install them.

Which means DELETE then CREATE again.

Short answer

No.. but it can be done thru workaround

Detailed answer

Helm manages the RELEASE of the Kubernetes manifests by either:

  • creating helm install
  • updating helm upgrade
  • deleting helm delete

However, you can recreate resources following one of these approaches :

1. Twice Consecutive Upgrade

If your chart is designed to enable/disable installation of resources with Values ( .e.g: .Values.customResources.enabled) you can do the following:

helm -n namespace upgrade <helm-release> <chart> --set customResources.enabled=false

# Then another Run
helm -n namespace upgrade <helm-release> <chart> --set customResources.enabled=true

So, if you are the builder of the chart, your task is to make the design functional.

2. Using helmfile hooks

Helmfile is Helm of Helm.

It manage your helm releases within a single file called helmfile.yaml.

Not only that, but it also can call some LOCAL commands before/or/after installing/or/upgrading a Helm release. This call which happen before or after, is named hook.

For your case, you will need presync hook.

If we organize your helm release as a Helmfile definition , it should be :

releases:
- name: <helm-release>
  chart: <chart>
  namespace: <namespace>
  hooks:
  - events: ["presync"]
    showlogs: true
    command: kubectl
    args: [ "-n", "{{`{{ .Release.Namespace }}`}}", "delete", "crd", "my-custom-resources" ]

Now you just need to run helmfile apply

I know that CRD are not namespaced, but I put namespace in the hook just to demonstrate that Helmfile can give you the namespace of release as variable and no need to repeat your self.

Solution 2

You can use helm upgrade to upgrade any existing deployed chart with changes.

The upgrade arguments must be a release and chart. The chart argument can be either: a chart reference(example/mariadb), a path to a chart directory, a packaged chart, or a fully qualified URL. For chart references, the latest version will be specified unless the --version flag is set.

To override values in a chart, use either the --values flag and pass in a file or use the --set flag and pass configuration from the command line, to force string values, use --set-string. In case a value is large and therefore you want not to use neither --values nor --set, use --set-file to read the single large value from file.

You can specify the --values'/'-f flag multiple times. The priority will be given to the last (right-most) file specified. For example, if both myvalues.yaml and override.yaml contained a key called 'Test', the value set in override.yaml would take precedence

For example

helm upgrade -f myvalues.yaml -f override.yaml redis ./redis
Share:
10,065

Related videos on Youtube

Riccardo Califano
Author by

Riccardo Califano

Updated on June 04, 2022

Comments

  • Riccardo Califano
    Riccardo Califano almost 2 years

    How can I execute "helm install" command and re-install resources that I have defined in "templates"? I have some custom resources that already exist so I want to re-install them. It is possible to do that through a parameter in helm command?

  • Riccardo Califano
    Riccardo Califano almost 4 years
    I have this error. I would reinstall this custom resource everytime helm install command is launched......helm upgrade --install --debug simulator-runtime .bob/simulator/simulator-1.0.0-h333cf6a.tgz --namespace=default --wait --timeout 900" Error: release simulator-runtime failed: certificate.tls "simulator-certificate" already exists