You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/_posts/2024-06-06-cdks8s-through-argocd.md
+26-12Lines changed: 26 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,9 +7,10 @@ published: true
7
7
-[ArgoCD in short](#argocd-in-short)
8
8
-[cdk8s in short](#cdk8s-in-short)
9
9
-[An example](#an-example)
10
-
-[Adding a cdk8s plugin to argocd](#adding-a-cdk8s-plugin-to-argocd)
10
+
-[Adding a cdk8s plugin to ArgoCD](#adding-a-cdk8s-plugin-to-argocd)
11
11
-[Dockerfile](#dockerfile)
12
12
-[Plugging in as an argo-repo-server sidecar](#plugging-in-as-an-argo-repo-server-sidecar)
13
+
-[Results when using the plugin](#results-when-using-the-plugin)
13
14
-[ArgoCD documentation and further reading](#argocd-documentation-and-further-reading)
14
15
-[The point of all this](#the-point-of-all-this)
15
16
@@ -20,9 +21,7 @@ cdk8s is a tool from AWS to be able to deal with kubernetes manifests in an impe
20
21
21
22
## ArgoCD in short
22
23
23
-
Chances are if you are reading this you already know a bit about ArgoCD. It allows us to package kubernetes manifests in "applications" which helps to compartmentalize things that you are managing inside kubernetes as well as giving a cli and a UI in that abstraction level. For each application we can choose how we want to observe and synchronize the declared state of our application as ArgoCD he from git into kubernetes.
24
-
25
-
https://argo-cd.readthedocs.io/en/stable/
24
+
Chances are if you are reading this you already know a bit about [ArgoCD](https://argo-cd.readthedocs.io/en/stable/). It allows us to package kubernetes manifests in "applications" which helps to compartmentalize things that you are managing inside kubernetes as well as giving a cli and a UI in that abstraction level. For each application we can choose how we want ArgoCD to observe and synchronize the declared state of our application from git to kubernetes.
26
25
27
26
## cdk8s in short
28
27
@@ -146,15 +145,15 @@ spec:
146
145
147
146
```
148
147
149
-
## Adding a cdk8s plugin to argocd
148
+
## Adding a cdk8s plugin to ArgoCD
150
149
151
-
While learning about cdk8s I was surprised to learn that it didn't work out of the box with argocd, and that I couldn't find any pre-made plugins.
150
+
While learning about cdk8s I was surprised to learn that it didn't work out of the box with ArgoCD, and that I couldn't find any pre-made plugins.
152
151
153
-
I did however come across [this great post about cdk8s by Max Brenner](https://shipit.dev/posts/integrating-cdk8s-with-argocd.html) and also [their repository on how to run cdk8s in a container](https://github.com/brennerm/cdk8s-docker).
152
+
I did however come across [this great post about cdk8s by Max Brenner](https://shipit.dev/posts/integrating-cdk8s-with-ArgoCD.html) and also [their repository on how to run cdk8s in a container](https://github.com/brennerm/cdk8s-docker).
154
153
155
154
### Dockerfile
156
155
157
-
From there I built my own version of the typescript container such that it would work without running as root which argocd plugins are not allowed to do for good reason.
156
+
From there I built my own version of the typescript container such that it would work without running as root which ArgoCD plugins are not allowed to do for good reason.
158
157
159
158
```Dockerfile
160
159
# docker.io/dsoderlund/cdk8s:typescript
@@ -176,14 +175,22 @@ The entrypoint.sh script allows you to run this from the command line and get it
176
175
177
176
### Plugging in as an argo-repo-server sidecar
178
177
179
-
So the idea here is that we want argocd repository server to render the yaml for us by invoking `cdk8s synth` for an app just like it does for helm, kustomize, or plain yaml. It should do this if it knows that it is a cdk8s-typescript style apps which is evident by the presence of the file `./imports/k8s.ts`.
178
+
So the idea here is that we want ArgoCD repository server to render the yaml for us by invoking `cdk8s synth` for an app just like it does for helm, kustomize, or plain yaml. ArgoCD should do this if it can tell that it is seeing a cdk8s-typescript style application. This will be evident by the presence of the file `./imports/k8s.ts`.
180
179
181
-
There is a working example you can clone and run in [my reference platform github repo](https://github.com/QuadmanSWE/ds-ref-platform/blob/main/2_platform/argocd/kustomization.yaml). Here is what the running app looks like through argocd.
180
+
The execution has three parts, init, command, and discover.
182
181
183
-

182
+
- Init will run before anything else to make preparations. `npm install` will make sure the container has everything needed to perform the `cdk8s synth` step. This will be cached in the container and kept for future ArgoCD synchs of the app.
183
+
184
+
- Command executes the synth, ignores any direct output, and then reads the resulting file(s) from the dist folder.
185
+
186
+
- Discover helps repo-server know that this is infact a cdk8s-typescript style application and that this plugin applies.
187
+
188
+
There is a working example you can clone and run in [my reference platform github repo](https://github.com/QuadmanSWE/ds-ref-platform/blob/main/2_platform/argocd/kustomization.yaml).
189
+
190
+
This is an excerpt of that working example that highlights the parts that configures and injects the plugin.
184
191
185
192
```yaml
186
-
# ... Removed for brevity, imagine an argocd helm values declaration.
193
+
# ... Removed for brevity, imagine an ArgoCD helm values declaration.
187
194
configs:
188
195
cmp:
189
196
create: true
@@ -230,6 +237,13 @@ repoServer:
230
237
emptyDir: {}
231
238
```
232
239
240
+
### Results when using the plugin
241
+
242
+
Here is what the running app looks like through ArgoCD.
243
+
244
+

245
+
246
+
233
247
### ArgoCD documentation and further reading
234
248
235
249
[Here is the docs for how these config mangement plugins works.](https://argo-cd.readthedocs.io/en/stable/operator-manual/config-management-plugins/) I also recommend reading [this](https://dev.to/ali_nazari_f9773d74e0b0e4/using-cdk8s-ytt-or-gomplate-with-argocd-through-config-management-plugins-4f6g) and [this](https://codefresh.io/blog/using-argo-cds-new-config-management-plugins-to-build-kustomize-helm-and-more/) article which though using different approaches and a bit different end results than what I am after, do a great job in explaining what all the different parts are.
0 commit comments