Argo

Argo CD is a declarative, GitOps continuous delivery tool for Kubernetes.

Target

Integrate ArgoCD with GitLab and automatically deploy repository data to different Kubernetes clusters.

ArgoCD

Task

ArgoCD info

System structure

argo_system

Helm repo

> You need gitlab repo token to let ArgoCD pull your repo.  
> [Create a project access token](https://docs.gitlab.com/ee/user/project/settings/project_access_tokens.html#create-a-project-access-token)
  • helm-nginx folder
    .
    ├── CHANGELOG.md
    ├── Chart.lock
    ├── Chart.yaml
    ├── README.md
    ├── templates
    │   ├── deployment.yaml
    │   ├── extra-list.yaml
    │   ├── health-ingress.yaml
    │   ├── _helpers.tpl
    │   ├── hpa.yaml
    │   ├── ingress-tls-secret.yaml
    │   ├── ingress.yaml
    │   ├── networkpolicy.yaml
    │   ├── NOTES.txt
    │   ├── pdb.yaml
    │   ├── prometheusrules.yaml
    │   ├── server-block-configmap.yaml
    │   ├── serviceaccount.yaml
    │   ├── servicemonitor.yaml
    │   ├── svc.yaml
    │   └── tls-secret.yaml
    ├── values.schema.json
    └── values.yaml
    
    1 directory, 22 files
    

My task

  • Use Argo to deploy an NGINX service at 10.1.5.100 in the argotest namespace.
  • Change the container tag in a pod and check whether Argo is syncing or not.
  • Add k8s cluster (10.1.5.201) to current cluster.
  • Use Argo to deploy an NGINX service in another Kubernetes cluster at 10.1.5.201

ps: Nginx k8s yaml files are at gitlab repo.

Steps

Deploy an NGINX Service In-Cluster

  1. Prepare Helm NGINX Repo
    • Add it on GitLab project.
  2. Prepare GitLab Token
    • Create it on Gitlab project.
  3. Create a New App in ArgoCD
    • Use the specified repo, path, and target revision.
      • In ArgoCD:
      • REPO URL: https://oauth2:<your_token>.git
      • PATH: helm-nginx
      • TARGET REVISION: argo-nginx (branch in GitLab)
  4. Check Deployed Resources
    • Verify that the NGINX service has been deployed correctly.

Check Auto Sync

  1. Change NGINX Pod Image Tag

    • Downgrade or upgrade the image tag in the Helm chart.
  2. Check Resources

    • Verify that the changes are automatically synced and applied to the NGINX pod.

Add a New Kubernetes Cluster

  1. Update Kubeconfig

    • Add a new cluster in $HOME/.kube/config:
      clusters:
      ...
      - cluster:
          certificate-authority-data: 
          ...
          server: https://10.1.5.201:6443
        name: my-new-k8s
      
      ps: You can find certificate-authority-data and server info at 10.1.5.201 at path $HOME/.kube/config.
  2. Add a New User

    • Include the user configuration:
      users:
      ...
      - name: kubernetes-admin_my_new_k8s
        user:
          client-certificate-data: 
          ...
          client-key-data: 
          ...
      
      ps: You can find client-certificate-data and client-key-data info at 10.1.5.201 at path $HOME/.kube/config.
  3. Add a New Context

    • Add the context for the new cluster:
      contexts: 
      ...
      - context:
          cluster: my-new-k8s
          user: kubernetes-admin_my_new_k8s
        name: kubernetes-admin@cluster.my-new-k8s
      
  4. Verify the Contexts

    • Run the following command to list contexts:
      kubectl config get-contexts
      
  5. Create Directory in the ArgoCD Pod

    • Execute these commands:
      kubectl exec -it argocd-server-6b477b574d-bf4lz -n argocd bash
      mkdir -p /home/argocd/.kube
      exit
      
  6. Copy the Kubeconfig File

    • Execute the following commands:
      kubectl config view --raw > /tmp/config
      kubectl cp /tmp/config argocd-server-6b477b574d-bf4lz:/home/argocd/.kube/config -n argocd
      kubectl exec -it argocd-server-6b477b574d-bf4lz -n argocd -- cat /home/argocd/.kube/config
      
  7. Add the Cluster to ArgoCD

    • Use the following command:
      argocd cluster add kubernetes-admin@cluster.my-new-k8s
      

Deploy a NGINX Service in Another Kubernetes Cluster

  • Follow the same steps as “Deploy an NGINX Service In-Cluster”, but replace in-cluster with kubernetes-admin@cluster.my-new-k8s.

References

comments