ARgo CD and OpenShift , Kubernetes - unix1998/technical_notes GitHub Wiki

Argo CD can be deployed on both OpenShift and Kubernetes, and it can be configured to automatically update or redeploy an application whenever there are changes in the source repository (such as a Java Spring Boot application). Here’s how this process typically works:

  1. Deployment of Argo CD:

    • Argo CD can be installed on Kubernetes clusters including OpenShift. The deployment process involves creating namespaces, roles, service accounts, and deploying the Argo CD components (API server, controller, repo server, and UI server).
  2. Connecting Argo CD to GitHub:

    • After Argo CD is deployed, it needs to be connected to your GitHub repository. This is done by creating an application in Argo CD and specifying the GitHub repository URL and the path within the repository where the Kubernetes manifests or Helm charts for your application are located.
  3. Configuration of Auto-Sync:

    • To ensure that Argo CD automatically synchronizes the state of the cluster with the desired state defined in the GitHub repository, enable the auto-sync feature. This ensures that any changes pushed to the GitHub repository trigger an update or redeployment of the application.
  4. Workflow:

    • Code Changes: When you make changes to your Java code or configuration files and push these changes to your GitHub repository, Argo CD detects these changes.
    • Sync Operation: Argo CD synchronizes the cluster with the desired state by pulling the latest code and applying the updated manifests or Helm charts. This can include updating Kubernetes Deployments, Services, ConfigMaps, Secrets, etc.
    • Deployment: The application in your cluster is updated or redeployed based on the changes in the repository.

Step-by-Step Process:

  1. Install Argo CD on OpenShift/Kubernetes:

  2. Create an Argo CD Application:

    • Use the Argo CD UI or CLI to create an application. Specify the GitHub repository URL and the path where your Kubernetes manifests are stored.
    apiVersion: argoproj.io/v1alpha1
    kind: Application
    metadata:
      name: my-java-app
      namespace: argocd
    spec:
      project: default
      source:
        repoURL: 'https://github.com/my-org/my-java-app-repo'
        targetRevision: HEAD
        path: 'k8s-manifests'
      destination:
        server: 'https://kubernetes.default.svc'
        namespace: my-app-namespace
      syncPolicy:
        automated:
          prune: true
          selfHeal: true
    
  3. Enable Auto-Sync:

    • Ensure that auto-sync is enabled in the syncPolicy section of the Argo CD Application manifest. This allows Argo CD to automatically synchronize whenever it detects changes in the repository.
  4. Push Changes to GitHub:

    • Make changes to your Java code or configuration files, commit them, and push them to the specified branch in the GitHub repository.
  5. Argo CD Syncs and Redeploys:

    • Argo CD will automatically detect the changes, pull the latest code, and apply the updated manifests to your Kubernetes cluster, resulting in an updated deployment of your application.

Example of an Update Workflow:

  • You update a configuration file in your Spring Boot application (e.g., application.properties).
  • Commit and push the changes to your GitHub repository.
  • Argo CD detects the commit and triggers a synchronization.
  • Argo CD updates the relevant Kubernetes resources in the cluster.
  • Your application is redeployed with the new configuration.

This setup ensures a continuous delivery pipeline where your application is always up-to-date with the latest changes in your GitHub repository.

####################################################################################################################################

each application managed by Argo CD should have a corresponding YAML manifest file of kind Application with a unique name. This file specifies the configuration of the application, including its source repository, the target cluster, and the synchronization policy. You can create and manage these YAML files using the Argo CD UI or the Argo CD command-line interface (CLI).

Here's how you can use the Argo CD command-line interface (CLI) to create an application:

Prerequisites:

  • Make sure you have the Argo CD CLI (argocd) installed. You can download it from the official GitHub releases page.
  • Connect your Argo CD CLI to your Argo CD server. You can do this using the argocd login command.

Steps to Create an Application Using Argo CD CLI:

  1. Define your Application manifest file:

    Save the following YAML content to a file named my-java-app.yaml:

    apiVersion: argoproj.io/v1alpha1
    kind: Application
    metadata:
      name: my-java-app
      namespace: argocd
    spec:
      project: default
      source:
        repoURL: 'https://github.com/my-org/my-java-app-repo'
        targetRevision: HEAD
        path: 'k8s-manifests'
      destination:
        server: 'https://kubernetes.default.svc'
        namespace: my-app-namespace
      syncPolicy:
        automated:
          prune: true
          selfHeal: true
    

    Customize the fields according to your application's details. For example, replace my-java-app with your application's name, and adjust the repository URL, target revision, path, and destination namespace as needed.

  2. Create the Application:

    Use the argocd CLI to create the application by running the following command:

    argocd app create -f my-java-app.yaml
    

    This command will create the application defined in the my-java-app.yaml file.

  3. Verify the Application:

    You can verify that the application has been created by listing all applications:

    argocd app list
    

    You should see your application (my-java-app) listed among the applications managed by Argo CD.

Updating an Application Using Argo CD CLI:

If you need to update the configuration of an existing application, you can modify the corresponding YAML manifest file and then use the Argo CD CLI to apply the changes:

  1. Update the Application manifest file:

    Modify the my-java-app.yaml file according to the changes you want to make.

  2. Apply the Changes:

    Use the argocd CLI to apply the changes to the application:

    argocd app create -f my-java-app.yaml --force
    

    The --force flag will force the application to be created or updated.

This approach allows you to manage Argo CD applications using the command-line interface, providing flexibility and automation in the application lifecycle management process.