Skip to content

Instantly share code, notes, and snippets.

@pmoranga
Forked from metacoma/00_readme.md
Created August 13, 2020 07:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pmoranga/0b263079f94c18f61b8a44590abd059b to your computer and use it in GitHub Desktop.
Save pmoranga/0b263079f94c18f61b8a44590abd059b to your computer and use it in GitHub Desktop.
ArgoCD & Kapitan configuration

Using ArgoCD together with Kapitan is actually pretty easy and only requires the kapitan binary in the argo-repo-server and a ConfigManagement plugin in ArgocD (https://argoproj.github.io/argo-cd/user-guide/config-management-plugins/)

1. Edit argocd-cm configmap and add :

  configManagementPlugins: |
    - name: kapitan
      init:
        command: [sh]
        args: ["kapitan-base-compile.sh"]
      generate:
        command: [sh]
        args: ["kapitan-release.sh"]

2. Edit the argocm-repo-server deployment and add/update the following elements :

volumes
initContainers

See the file below for an example

3. place the following files in the root of your git repo (where your kapitan inventory lives)

kapitan-base-compile.sh

cd $(git rev-parse --show-toplevel)
kapitan compile --fetch --t $ARGOCD_APP_NAME

kapitan-release.sh

find ./compiled/$ARGOCD_APP_NAME -type f -name '*.yml' -exec printf "\n\n---\n\n" \; -exec cat {} \; | tee /tmp/all.yaml

4. Create an application in ArgoCD :

--repo https://github.com/acme/demo.git \
--path . \
--dest-server https://mycluster.azmk8s.io:443 \
--dest-namespace euw-dev-cd

The target name in your kapitan inventory should match the application name parameter in step 3

During the refresh step of ArgoCD the kapitan plugin (first) compile the target and then join all the relevant .yml files from the compiled folder to one big yaml file that is outputted to stdout for ArgoCD to consume.

when your kapitan produces .yaml files instead of .yml, update the kapitan-release.sh file accordingly

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
labels:
app.kubernetes.io/component: repo-server
app.kubernetes.io/name: argocd-repo-server
app.kubernetes.io/part-of: argocd
name: argocd-repo-server
namespace: argocd
spec:
progressDeadlineSeconds: 600
replicas: 1
revisionHistoryLimit: 10
selector:
matchLabels:
app.kubernetes.io/name: argocd-repo-server
strategy:
rollingUpdate:
maxSurge: 25%
maxUnavailable: 25%
type: RollingUpdate
template:
metadata:
creationTimestamp: null
labels:
app.kubernetes.io/name: argocd-repo-server
spec:
automountServiceAccountToken: false
containers:
- command:
- uid_entrypoint.sh
- argocd-repo-server
- --redis
- argocd-redis:6379
image: argoproj/argocd:v1.2.3
imagePullPolicy: Always
livenessProbe:
failureThreshold: 3
initialDelaySeconds: 5
periodSeconds: 10
successThreshold: 1
tcpSocket:
port: 8081
timeoutSeconds: 1
name: argocd-repo-server
ports:
- containerPort: 8081
protocol: TCP
- containerPort: 8084
protocol: TCP
readinessProbe:
failureThreshold: 3
initialDelaySeconds: 5
periodSeconds: 10
successThreshold: 1
tcpSocket:
port: 8081
timeoutSeconds: 1
resources: {}
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
volumeMounts:
- mountPath: /app/config/ssh
name: ssh-known-hosts
- mountPath: /app/config/tls
name: tls-certs
- mountPath: /usr/local/bin/kapitan
name: custom-tools
subPath: kapitan
dnsPolicy: ClusterFirst
initContainers:
- args:
- wget -q https://github.com/deepmind/kapitan/releases/download/v0.24.0/kapitan-linux-amd64 && mv
kapitan-linux-amd64 /custom-tools/kapitan && chmod +x /custom-tools/kapitan
command:
- sh
- -c
image: alpine:3.8
imagePullPolicy: IfNotPresent
name: download-tools
resources: {}
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
volumeMounts:
- mountPath: /custom-tools
name: custom-tools
restartPolicy: Always
schedulerName: default-scheduler
securityContext: {}
terminationGracePeriodSeconds: 30
volumes:
- configMap:
defaultMode: 420
name: argocd-ssh-known-hosts-cm
name: ssh-known-hosts
- configMap:
defaultMode: 420
name: argocd-tls-certs-cm
name: tls-certs
- emptyDir: {}
name: custom-tools
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment