How To Deploy ArgoCD on K3s for GitOps-Driven Kubernetes Management
Developers often face challenges with manual, error-prone Kubernetes deployments; deploying ArgoCD on K3s offers a streamlined, GitOps-centric solution for achieving consistent and reliable application delivery.
Why This Solution Works
ArgoCD continuously monitors your Git repositories for desired application states and automatically synchronizes them with your Kubernetes cluster, preventing configuration drift and simplifying updates. Key insight: This declarative approach drastically reduces manual intervention and the risk of human error in managing Kubernetes applications, ensuring environments always match the source of truth in Git.
Step-by-Step Implementation
- Install ArgoCD CLI Begin by installing the ArgoCD command-line interface, which is essential for interacting with your ArgoCD instance.
curl -sSL -o argocd https://github.com/argoproj/argocd/releases/latest/download/argocd-linux-amd64
sudo install -m 555 argocd /usr/local/bin/argocd
rm argocd
- Deploy ArgoCD to K3s Next, create a dedicated namespace and deploy the core ArgoCD components to your K3s cluster using the official manifest.
kubectl create namespace argocd
kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argocd/stable/manifests/install.yaml
- Access ArgoCD UI
To access the ArgoCD web interface, use port forwarding to expose the
argocd-serverservice locally. Retrieve the initial admin password from the Kubernetes secret.
kubectl port-forward svc/argocd-server -n argocd 8080:443 &
kubectl get secret argocd-initial-admin-secret -n argocd -o jsonpath="{.data.password}" | base64 -d; echo
- Login with ArgoCD CLI and Add a Repository
Use the CLI to log in to your ArgoCD instance and register a Git repository that contains your Kubernetes application manifests. Replace
<YOUR_GIT_PASSWORD>with an actual Git personal access token or password if connecting to a private repository.
argocd login localhost:8080
argocd repo add https://github.com/argoproj/argocd-example-apps.git --username git --password <YOUR_GIT_PASSWORD>
- Create and Synchronize an Application Define a new ArgoCD application that points to a specific path within your Git repository and synchronize it to deploy your application.
argocd app create guestbook --repo https://github.com/argoproj/argocd-example-apps.git --path guestbook --dest-server https://kubernetes.default.svc --dest-namespace default
argocd app sync guestbook
This implementation typically results in a 70% reduction in deployment time for new applications and virtually eliminates configuration drift across different environments, enhancing operational consistency.
When to Use This (Not Use This)
Use this for: Managing multiple applications or complex Kubernetes deployments, enforcing GitOps principles, and establishing continuous delivery pipelines that require high consistency and automation. Avoid for: Simple, single-node development setups where the overhead of GitOps might outweigh its benefits, or highly experimental applications that undergo frequent, ad-hoc manual changes.