Skip to content

ArgoCD Hands-on

Interactive Diagram

새 탭 ↗

ArgoCD GitOps CD

  • Jenkins configuration
    • Jenkins installation and Plugin setting
    • Pipeline configuration (Github, Docker Hub integration, etc.)
  • ArgoCD
    • ArgoCD installation
    • ArgoCD CLI
    • ArgoCD configuration (Project and Application creation, ArgoCD Image Updater setup)
  • Add helm repo
Terminal window
helm repo add jenkins https://charts.jenkins.io
# change Service Type to LoadBalancer for external Jenkins access and install
helm install [RELEASE_NAME] jenkins/jenkins
  • Integrate Jenkins with gitHub
    • Create a Credential in GitHub: Go to the Github Setting > Developer settings menu, then go to the Personal access tokens menu as shown below. Next, select the Generate new token menu in the top right.
    • Configure the GitHub connection in Jenkins: Go to the Jenkins > Manage Jenkins > Configure System menu and add the GitHub account configuration
  • Integrate Jenkins with Docker Hub
    • In the Jenkins > Manage Jenkins > Manage Credentials menu, add a ‘Username with password’ type Credential for Docker hub integration
  • Pipeline configuration
    • Dockerfile example
    Dockerfile
    # base image
    FROM adoptopenjdk/openjdk11
    # copy build/libs/*.jar from the temp image to app.jar
    COPY build/libs/kiki.jar app.jar
    # expose container port 8080
    EXPOSE 8080
    CMD ["java","-jar","/app.jar"]
    • Jenkinsfile example
    Jenkinsfile
    podTemplate(label: 'docker-build',
    containers: [
    22 collapsed lines
    containerTemplate(
    name: 'git',
    image: 'alpine/git',
    command: 'cat',
    ttyEnabled: true
    ),
    containerTemplate(
    name: 'docker',
    image: 'docker',
    command: 'cat',
    ttyEnabled: true
    ),
    containerTemplate(
    name: 'gradle',
    image: 'gradle:7.1.0-jdk11',
    command: 'cat',
    ttyEnabled: true
    )
    ],
    volumes: [
    hostPathVolume(mountPath: '/var/run/docker.sock', hostPath: '/var/run/docker.sock'),
    ]
    ) {
    node('docker-build') {
    def dockerHubCred = "docker_hub_id"
    def appImage
    stage('Checkout'){
    git (
    branch: 'master',
    credentialsId: 'heyKim',
    url: 'https://github.com/heyKim/todo.git'
    )
    }
    stage('Test'){
    container('gradle'){
    script {
    sh 'chmod 755 ./gradlew'
    sh 'java -version'
    sh 'printenv|sort'
    // sh './gradlew test'
    sh './gradlew build -x test'
    }
    }
    }
    stage('Build'){
    container('docker'){
    script {
    appImage = docker.build("jkk3366/jenkins")
    }
    }
    }
    stage('Push'){
    container('docker'){
    script {
    docker.withRegistry('https://registry.hub.docker.com', dockerHubCred){
    appImage.push("${env.BUILD_NUMBER}")
    appImage.push("latest")
    }
    }
    }
    }
    }
    }
  • Add helm repo
Terminal window
helm repo add argo https://argoproj.github.io/argo-helm
  • Download the source to modify the config, then install argocd after modifying the source
Terminal window
# download source
helm fetch argo/argo-cd
# modify source
# change only Service Type from ClusterIP to LoadBalancer for external access to the argocd server
# install argocd via helm install
helm install "specify argo cd name" argo/argo-cd
# when you want to apply the values.yaml modified during installation
helm install "specify argo cd name" argo/argo-cd -f ./values.yaml
  • Check the password after installation
Terminal window
# check the password from the secret (id defaults to admin)
kubectl -n argocd get secret argocd-initial-admin-secret -o jsonpath="{.data.password}" | base64 -d
# `argocd-initial-admin-secret` reportedly needs the namespace removed after changing the password (per the official site).

ArgoCD main screen

ArgoCD main screen ArgoCD provides a CRD (Custom Resource Definition) called Application. An Application is a bundle of Kubernetes resources and is responsible for deployment.

ArgoCD App creation 1 ArgoCD App creation 2 ArgoCD App creation 3

  • Application Name: Enter the name of the App.
  • Project: The field for selecting a project. A concept similar to Kubernetes namespaces, it allows you to logically separate and manage multiple Apps into projects.
  • Sync Policy: Determines how changes in the Git repository are synced. Auto automatically reflects changes in the Git repository into operations, while Manual requires the user to reflect them into operations directly via a button click or API.
  • Repository URL: Means the Git repository that ArgoCD will watch
  • Revision: Determines which revision of Git (HEAD, master branch, etc.) to watch
  • Path: Determines which directory in the Git repository to watch. (In the case of a dot(.), the root path; if you enter a directory name, it tracks only the deployment manifest of that directory)
  • Cluster: Determines which Kubernetes cluster to deploy to
  • Namespace: Determines which namespace of the Kubernetes cluster to deploy to
  • Select the Kubernetes manifests Tool: Select the tool to define the Kubernetes manifest and enter the configuration information.

ArgoCD App creation 4 After creating the ArgoCD Application, it is in the OutOfSync state because it is before synchronization

ArgoCD App creation 5 When the namespace of the Deployment is changed in the config repo, it detects this and indicates that synchronization is needed

  • A feature that automatically updates the container image of k8s workloads managed by Argo CD.
  • Without needing to manually update the image version, etc. in the resource yaml, it automatically detects updates of new images and applies them to the k8s workload.
  • It is configured by adding annotations to the Application resource managed by Argo CD.

NOTE: This is a feature still under development.

  1. Install argocd-image-updater
Terminal window
# install on the k8s workload where argocd is installed
git clone https://github.com/argoproj-labs/argocd-image-updater/blob/master/manifests/install.yaml
# Apply the installation manifests¶
kubectl apply -n argocd -f manifests/install.yaml
  1. Grant Access permissions for the Docker Registry
  2. Add annotations to the ArgoCD Application To configure the Auto Image Updater, you need to add annotations. You can add the annotations with the command below
Terminal window
kubectl annotate app argocd-updater-test -n argocd\
argocd-image-updater.argoproj.io/image-list=registry-1.docker.io/jkk3366/jenkins \
argocd-image-updater.argoproj.io/todo.force-update=true \
argocd-image-updater.argoproj.io/write-back-method=git

You can also add the annotations below in the ArgoCD UI.

Terminal window
argocd-image-updater.argoproj.io/image-list: jkk3366/jenkins
argocd-image-updater.argoproj.io/todo.force-update: true
argocd-image-updater.argoproj.io/write-back-method: git
  1. Easy Config modification
  • As-Is The configuration information is included inside the Docker Image, so properties are managed statically.
    Because the config is not separated from the application source, you have to go through the build process to modify the config.

  • To-Be Separate CI/CD and manage dynamically by leveraging the kustomize feature that creates properties as a ConfigMap.

    • ConfigMap repository example.
    • kustomization.yaml
    • Directoryprd
      • Directorybackend001
        • application-api.yml
        • application-db.yml
        • application.yml
      • Directorybackend002
        • application-api.yml
        • application-db.yml
        • application.yml
    • Kustomization configMapGenerator example
    apiVersion: kustomize.config.k8s.io/v1beta1
    kind: Kustomization
    ...
    configMapGenerator:
    - name: account
    files:
    - ./prd/backend001/application.yml
    - ./prd/backend001/application-api.yml
    - ./prd/backend001/application-db.yml
    - name: apigateway
    files:
    - ./prd/backend002/application.yml
    - ./prd/backend002/application-api.yml
    - ./prd/backend002/application-db.yml
  1. Deployment (CD) without building is possible
  • As-Is argocd-cd-asis Currently, when building monitoring, filebeat, metricbeat, prometheus, elasticsearch, etc. are installed manually via the kubectl apply -f or helm install commands, so change management and version management are absent and Human error easily occurs
  • To-Be
    The state defined in the git repo and the cluster are kept identical, making management easy.
  1. Easy Multi Cluster management
  • As-Is To install metricbeat on hundreds of clusters, you have to install it manually hundreds of times, which is inefficient

  • To-Be Using argocd, even when a new cluster is added, you can simply add the cluster configuration and maintain the same shape across multiple clusters without separate processing.

  1. helm deployment without a Helm Chart Repo
  • As-Is The ICP Helm Chart Repo is in use, so an alternative is needed for helm deployment to a Native K8S Cluster that is not ICP.
  • To-Be Through ArgoCD-based helm deployment, it can be used without separately maintaining a helm chart repo.