Introduction
In the world of handling containers and making them work together smoothly, Kubernetes stands out as a go-to choice. It’s like a powerful and flexible system that helps manage applications packed in containers. Now, when it’s time to set up and take care of tasks in Kubernetes, a lot of developers and DevOps teams like using tools that follow Continuous Integration and Continuous Deployment, or CI/CD for short.
ArgoCD is one of these tools, and people really like it because it’s easy to use and gets the job done well when deploying stuff in Kubernetes. This blog post is all about how to use ArgoCD to put your jobs into action on Kubernetes and also check out what makes ArgoCD special compared to other tools doing the same CI/CD job.
Getting Started with ArgoCD
Pre-requisites:
- Pre-installed Kubernetes environment to install ArgoCD. Here we’ll be using Minikube. (https://minikube.sigs.k8s.io/docs/start/)
- Have an application image published on a container registry (Dockerhub)
- Have a Git repository ready with the manifest files.
Install ArgoCD on Kubernetes
Use kubectl to install ArgoCD on your Kubernetes (minikube) cluster. This will create the necessary resources.
kubectl create namespace argocd
kubectl apply -n argocd -f
https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml
This will create a new namespace, argocd, where ArgoCD services and application resources will live.
Access the ArgoCD Web UI
Once installed, you can access the ArgoCD UI using port forwarding.
kubectl port-forward svc/argocd-server -n argocd 8080:443
Open your browser and go to https://localhost:8080.
The default login credentials are admin (username) and the password can be retrieved using:
kubectl -n argocd get secret argocd-initial-admin-secret -o
jsonpath=”{.data.password}” | base64 -d
This command fetches the ArgoCD admin password from the Kubernetes Secret, decodes it from base64, and displays the actual password.
Deploy Your First Application
ArgoCD provides several ways to deploy applications, offering flexibility to accommodate different workflows and scenarios. Some common ways to deploy applications using ArgoCD include the use of the WebUI, ArgoCD CLI, Declarative GitOps Workflow and more. Here in this case, we’ll be focusing on deploying an application using the WebUI.
In other words, the Git repository becomes the source of truth for the application configuration. This is in line with the GitOps philosophy, where the desired state of the system is declared in the Git repository, and tools like ArgoCD use this repository to ensure the actual state matches the desired state.
Creating a New Application
Add all your configuration files and manifests inside a Git repository, because this Git repository holds the declarative configuration, and ArgoCD ensures the Kubernetes cluster converges to this desired state automatically, providing a robust and automated deployment pipeline.
Head to the Applications section of the ArgoCD Web UI and click on “New Application.” Fill in application details, including the Git repository, name of application (myapp-argo-application), target cluster, and path to manifests (hover-dev in this case). Finally, save the configuration by hitting “Create” from the top left.
Alternatively, you can save the following application.yaml file and run the kubectl apply command.
# Argo CD Configuration (application.yaml)
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: myapp-argo-application
namespace: argocd
spec:
project: default
source:
repoURL: https://github.com/aftab-s/ArgoCD-WebApp-Test.git
targetRevision: HEAD
path: hover-dev
destination:
server: https://kubernetes.default.svc
# Specify which namespace the config files in the repo should be
applied to
namespace: myapp
# Since by default there is no myapp namespace setup prior,
# We have to make argo cd create a namespace “myapp” automatically while
deploying the K8s cluster.
syncPolicy:
syncOptions:
– CreateNamespace=true # By default, it’ll be set to false
automated: # this attribute will pull changes from (polls) git repo
every 3 minute intervals
# If that delay has to be removed, you can configure a Git Webhook
selfHeal: true # Since by default, changes made to the live cluster
manually will not trigger automated sync
prune: true # If service.yaml is deleted in the git repo, the service
must be deleted from the whole cluster also
After saving this file, run the kubectl apply command.
kubectl apply -f application.yaml
This will create the namespace, and create the deployment inside the minikube cluster.
Syncing the Application
Go to the Applications dashboard and select your application. Based on your requirements, click “Sync” and choose “Manual Sync”, where ArgoCD will detect the changes in the Git repository but sync will have to be carried out manually (will have to go to the Web UI and hit the “Sync” button) or “Automated Sync” where ArgoCD will detect the changes in the Git repository and will carry out the Sync automatically by itself.
Now if you’d like to access the application running on the cluster, run the kubectl port-forward command for the application service you’d like to access. Here in this case, the command looks like this:
kubectl port-forward service/myapp-service -n myapp 8899:8080
You can access the application on http://localhost:8899
ArgoCD vs. Other CI/CD Tools: What Makes It Different?
Key Features of ArgoCD
While ArgoCD shares some features with other CI/CD tools like Jenkins or GitLab CI/CD, it offers distinct advantages. ArgoCD uses a declarative approach to configuration, allowing users to define the desired state of their Kubernetes applications in a YAML file. This approach enhances clarity and reproducibility, as the entire deployment process is codified.
- GitOps Workflow ArgoCD promotes a GitOps workflow, where the entire configuration and deployment process is version-controlled using Git. This ensures traceability and collaboration, as changes are proposed via pull requests and reviewed before being applied to the Kubernetes cluster.
- Kubernetes Native Unlike some general-purpose CI/CD tools that require extensive customization for Kubernetes deployments, ArgoCD is purpose-built for Kubernetes. It understands Kubernetes resources, making it easier to manage deployments, updates, and rollbacks in a Kubernetes-native manner.
- Multi-Environment Support ArgoCD supports deploying applications to multiple environments, such as development, staging, and production, with separate configuration files. This flexibility allows teams to manage and maintain consistent deployment practices across different stages of the development lifecycle.
ArgoCD’s focus on Kubernetes and GitOps makes it a compelling choice for organisations looking to streamline their Kubernetes job management process. Its intuitive interface, powerful features, and automation capabilities significantly improve efficiency and reduce the risk of errors.
With its ease of use and powerful features, ArgoCD is quickly becoming the go-to tool for managing Kubernetes jobs. By embracing its GitOps-based approach, you can achieve a more efficient, reliable, and streamlined workflow for your Kubernetes deployments.
Feature | ArgoCD | Other CI/CD Tools |
Primary focus | Kubernetes deployments and jobs | General-purpose CI/CD pipelines |
Configuration management | GitOps with declarative YAML files | Scripted configuration or UI-based configuration |
Job execution platform | Kubernetes | Can vary depending on the tool |
Integration with Kubernetes | Deep integration with Kubernetes resources | Limited or no integration |
Version control and auditability | Built-in Git integration and version history | May require external tools |
Conclusion
ArgoCD stands out as a specialized and effective CI/CD tool for Kubernetes deployments. Its emphasis on declarative configuration, GitOps workflow, and Kubernetes-native approach makes it a compelling choice for teams looking to streamline their container orchestration workflows. While other CI/CD tools are versatile and widely adopted, ArgoCD’s focus on Kubernetes-specific deployments provides a level of simplicity and efficiency that can be advantageous for teams heavily invested in Kubernetes-based architectures. As organizations continue to embrace containerization and Kubernetes, tools like ArgoCD play a crucial role in enabling seamless and reliable application deployments.