How to Install ArgoCD on Kubernetes

Introduction

ArgoCD is a powerful continuous delivery tool for Kubernetes, enabling developers to automate the deployment of their applications. This guide will walk you through the steps to install ArgoCD on Kubernetes, covering basic installation to advanced configurations. By the end of this tutorial, you’ll have a fully functional ArgoCD instance running on your Kubernetes cluster.

What is ArgoCD?

ArgoCD is a declarative, GitOps continuous delivery tool for Kubernetes. It automates the deployment of the desired application state as defined in a Git repository. ArgoCD continuously monitors running applications and compares the current, live state against the desired target state. When the live state deviates from the target state, ArgoCD can automatically or manually synchronize it.

Prerequisites

Before we begin, ensure you have the following prerequisites:

  • A running Kubernetes cluster (v1.18+)
  • kubectl installed and configured to interact with your cluster
  • Helm installed on your local machine

Step 1: Install ArgoCD

1.1 Create a Namespace for ArgoCD

First, create a namespace for ArgoCD to keep its resources isolated:

kubectl create namespace argocd

1.2 Install ArgoCD Using Kubectl

You can install ArgoCD by applying the official ArgoCD manifests:

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

1.3 Verify the Installation

Check if all ArgoCD pods are running:

kubectl get pods -n argocd

You should see something like this:

NAME                                      READY   STATUS    RESTARTS   AGE
argocd-application-controller-0 1/1 Running 0 2m
argocd-dex-server-847f8bc98c-dkj5d 1/1 Running 0 2m
argocd-redis-64c69757cf-jdksl 1/1 Running 0 2m
argocd-repo-server-6b6d9d8d85-rfkl9 1/1 Running 0 2m
argocd-server-5b6d9d8d85-vn9ms 1/1 Running 0 2m

Step 2: Access the ArgoCD UI

2.1 Expose the ArgoCD API Server

To access the ArgoCD UI, you’ll need to expose the ArgoCD API server using a service type that suits your needs. For simplicity, we’ll use a LoadBalancer service:

kubectl patch svc argocd-server -n argocd -p '{"spec": {"type": "LoadBalancer"}}'

2.2 Get the Initial Admin Password

Retrieve the initial admin password, which is auto-generated and stored in a Kubernetes secret:

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

2.3 Open the ArgoCD UI

Find the external IP address of the ArgoCD API server:

kubectl get svc -n argocd

Look for the argocd-server service and note the EXTERNAL-IP. Open your browser and navigate to https://<EXTERNAL-IP>. Log in with the username admin and the password you retrieved in the previous step.

Step 3: Configure ArgoCD

3.1 Connect ArgoCD to a Git Repository

ArgoCD uses Git repositories as the source of truth for application definitions. To connect ArgoCD to your Git repository, follow these steps:

  1. Navigate to the ArgoCD UI.
  2. Click on Settings > Repositories > Connect Repo.
  3. Enter the repository URL and, if necessary, provide authentication details.

3.2 Create an Application in ArgoCD

To create an application:

  1. Click on New App.
  2. Fill in the application details:
    • Application Name: Name of your application.
    • Project: Default.
    • Sync Policy: Automatic or Manual.
    • Repository URL: URL of your Git repository.
    • Revision: Branch to track (e.g., main).
    • Path: Path within the repository where the Kubernetes manifests are located.
    • Cluster: The Kubernetes cluster where the application will be deployed.
    • Namespace: Namespace in the cluster where the application will be deployed.
  3. Click Create.

Advanced Configurations

4.1 Set Up RBAC

ArgoCD supports Role-Based Access Control (RBAC) to restrict access to certain features and resources. To configure RBAC:

  1. Create a ConfigMap named argocd-rbac-cm in the argocd namespace.
  2. Define roles and policies in the ConfigMap:
apiVersion: v1
kind: ConfigMap
metadata:
name: argocd-rbac-cm
namespace: argocd
data:
policy.csv: |
g, admin, role:admin
g, developer, role:developer
policy.default: role:readonly
scopes: '[groups]'

4.2 Customize the UI

You can customize the ArgoCD UI by modifying the argocd-cm ConfigMap:

apiVersion: v1
kind: ConfigMap
metadata:
name: argocd-cm
namespace: argocd
data:
ui.banner: "Welcome to ArgoCD!"
ui.theme: "dark"

Apply the changes:

kubectl apply -f argocd-cm.yaml

4.3 Enable SSO

ArgoCD supports Single Sign-On (SSO) with various identity providers like OAuth2, OIDC, SAML, and LDAP. To enable SSO:

  1. Create a secret with your identity provider’s credentials.
  2. Update the argocd-cm ConfigMap with the SSO configuration.

For example, to configure OIDC:

apiVersion: v1
kind: ConfigMap
metadata:
name: argocd-cm
namespace: argocd
data:
oidc.config: |
name: Okta
issuer: https://<your-okta-domain>/oauth2/default
clientID: <your-client-id>
clientSecret: $oidc.clientSecret

Create the secret with the client’s secret:

kubectl create secret generic argocd-secret -n argocd --from-literal=oidc.clientSecret=<your-client-secret>

Troubleshooting

5.1 Common Issues and Solutions

  • Issue: Unable to access the ArgoCD UI.
    • Solution: Ensure the argocd-server service is of type LoadBalancer and has an external IP address.
  • Issue: Application sync failures.
    • Solution: Check the application logs and ensure that the repository path and branch are correct.
  • Issue: Authentication failures.
    • Solution: Verify the credentials and configuration for the Git repository and identity provider.

FAQs

What is ArgoCD?

ArgoCD is a declarative, GitOps continuous delivery tool for Kubernetes that automates the deployment of applications.

How do I install ArgoCD on Kubernetes?

You can install ArgoCD by applying the official manifests provided by ArgoCD, creating a namespace for it, and verifying the installation with kubectl.

How do I access the ArgoCD UI?

You can access the ArgoCD UI by exposing the argocd-server service as a LoadBalancer and navigating to the external IP address in your browser.

How do I connect ArgoCD to my Git repository?

You can connect ArgoCD to your Git repository by navigating to the ArgoCD UI, adding the repository under settings, and providing the necessary authentication details.

Conclusion

Installing ArgoCD on Kubernetes is a straightforward process that involves creating a namespace, applying the installation manifests, and configuring access to the UI. With ArgoCD, you can automate the deployment of your applications, ensuring a consistent and reliable delivery process. By following this guide, you should now have a functional ArgoCD setup and be ready to leverage its powerful features to manage your Kubernetes applications effectively. Thank you for reading the DevopsRoles page!

,

About HuuPV

My name is Huu. I love technology, especially Devops Skill such as Docker, vagrant, git, and so forth. I like open-sources, so I created DevopsRoles.com to share the knowledge I have acquired. My Job: IT system administrator. Hobbies: summoners war game, gossip.
View all posts by HuuPV →

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.