ArgoCD for Kubernetes

S
Suraj Shinare 4th February 2022 - 6 mins read

Deploying your application using Kubernetes brings a lot of infrastructure related advantages. These include, flexibility while scaling, managing distributed components, having complete control over various versions of your application. This also brings a lot of complexity along with it. Continuous Integration and Continuous Deployment (CI/CD) systems work at a high level of abstraction so as to help reduce costs and also reduce the level of complexity which results in simplified operations.

In this blog tutorial, we will be exploring ArgoCD which is a declarative GitOps continuous delivery tool for Kubernetes.

Why ArgoCD?

Argo CD follows the GitOps pattern of using Git repositories as the source of truth for defining the desired application state.

Prerequisites

  • You should have a k8s cluster and CI pipeline for any application
  • You should have two application versions (Docker Images stored in Docker Registry)

Proposed CICD Pipeline for enterprise use cases -

  • Dev team will push the code in Source Code Repo and trigger the pipeline
  • Jenkins will clone the repository, builds and create a Docker image
  • Docker images will be pushed to Docker Registry ( AWS ECR/Gitlab)
  • After that, Jenkins will update the GitOps repository with newer docker image version
  • ArgoCD will be continuously syncing with GitOps repository and deploy the changes if it's not synced
  • Deployment status can be observed in Argo UI
  • Rolling Deployment strategy is recommended for Pod deployment
  • Note – For Prod environment, Release manager can update/push the changes in GitOps repository and deployment can be initiated

Let's quickly Jump into Argo configurations, and see how this works.

Step 1. Install Argo CD with below commands

kubectl create namespace argocd kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml

Step 2. Login Into Argo CD UI

We are using port Forwarding to access Argo CD UI without exposing the service

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

Argo CD UI will be available over :8080



The initial password for the admin account is auto-generated and stored as clear text in the field password in a secret named argocd-initial-admin-secret in your Argo CD installation namespace. You can simply retrieve this password using kubectl:

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

Now our Argo CD Ready to deployment



Step 3. Configure Agro CD with Demo Application

  • Application Manifest Files
                                - Namespace.yaml
                                    apiVersion: v1
                                    kind: Namespace
                                    metadata:
                                    name: myapp
    
                                - Deployment.yaml
                                    apiVersion: apps/v1
                                    kind: Deployment
                                    metadata:
                                    name: myapp
                                    spec:
                                    selector:
                                        matchLabels:
                                        app: myapp
                                    replicas: 4
                                    template:
                                        metadata:
                                        labels:
                                            app: myapp
                                        spec:
                                        containers:
                                        - name: myapp
                                            image: m2021/eks-cicd:1.2
                                            ports:
                                            - containerPort: 80
    
                                - Service.yaml
                                    apiVersion: v1
                                    kind: Service
                                    metadata:
                                    name: myapp-service
                                    spec:
                                    selector:
                                        app: myapp
                                    ports:
                                    - port: 80
                                        protocol: TCP
                                        targetPort: 80
                            
  • Application Manifest Files
                                apiVersion: argoproj.io/v1alpha1
                                    kind: Application
                                    metadata:
                                        name: myapp-argo-application
                                        namespace: argocd
                                    spec:
                                        project: default
    
                                    source:
                                        repoURL: https://gitlab.com/surajshinare/argocd-app-config.git
                                        targetRevision: HEAD
                                        path: dev
                                    destination:
                                        server: https://kubernetes.default.svc
                                        namespace: myapp
    
                                    syncPolicy:
                                        syncOptions:
                                        - CreateNamespace=true
    
                                    automated:
                                        selfHeal: true
                                        prune: true
                            
  • Apply application.yaml file in k8s cluster with below command and application ready for deployment kubectl apply -f application.yaml


Step 3. Configure Agro CD with Demo Application

We will update docker version and pod count in our deployment.yaml and service.yaml file



We have successfully deployed sample application via ArgoCD in Kubernetes.

Conclusion

In the above demonstration, you have seen the fundamentals of installing and deploying applications using ArgoCD. Kubernetes can be complicated as it requires layers of ideation, and hence it is important that you make sure that your deployments are as sustainable as possible.

Kubernetes can resolve all your infrastructure woes! If you would like to discuss more about GitOps and Kubernetes and how we can help you with the same, feel free to reach out our certified cloud consultants by filling in your contact details in the form below.

Top Blog Posts

×

Talk to our experts to discuss your requirements

Real boy icon sized sample pic Real girl icon sized sample pic Real boy icon sized sample pic
India Directory