# Fix a Flux HelmRelease that never becomes Ready

> A HelmRelease fails three times over: no chart version matches, the values reference is wrong, then the install times out. Fix each layer.

Level: Advanced · Topic: GitOps · About 15 minutes
Try it in the browser: https://k8wiz.com/playground/fix-a-flux-helmrelease-that-is-not-ready

The playground is a simulated Kubernetes cluster that runs in the browser. kubectl output and errors follow the real ones.

## The situation

Flux should install the `api` chart into the `shop` namespace from the `k8wiz` HelmRepository. The HelmRelease has been `False` since it was created and no Pod has ever started.

There is more than one fault, and each only shows once the one before it is fixed. Work down the chain: the chart source, the values Flux composes, then the Helm install itself.

The chart needs a Secret holding the database URL. The platform team created `api-db` in `shop` for that.

## Objectives

1. Read why the HelmRelease isn't Ready (`flux get helmreleases -n shop` or `kubectl describe helmrelease api`)
2. The HelmChart resolves to a chart version that exists (`helm search repo k8wiz/api --versions` lists what the repository has)
3. Flux composes the values from the api-values ConfigMap
4. The HelmRelease is Ready and api runs 2 replicas

## Hints

1. `flux get helmreleases -n shop` says the HelmChart `flux-system/shop-api` isn't ready: no `api` chart matches version `2.x`. helm-controller creates that HelmChart object from `spec.chart.spec`. `helm repo add k8wiz https://charts.k8wiz.dev && helm search repo k8wiz/api --versions` shows the newest is 1.0.0.
2. kubectl patch helmrelease api --type=merge -p '{"spec":{"chart":{"spec":{"version":"1.x"}}}}'
3. The next message is about the values reference: `valuesFrom` reads the key `values.yaml` unless `valuesKey` says otherwise, and `kubectl get configmap api-values -o yaml` shows the key is `values.yml`. Set `valuesKey: values.yml` on the reference, or recreate the ConfigMap with the default key.
4. Now Flux runs the install and Pods appear, in `CreateContainerConfigError`. `kubectl describe pod` says the Secret `api-db` has no key `url`. After `timeout: 1m` the install fails with `context deadline exceeded` and Flux uninstalls it.
5. `kubectl create secret generic api-db --from-literal=url=postgres://api:s3cret@db.shop.svc:5432/orders --dry-run=client -o yaml | kubectl apply -f -`, then `flux reconcile helmrelease api -n shop` to retry now and wait for the result.

## Solution

```bash
flux get helmreleases -n shop
```
```bash
kubectl patch helmrelease api --type=merge -p '{"spec":{"chart":{"spec":{"version":"1.x"}}}}'
```
```bash
kubectl patch helmrelease api --type=merge -p '{"spec":{"valuesFrom":[{"kind":"ConfigMap","name":"api-values","valuesKey":"values.yml"}]}}'
```
```bash
kubectl create secret generic api-db --from-literal=url=postgres://api:s3cret@db.shop.svc:5432/orders --dry-run=client -o yaml | kubectl apply -f -
```
```bash
flux reconcile helmrelease api -n shop
```

## What it teaches

- A HelmRelease depends on three objects in a row: the HelmRepository, the HelmChart that helm-controller creates from `spec.chart.spec`, and the release itself. The Ready message names the first one that failed.
- `spec.chart.spec.version` is a semver range. A range that matches nothing fails at the HelmChart, before any values are read.
- `valuesFrom` merges ConfigMaps and Secrets in order, with `spec.values` on top. It reads the key `values.yaml` unless `valuesKey` names another, and a missing key is an error unless the reference is `optional`.
- `spec.timeout` is how long Helm waits for the release's workloads. A failed install is uninstalled by default, so Pods that never start come and go until the cause is fixed.
- The `flux` command line works in `flux-system` unless you pass `-n`. `flux reconcile helmrelease NAME -n NAMESPACE` retries at once; without it Flux waits for the next interval or retry.
