Skip to main content

Argo CD with GitLab CI, Part 1: Table of Contents, Mermaid Flowchart, Setup Overview

998 words·
Argo CD Argo CD CLI GitLab GitLab CI CI Pipeline Kubernetes CoreDNS Python Flask Mermaid Flowchart
Table of Contents
ArgoCD - This article is part of a series.
Part 1: This Article
GitHub Repository Available



Table of Contents
#

Part 1: Table of Contents & Overview
#

  1. Table of Contents

  2. Mermaid Flowchart

    2.1 Main Flowchart

    2.2 Permissions Flowchart

  3. Setup Overview

    3.1 GitLab & Kubernetes Setup

    3.2 GitLab Repositories

     3.2.1 Code and Pipeline Project
    
     3.2.2 Helm Chart Project
    

Part 2: GitLab Repositories
#

  1. GitLab Repository: Flask App - Code & Pipeline

    1.1 File & Folder Structure

    1.2 CI Pipeline Manifest

    1.3 Dockerfile

    1.4 Python Code

     1.4.1 Flask Application: app.py
    
     1.4.2 Requirements: requirements.txt
    
  2. GitLab Repository: Flask App - Manifest

    2.1 File & Folder Structure

    2.2 Helm Chart

     2.2.1 deployment.yaml
    
     2.2.2 service.yaml
    
     2.2.3 values.yaml
    
     2.2.4 Chart.yaml
    
  3. GitLab Deploy Key: For CI Pipeline

    3.1 Create SSH Key Pair

    3.2 Add Public Key to Helm Project

    3.3 Add Private Key to Pipeline Project

  4. Verify Image Name

    4.1 Job Logs

    4.2 Helm Chart values.yaml


Part 3: Setting Up Argo CD CLI and CoreDNS
#

  1. Argo CD Installation

    1.1 Create Namespace

    1.2 Install Argo CD

    1.3 Verify Installation / Resources

    1.4 Adapt Argo CD Service

    1.4.1 Convert ClusterIP to LoadBalancer Service
    
    1.4.2 Verify Service Details
    
    1.4.3 Custom TLS Certificate Secret
    

    1.5 Argo CD Webinterface

    1.5.1 DNS Entry
    
    1.5.2 Access Webinterface
    
    1.5.3 Initial Admin Password
    
  2. Argo CD CLI Installation

    2.1 Install Argo CD CLI

    2.2 Argo CD CLI Configuration

     2.2.1 Argo CD DNS Entry
    
     2.2.3 Set Argo CD Server Address
    
  3. GitLab DNS Entry

    3.1 Add DNS Entry

    3.2 CoreDNS ConfigMap

     3.2.1 Backup the ConfigMap
    
     3.2.2 Add GitLab DNS Entry
    
     3.2.3 Verify DNS Resolution
    

Part 4: Argo CD Configuration
#

  1. Kubernetes Cluster Requirements

    1.1 Create Namespace for the Flask-App

  2. GitLab Host Keys

    2.1 Scan GitLab Host Keys

    2.2 Add GitLab Host Keys to Argo CD

  3. GitLab Deploy Key: For Argo CD

    3.1 Create SSH Key Pair

    3.2 Add Public SSH Key to GitLab Repository

  4. GitLab Project Access Token

    4.1 Create Project Access Token

    4.2 Copy Project Token User

    4.3 Create GitLab Registry Secret

    4.4 Verify the Secret

  5. Argo CD Setup

    5.1 Connect GitLab Repository

    5.2 Verify GitLab Repository

    5.3 Create an Argo CD Application

     5.3.1 Manifest Version
    
     5.3.2 CLI Version
    
     5.3.3 Explanation
    

    5.4 Verify the Argo CD Application

    5.5 Very Flask Web App Deployment

    5.6 Manually Trigger Synchronization

    5.7 Delete Argo CD Application



Overview
#

Mermaid Flowchart
#

Main Flowchart
#

graph TD Dev(Developer) -.->|Push changes| A1 %% Code Repo subgraph A[Code Repository] A1[Source Code
Dependencies] -.->|Trigger pipeline| A3[CI Pipeline Manifest] A2[Dockerfile] end A3 -.-> B %% Pipeline %% Pipeline subgraph B[GitLab CI Pipeline] B1(Stage 1: build_image) -.->|Job dependency| B2(Stage 2: update_helm_chart) end %% Build Stage B1 -.-> BuildStageGroup subgraph BuildStageGroup["Build Stage"] S3A("Login to GitLab Container Registry") -.-> S3B("Build image from Dockerfile") S3B -.-> S3C("Push image to GitLab Container Registry") end %% Dockerfile S3B -.-> D1 D2 -.->|Containerized Application| S3C subgraph Dockerfile["Dockerfile"] D1("Build Image") -.->|Compiled Source| D2("Runtime Image") end A1 -.-> D1 B2 -.->|Update values| C2 A2 -.-> Dockerfile S3C -.->|Push image| Registry(GitLab Registry) %% Helm Repo subgraph C[Helm Chart Repository] C1[Templates] C2[values.yaml] end Argo(Argo CD) -.->|Sync changes| C Argo(Argo CD) -.->|Deploy changes| K8s(Kubernetes Cluster) K8s -.->|Pull image| Registry %% Styling for Bold and Larger Text classDef boldLargeText font-weight:bold class Dev,A,B,BuildStageGroup,Dockerfile,C,K8s,Registry,Argo boldLargeText %% Bigger Front Size style Dev font-size:24px style Argo font-size:24px style Registry font-size:24px style K8s font-size:24px %% Bigger Border classDef themeColor stroke-width:3px; class A,C themeColor %% Dashed Border classDef themeColor2 stroke-dasharray:5 5; class B,BuildStageGroup,Dockerfile themeColor2



Permissions Flowchart
#

The following flowchart shows the GitLab Deploy Keys, GitLab Access Token and Kubernetes Secret for the necessary permissions:

graph TD %% Code Repo subgraph A[Code Repository] A1[Source Code] A3[CI Pipeline Manifest] A2[Dockerfile] end %% Helm Repo subgraph C[Helm Chart Repository] C1[Templates] C2[values.yaml] end A -.->|CI variable| KP1A C -.->|Deploy key| KP1B %% SSH Key Pair 1 subgraph keypair1["SSH Key Pair"] KP1A(pipeline_key) KP1B(pipeline_key.pub) end ArgoCLI(Argo CD CLI) -.-> KP2A ArgoCLI -.->|Connect GitLab Repository| Argo C -.->|Deploy key| KP2B %% SSH Key Pair 2 subgraph keypair2["SSH Key Pair"] KP2B(argocd_repo_key.pub) KP2A(argocd_repo_key) end A -.-> keypair3 Secret -.-> keypair3 K8s -.->|Access GitLab Registry| Secret(Kubernetes Secret) %% Project Access Token subgraph keypair3["Project Access Token"] KP3A(read_registry) end Argo(Argo CD) -.->|Sync changes| C Argo(Argo CD) -.->|Deploy changes| K8s(Kubernetes Cluster) %% Styling for Bold and Larger Text classDef boldLargeText font-weight:bold class A,B,BuildStageGroup,Dockerfile,C,K8s,Argo boldLargeText %% Bigger Front Size style Argo font-size:24px style K8s font-size:24px %% Dashes classDef dashedOutline stroke-dasharray: 5,5; class keypair1,keypair2,keypair3 dashedOutline %% Bigger Border classDef themeColor stroke-width:3px; class A,C themeColor



GitLab & Kubernetes Setup
#

  • I’m using a Kubeadm based K8s cluster with one controller and three worker nodes, MetalLB LoadBalancer and Nginx Ingress.

  • GitLab is containerized

  • Argo CD CLI is installed on the Kubernetes control plane

192.168.70.4 # GitLab / GitLab Registry: "gitlab.jklug.work", "gitlab-registry.jklug.work"
192.168.70.5 # GitLab Runner

# Kubernetes Cluster
NAME      STATUS   ROLES           AGE   VERSION    INTERNAL-IP     EXTERNAL-IP   OS-IMAGE             KERNEL-VERSION     CONTAINER-RUNTIME
ubuntu1   Ready    control-plane   12d   v1.29.11   192.168.30.10   <none>        Ubuntu 24.04.1 LTS   6.8.0-49-generic   containerd://1.7.23
ubuntu2   Ready    worker          12d   v1.29.11   192.168.30.11   <none>        Ubuntu 24.04.1 LTS   6.8.0-49-generic   containerd://1.7.23
ubuntu3   Ready    worker          12d   v1.29.11   192.168.30.12   <none>        Ubuntu 24.04.1 LTS   6.8.0-49-generic   containerd://1.7.23
ubuntu4   Ready    worker          12d   v1.29.11   192.168.30.13   <none>        Ubuntu 24.04.1 LTS   6.8.0-49-generic   containerd://1.7.23



GitLab Repositories
#

Code and Pipeline Repository
#

The GitLab repository flask-app-code is used for the source code of the Java Flask web application and the CI pipeline.

# "flask-app-code"
git@gitlab.jklug.work:python/flask-app-code.git

GitHub Repository:
https://github.com/jueklu/gitlab-ci-adapt-helm-chart_pt1


File and folder structure:

flask-app-code
├── Dockerfiles
│   └── Dockerfile
├── flask-app  # Python Flask web application
│   ├── app.py
│   └── requirements.txt
├── .gitlab-ci.yml  # GitLab CI Pipeline manifest
└── README.md

Helm Chart Repository
#

The GitLab repository flask-app-helm is used for the Helm chart, that is deployed via argo CD.

# "flask-app-helm"
git@gitlab.jklug.work:python/flask-app-helm.git

GitHub Repository:
https://github.com/jueklu/gitlab-ci-adapt-helm-chart_pt2


File and folder structure:

flask-app-helm
├── helm-chart  # Helm chart
│   ├── Chart.yaml
│   ├── templates
│   │   ├── deployment.yaml
│   │   └── service.yaml
│   └── values.yaml
└── README.md





Links #

# Official Documentation: Installation
https://argo-cd.readthedocs.io/en/stable/getting_started/

# Official Documentation: TLS Certificates
https://argo-cd.readthedocs.io/en/stable/operator-manual/tls/

jueklu/gitlab-ci-adapt-helm-chart_pt1

GitLab CI Pipeline the containerizes a Python Flask web application and updates a Helm chart located in another repository.

Dockerfile
0
0

jueklu/gitlab-ci-adapt-helm-chart_pt2

Simple Helm chart example for the Argo CD deployment of a Python Flask web application.

null
0
0
ArgoCD - This article is part of a series.
Part 1: This Article