How to configure customInitContainers in JFrog helm charts using custom values YAML file
This article will help to understand what is customInitContainers, why we use it and how we can configure it in the JFrog helm charts to deploy JFrog applications.
What are customInitContainers?
A Pod can have multiple containers running apps within it, but it can also have one or more init containers, which are run before the app containers are started.
Init containers are exactly like regular containers, except:
- Init containers always run to completion.
- Each init container must complete successfully before the next one starts.
If a Pod's init container fails, the kubelet repeatedly restarts that init container until it succeeds. However, if the Pod has a restartPolicy of Never, and an init container fails during startup of that Pod, Kubernetes treats the overall Pod as failed.
What do we use customInitContainers for?
Init Containers are used to perform tasks before a pod is deployed.
It’s sometimes necessary to prepare the main container which will be running our application or the main logic and it's accomplished through init containers.
There can also be situations where we need to execute particular utilities or setup scripts that are not present in our main image ( as it would make it heavy and we only need it once in the beginning ).
How to configure customInitContainers in JFrog helm charts?
If you need to add a custom init container, use the section for defining a custom init container in the values.yaml file (by default this section is commented out).
Syntax:
customInitContainers: |
- name: "custom-systemyaml-setup"
image: "{{ .Values.initContainerImage }}"
imagePullPolicy: "{{ .Values.imagePullPolicy }}"
command:
- 'sh'
- '-c'
- 'wget -O {{ .Values.xray.persistence.mountPath }}/etc/system.yaml https://<repo-url>/systemyaml'
volumeMounts:
- mountPath: "{{ .Values.xray.persistence.mountPath }}"
name: data-volume
For Artifactory
artifactory: ## Add custom init containers customInitContainers: | ## Init containers template goes here ##
For Xray
common: ## Add custom init containers executed before predefined init containers customInitContainersBegin: | ## Init containers template goes here ## ## Add custom init containers executed after predefined init containers customInitContainers: | ## Init containers template goes here ##
For Mission Control
common: ## Add custom init containers customInitContainers: | ## Init containers template goes here ##
For Distribution
distribution: ## Add custom init containers customInitContainers: | ## Init containers template goes here ##
Example:
Below is the sample example for Artifactory, where we are using the customInitContainers to copy the custom access config before starting Artifactory.
artifactory:
customInitContainers: |
- name: "custom-access-config-patch"
image: "{{ .Values.initContainerImage }}"
imagePullPolicy: "{{ .Values.artifactory.image.pullPolicy }}"
command:
- 'sh'
- '-c'
- 'mkdir -p {{ .Values.artifactory.persistence.mountPath }}/etc/access'
- 'cp -fv /tmp/etc/access.config.patch.yml {{ .Values.artifactory.persistence.mountPath }}/etc/access/access.config.patch.yml'
volumeMounts:
- mountPath: "{{ .Values.artifactory.persistence.mountPath }}"
name: volume
- name: access-config-patch
mountPath: "/tmp/etc/access.config.patch.yml"
subPath: access.config.patch.yml
customVolumes: |
- name: access-config-patch
secret:
secretName: access-config-patch-secret