Location>code7788 >text

Argo CD First Experience

Popularity:710 ℃/2024-09-08 11:38:30

What is an Argo CD?

Argo CD is a declarative GitOps continuous delivery tool for Kubernetes clusters. It ensures that the actual state of the cluster is consistent with the configuration in the repository by continuously monitoring Kubernetes resource profiles in the Git repository and automatically applying those configurations to the specified Kubernetes cluster. argo CD supports various Kubernetes manifest formats such as Kustomize, Helm Charts, Ksonnet, YAML, and JSON, allowing you to manage and deploy Kubernetes resources through Git repositories.

Benefits of Argo CD

  1. declarative management: Argo CD uses a declarative management approach, where developers simply define the desired state of the application in a Git repository and Argo CD automatically synchronizes the actual state of the cluster with it. This reduces human error and makes configuration management clearer and more auditable.

  2. GitOps Workflow: Argo CD implements GitOps best practices by using Git repositories as the sole Source of Truth for configuration management. Every application deployment or update is triggered by a code commit and merge request, ensuring automation and audit trails.

  3. Continuous synchronization and self-healing: Argo CD continuously monitors the state of resources in a Kubernetes cluster and automatically corrects any deviations from the desired state as they are detected, so that the state of the cluster always matches the configuration in the Git repository.

  4. Multi-cluster support: Argo CD can manage multiple Kubernetes clusters, making it easier to deploy and manage applications across clusters.

  5. fine-grained access control: Argo CD provides a fine-grained access control mechanism that allows role-based access control (RBAC) as well as control of access rights to specific projects and applications through SSO integration.

Argo CD vs Jenkins

functionality Argo CD Jenkins
build Focus on declarative deployment of Kubernetes clusters Generic CI/CD tool supporting multiple programming languages and environments
GitOps Support Built-in support for GitOps workflows, with Git as the only source of truth Need to support GitOps workflows via plugins or custom scripts
Deployment automation Automatically synchronize Kubernetes provisioning for continuous cluster consistency Manual configuration of the deployment process via pipeline
Observability and rollback Built-in monitoring and automatic rollback Realized through third-party tools or plug-ins
Plug-in Support Provides basic functionality without a lot of plug-ins Extended functionality through plug-ins with a wide range of plug-ins
CI/CD integration Focuses on the CD part of the process and is often integrated with other tools such as Argo Workflows. Supports both CI and CD, high level of integration

Deploying a Service with Argo CD

Next we will show how to deploy a simple service using Argo CD. Let's say we want to deploy an Nginx service in a Kubernetes cluster.

1. Installing the Argo CD

First, we need to install the Argo CD in the Kubernetes cluster:

kubectl create namespace argocd
kubectl apply -n argocd -f https:///argoproj/argo-cd/stable/manifests/

Once the installation is complete, you can obtain the external access address for the Argo CD API Server by using the following command:

kubectl get svc -n argocd

2. Visit to the Argo CD

You can access the Argo CD web interface via port-forward:

kubectl port-forward svc/argocd-server -n argocd 8080:443

Then visit in your browserhttps://localhost:8080. The default username isadminYou can get the initial password with the following command:

kubectl get secret argocd-initial-admin-secret -n argocd -o jsonpath="{.}" | base64 -d

3. Create Git repositories and push configuration

Create a new repository on GitHub or another Git service and save the following as a file, push it to your Git repository.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
  labels:
    app: nginx
spec:
  replicas: 3
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.14.2
        ports:
        - containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
  name: nginx-service
spec:
  selector:
    app: nginx
  ports:
  - protocol: TCP
    port: 80
    targetPort: 80

4. Defining the Argo CD application using YAML files

Create a new YAML file, and add the following to it:

apiVersion: /v1alpha1
kind: Application
metadata:
  name: nginx-app
  namespace: argocd
spec:
  project: default
  source:
    repoURL: '<YOUR_GIT_REPOSITORY_URL>'
    targetRevision: HEAD
    path: '<YOUR_APP_PATH>'
  destination:
    server: https://
    namespace: default
  syncPolicy:
    automated:
      prune: true
      selfHeal: true

commander-in-chief (military)<your-username> cap (a poem)<your-repo> Replace it with your GitHub username and repository name.

5. Application of YAML files

Apply the definition file for the Argo CD application to the Kubernetes cluster with the following command:

kubectl apply -f 

6. Validation of deployment

Going back to the Argo CD's web interface, you should see a file namednginx-app of the application. If the status is "Synced", the deployment has been successful.

You can also verify that the Nginx service is running properly in Kubernetes with the following command:

kubectl get pods -l app=nginx
kubectl get svc nginx-service

summarize

Argo CD is a powerful Kubernetes Continuous Delivery tool that simplifies and automates application management in Kubernetes clusters. Through GitOps workflows, Argo CD makes application deployment and configuration more transparent and traceable. Argo CD is more focused on Kubernetes environments than traditional CI/CD tools such as Jenkins, and is especially suited for continuous delivery of microservices and containerized applications.