commit f9f3f02afebec56b844266f3c858d12318682453 Author: Gilles Mouchet Date: Wed Oct 15 19:16:27 2025 +0200 original diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..2c838c6 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2023 Sam + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..cc432d6 --- /dev/null +++ b/README.md @@ -0,0 +1,118 @@ +# Overview +In this demo we will learn the basics of ArgoCD + +## Install the School App +```bash +# Setup MongoDB DB in K8s +kubectl create ns schoolapp +helm repo add bitnami https://charts.bitnami.com/bitnami +helm install schoolapp-mongodb --namespace schoolapp \ + --set auth.enabled=true \ + --set auth.rootUser=schoolapp \ + --set auth.rootPassword=mongoRootPass \ + bitnami/mongodb + +# Add project repo to helm +helm repo add schoolapp https://gitlab.com/api/v4/projects/34240616/packages/helm/stable + +# Install the Frontend +helm install frontend -n schoolapp schoolapp/schoolapp-frontend +# Install the API +helm install api -n schoolapp schoolapp/schoolapp-api +# Port forward the frontend +kubectl -n schoolapp port-forward service/frontend 8001:8080 +# Port forward the api +kubectl -n schoolapp port-forward service/api 5000:5000 +``` + +## Test the School App + +From a browser, go to http://127.0.0.1:8001 + +## ArgoCD Setup + +Now let's get ArgoCD ready for our school app. + +## Install ArgoCD + +### Install the ArgoCD Server + +```bash +kubectl create namespace argocd +kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml +``` + +Wait until all the pods are running + +```bash +watch kubectl get po +``` + +## Access ArgoCD + +### Expose the ArgoCD API Server + +```bash +kubectl port-forward svc/argocd-server -n argocd 8002:443 +``` + +### Get the admin password + +```bash +kubectl -n argocd get secret argocd-initial-admin-secret -o jsonpath="{.data.password}" | base64 -d; echo +``` + +For this demo, I won't change the password, but you should go ahead and change the password and remove the K8s secret. + +### Login using the UI + +You can log in to the UI by opening a browser window and going to https://127.0.0.1:8002 + +```bash +username: admin +password: +``` + +## School App Example with ArgoCD and Hardcoded Secrets + +Now let's see how to use a GitOps approach with ArgoCD to run our school app. + +## Delete the Current School App + +```bash +kubectl delete ns schoolapp +``` + +## Create the School App Application in ArgoCD + +```bash +kubectl apply -f argocdSchoolApp.yaml +``` + +## Test the School App with ArgoCD + +```bash +# Port forward the frontend +kubectl port-forward service/frontend 8001:8080 -n schoolapp +# Port forward the api +kubectl port-forward service/api 5000:5000 -n schoolapp +``` + +Try creating and deleting a course and check the logs of the api pod. + +```bash +kubectl logs -n schoolapp -f $(kubectl get pods --template '{{range .items}}{{.metadata.name}}{{end}}' --selector=app=api) -c api +``` + +## Making a Change in Git + +Now let's see how Argo CD can detect drift between the live state and the target state. Let's make a simple change in our Git repo for the called schoolapp-subchart/values.yaml. Change the mongodb.auth.enabled value from true to false. + +```yaml +mongodb: + auth: + enabled: false + rootUser: 'schoolapp' + rootPassword: 'mongoRootPass' +``` +Then commit and push your changes. diff --git a/argocdSchoolApp.yaml b/argocdSchoolApp.yaml new file mode 100644 index 0000000..2a3f08b --- /dev/null +++ b/argocdSchoolApp.yaml @@ -0,0 +1,17 @@ +apiVersion: argoproj.io/v1alpha1 +kind: Application +metadata: + name: schoolapp + namespace: argocd +spec: + destination: + namespace: schoolapp + server: 'https://kubernetes.default.svc' + source: + path: schoolapp-subchart + repoURL: 'https://github.com/samgabrail/env0-argocd.git' + targetRevision: HEAD + project: default + syncPolicy: + syncOptions: + - CreateNamespace=true \ No newline at end of file diff --git a/schoolapp-subchart/Chart.lock b/schoolapp-subchart/Chart.lock new file mode 100644 index 0000000..4b795ee --- /dev/null +++ b/schoolapp-subchart/Chart.lock @@ -0,0 +1,12 @@ +dependencies: +- name: schoolapp-frontend + repository: https://gitlab.com/api/v4/projects/34240616/packages/helm/stable + version: 0.5.8 +- name: schoolapp-api + repository: https://gitlab.com/api/v4/projects/34240616/packages/helm/stable + version: 0.5.8 +- name: mongodb + repository: https://charts.bitnami.com/bitnami + version: 11.1.1 +digest: sha256:011d9f270e259d2fa11a8fe98444957281741c23b95c12f11c292c030539e7f3 +generated: "2022-05-10T20:08:39.4974464Z" diff --git a/schoolapp-subchart/Chart.yaml b/schoolapp-subchart/Chart.yaml new file mode 100644 index 0000000..03a6ae7 --- /dev/null +++ b/schoolapp-subchart/Chart.yaml @@ -0,0 +1,16 @@ +--- +apiVersion: v2 +name: schoolapp-subchart +type: application +version: 1.0.0 +appVersion: "1.0.0" +dependencies: +- name: schoolapp-frontend + version: 0.5.8 + repository: https://gitlab.com/api/v4/projects/34240616/packages/helm/stable +- name: schoolapp-api + version: 0.5.8 + repository: https://gitlab.com/api/v4/projects/34240616/packages/helm/stable +- name: mongodb + version: 11.1.1 + repository: https://charts.bitnami.com/bitnami \ No newline at end of file diff --git a/schoolapp-subchart/charts/mongodb-11.1.1.tgz b/schoolapp-subchart/charts/mongodb-11.1.1.tgz new file mode 100644 index 0000000..1072547 Binary files /dev/null and b/schoolapp-subchart/charts/mongodb-11.1.1.tgz differ diff --git a/schoolapp-subchart/charts/schoolapp-api-0.5.8.tgz b/schoolapp-subchart/charts/schoolapp-api-0.5.8.tgz new file mode 100644 index 0000000..10c8eaf Binary files /dev/null and b/schoolapp-subchart/charts/schoolapp-api-0.5.8.tgz differ diff --git a/schoolapp-subchart/charts/schoolapp-frontend-0.5.8.tgz b/schoolapp-subchart/charts/schoolapp-frontend-0.5.8.tgz new file mode 100644 index 0000000..26d2a16 Binary files /dev/null and b/schoolapp-subchart/charts/schoolapp-frontend-0.5.8.tgz differ diff --git a/schoolapp-subchart/values.yaml b/schoolapp-subchart/values.yaml new file mode 100644 index 0000000..065c550 --- /dev/null +++ b/schoolapp-subchart/values.yaml @@ -0,0 +1,13 @@ +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. + +mongodb: + auth: + enabled: true + rootUser: 'schoolapp' + rootPassword: 'mongoRootPass' + +schoolapp-api: + vault: + status: 'disabled' + kind: 'disabled' \ No newline at end of file