5.2. Kustomize
This lab explains how to use kustomize as manifest format together with Argo CD.
Kustomize Introduction
Kustomize
introduces a template-free way to customize application configuration that simplifies the use of off-the-shelf applications. It is built into kubectl and oc with the command kubectl apply -k or oc apply -k.
It uses a concept called overlays, which allows to reduce redundant configuration for multiple stages (e.g. dev, prod, test) without a use of a template language.
Argo CD supports kustomize manifests out of the box.
Kustomize Overlays
When you want to use Kustomize with an overlay, you have to point the Argo Application to the Overlay
Kustomize Configuration
The following configuration options are available for Kustomize:
namePrefixis a prefix appended to resources for Kustomize appsnameSuffixis a suffix appended to resources for Kustomize appsimagesis a list of Kustomize image overridescommonLabelsis a string map of an additional labelscommonAnnotationsis a string map of an additional annotations
Use the following command to set those parameters:
# In the Application spec.source.kustomize section:
namePrefix: <namePrefix>
Further Docs
Read more about the kustomize integration in the official documentation
Task 5.2.1: Deploy the simple-example with kustomize
Let’s deploy the simple-example from lab 1 using kustomize .
First you’ll have to create a new Argo CD application.
Create a file argocd-kustomize-application.yaml with the following content and apply it:
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: argo-kustomize-$USER
namespace: openshift-gitops
spec:
project: default
source:
repoURL: https://gitea.training.cluster.acend.ch/$USER/argocd-training-examples.git
targetRevision: HEAD
path: kustomize/simple-example
destination:
server: https://kubernetes.default.svc
namespace: $USER
oc apply -f argocd-kustomize-application.yaml
Sync the application
Hint
To sync (deploy) the resources you can simply click sync in the web UI.
And verify the deployment:
oc get pod --namespace $USER --watch
Tell the application to sync automatically, to enable self-healing and auto-prune
Hint
Edit argocd-kustomize-application.yaml to add automated sync policy, then re-apply:
syncPolicy:
automated:
selfHeal: true
prune: true
oc apply -f argocd-kustomize-application.yaml
Task 5.2.2: Set a configuration parameter
We can set the kustomize configuration parameter with the following command:
Edit argocd-kustomize-application.yaml to add the nameprefix in spec.source.kustomize, then re-apply:
kustomize:
namePrefix: acend
oc apply -f argocd-kustomize-application.yaml
And take a look at the application in the web UI.
Warning
Only use this way of setting params in dev and test stages. Not for Production!Task 5.2.3: Create a second application representing the production stage
Let’s now also deploy an application for the production stage.
This does mean we deploy an overlay which specifically configures the production stage.
Let’s create the production stage Argo CD application (path: kustomize/overlays-example/overlays/production) with the name argo-kustomize-prod-$USER and enable automated sync, self-healing and pruning.
Hint
Create a file argocd-kustomize-application-prod.yaml with the following content and apply it:
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: argo-kustomize-prod-$USER
namespace: openshift-gitops
spec:
project: default
source:
repoURL: https://gitea.training.cluster.acend.ch/$USER/argocd-training-examples.git
targetRevision: HEAD
path: kustomize/overlays-example/overlays/production
destination:
server: https://kubernetes.default.svc
namespace: $USER
syncPolicy:
automated:
selfHeal: true
prune: true
oc apply -f argocd-kustomize-application-prod.yaml
And verify the deployment:
oc get pod --namespace $USER --watch
Task 5.2.4: Delete the Applications
Delete the applications after you’ve explored the Argo CD Resources and the managed Kubernetes resources.
Hint
oc delete application argo-kustomize-$USER argo-kustomize-prod-$USER -n openshift-gitops