syncing of helmrelease through flux

98 Views Asked by At

I have an issue and I'm looking for more general answer approach or strategy. I have flux with HelmRelease that points to oct container registry. The chart stays static and has one deployment with image set to develop tag.

My setup pulls the image when I trigger chart version change, but I don't want to change the chart ver on each build(as chart hasn't changed), but rather have either flux or implement strategy that pulls a new image when the image digest differs from the one currently deployed.

My pipeline builds a new image every time there are changes to develop branch and adds new image to CR with develop tag.

So, again what I have is a deployment that is statically using an image reference with develop tag, but when image digest changes it is not pulled until I change chart version. Has anyone worked this out or faced similar situation?

These are my flux specs:

---
apiVersion: source.toolkit.fluxcd.io/v1beta2
kind: HelmRepository
metadata:
  name: nchart-repository
  namespace: flux-system
spec:
  interval: 1m0s
  url: oci://gitttt.asd.com:5050/company/assets/asd/chart
  type: oci
  secretRef:
    name: temp-credz
---
apiVersion: helm.toolkit.fluxcd.io/v2beta2
kind: HelmRelease
metadata:
  name: niccom-dev
  namespace: flux-system
spec:
  chart:
    spec:
      chart: ncom-chart
      sourceRef:
        kind: HelmRepository
        name: nchart-repository
      version: 0.1.6
      valuesFiles:
        - values-dev.yaml
      reconcileStrategy: Revision
  interval: 2m
  timeout: 1m
  driftDetection:
    mode: enabled

My chart I published to CR oci://gitttt.asd.com:5050/company/assets/asd/chart/ncom-chart:0.1.6

which contains a deployment with snippet of

containers:
      - name: {{ .Values.www.name }}
        image: "{{ .Values.base_repo.path }}{{ .Values.www.www_container_repository }}:{{ .Values.www.www_container_tag }}"

and after install through helm generates image value of gitttt.asd.com:5050/company/assets/xyz/www:develop

As I mentioned above it all works when I bump chart ver to 0.1.7 etc., but what I want is to keep chart static pointed to develop tag and just build an image.

1

There are 1 best solutions below

1
wajih tlili On

1- Utilize Kubernetes ImagePullPolicy:

  • Ensure that your Kubernetes deployment has its imagePullPolicy set to Always or IfNotPresent. This ensures that Kubernetes pulls the latest image every time the pod starts.

2- Update the Image Digest in HelmRelease:

  • Instead of updating the chart version in your HelmRelease, you can update the image digest directly.
  • Have your CI pipeline update the HelmRelease resource with the new image digest whenever a new image is built. You can use tools like kubectl patch or any other method your CI/CD system supports to update the HelmRelease resource.

3- Flux Image Update Automation:

  • Configure Flux to automatically update the HelmRelease resource whenever there is a change in the image digest.
  • You can achieve this by setting up a GitRepository or a HelmRepository for Flux to watch for changes in your HelmRelease resources.
  • Flux will automatically detect changes in the HelmRelease resources and apply them to your cluster.