Setting Up Argo CD on Kubernetes

Setting Up Argo CD on Kubernetes

在 Kubernetes 上部署 Argo CD

Argo CD is a Kubernetes-native, declarative GitOps tool for deploying applications at scale. It pulls application manifests directly from a Git repository and syncs them to a Kubernetes cluster, supports YAML, Kustomize, Jsonnet, and Helm, and ships with a built-in web UI for monitoring sync status and application health. Argo CD 是一款 Kubernetes 原生的声明式 GitOps 工具,用于大规模部署应用程序。它直接从 Git 仓库拉取应用清单并将其同步到 Kubernetes 集群,支持 YAML、Kustomize、Jsonnet 和 Helm,并内置了用于监控同步状态和应用健康状况的 Web UI。

This guide installs Argo CD on a Kubernetes cluster, sets up access to its web UI and CLI, and deploys applications through both a YAML manifest and the Argo CD dashboard. By the end, you’ll have Argo CD running behind TLS with two applications deployed and synced through it. 本指南将介绍如何在 Kubernetes 集群上安装 Argo CD,设置对其 Web UI 和 CLI 的访问权限,并通过 YAML 清单和 Argo CD 仪表板部署应用程序。完成后,你将拥有一个运行在 TLS 保护下的 Argo CD,并成功部署和同步两个应用程序。

Before you begin, you’ll need access to a Kubernetes cluster with at least three nodes, a Linux-based local or remote instance to test the Argo CD CLI, the kubectl CLI installed and configured on your local machine, the Helm client installed locally, and a domain name for your Argo CD installation (for example, argo.example.com). 在开始之前,你需要准备:一个至少包含三个节点的 Kubernetes 集群、一个用于测试 Argo CD CLI 的 Linux 本地或远程实例、已安装并配置好的 kubectl CLI、本地安装的 Helm 客户端,以及一个用于 Argo CD 安装的域名(例如 argo.example.com)。

1. Install Argo CD

1. 安装 Argo CD

  1. Create a namespace for Argo CD: $ kubectl create namespace argocd

  2. 为 Argo CD 创建命名空间: $ kubectl create namespace argocd

  3. Create a new directory for Argo CD in your home directory: $ mkdir ~/argocd

  4. 在主目录下为 Argo CD 创建一个新目录: $ mkdir ~/argocd

  5. Switch to the argocd directory: $ cd ~/argocd

  6. 切换到 argocd 目录: $ cd ~/argocd

  7. Clone the Argo CD Helm repository: $ git clone https://github.com/argoproj/argo-helm.git

  8. 克隆 Argo CD Helm 仓库: $ git clone https://github.com/argoproj/argo-helm.git

  9. Navigate to the argo-cd chart directory: $ cd argo-helm/charts/argo-cd/

  10. 进入 argo-cd chart 目录: $ cd argo-helm/charts/argo-cd/

  11. Update Helm dependencies: $ helm dependency up

  12. 更新 Helm 依赖: $ helm dependency up

  13. Install Argo CD into the argocd namespace using Helm: $ helm install argocd . -f values.yaml -n argocd

  14. 使用 Helm 将 Argo CD 安装到 argocd 命名空间: $ helm install argocd . -f values.yaml -n argocd

On success, you’ll see metadata about the installation: 安装成功后,你将看到安装相关的元数据:

  1. Verify that Argo CD is deployed to the argocd namespace: $ kubectl get pods -n argocd The output should display pods with names starting with argocd-.

  2. 验证 Argo CD 是否已部署到 argocd 命名空间: $ kubectl get pods -n argocd 输出应显示名称以 argocd- 开头的 Pod。

  3. Check the running services and ports: $ kubectl get services -n argocd The argocd-server service serves the Argo CD UI.

  4. 检查正在运行的服务和端口: $ kubectl get services -n argocd argocd-server 服务用于提供 Argo CD UI。

2. Access the Argo CD UI

2. 访问 Argo CD UI

The Argo CD UI isn’t reachable from outside the cluster by default. Use port forwarding to expose it locally without exposing the service externally. 默认情况下,无法从集群外部访问 Argo CD UI。请使用端口转发(Port Forwarding)在本地暴露它,而无需将服务暴露到外部。

  1. Extract the default admin password from the argocd-initial-admin-secret secret: $ kubectl get secrets -n argocd argocd-initial-admin-secret -o yaml Copy the encrypted password for decoding.

  2. argocd-initial-admin-secret 密钥中提取默认管理员密码: $ kubectl get secrets -n argocd argocd-initial-admin-secret -o yaml 复制加密后的密码以进行解码。

  3. Decode the password: $ echo <ENCRYPTED_PASSWORD> | base64 --decode

  4. 解码密码: $ echo <ENCRYPTED_PASSWORD> | base64 --decode

  5. Forward port 443 of the argocd-server service to port 8080 on your localhost: $ kubectl port-forward svc/argocd-server -n argocd 8080:443 This occupies your current terminal session.

  6. argocd-server 服务的 443 端口转发到本地主机的 8080 端口: $ kubectl port-forward svc/argocd-server -n argocd 8080:443 这会占用当前的终端会话。

  7. Open the Argo CD UI in a browser: http://127.0.0.1:8080

  8. 在浏览器中打开 Argo CD UI:http://127.0.0.1:8080

  9. Sign in with username admin and the decoded password. You can only access the dashboard while the port forward is active — press Ctrl + C in the terminal to end it.

  10. 使用用户名 admin 和解码后的密码登录。只有在端口转发处于活动状态时才能访问仪表板 —— 在终端中按 Ctrl + C 即可结束。

Optional: Access Argo CD Using the CLI Tool

可选:使用 CLI 工具访问 Argo CD

Keep the port forward from the previous step active in one terminal, then open a new terminal for the following steps. 保持上一步的端口转发在终端中运行,然后打开一个新的终端进行以下步骤。

  1. Download the Argo CD CLI tool: $ wget https://github.com/argoproj/argo-cd/releases/download/v2.7.4/argocd-linux-amd64

  2. 下载 Argo CD CLI 工具: $ wget https://github.com/argoproj/argo-cd/releases/download/v2.7.4/argocd-linux-amd64

  3. Move the binary to /usr/local/bin/: $ sudo mv argocd-linux-amd64 /usr/local/bin/argocd

  4. 将二进制文件移动到 /usr/local/bin/$ sudo mv argocd-linux-amd64 /usr/local/bin/argocd

  5. Grant execute permissions: $ sudo chmod +x /usr/local/bin/argocd

  6. 授予执行权限: $ sudo chmod +x /usr/local/bin/argocd

  7. Log in to the Argo CD server: $ argocd login localhost:8080

  8. 登录到 Argo CD 服务器: $ argocd login localhost:8080

  9. Change the default admin password: $ argocd account update-password

  10. 修改默认管理员密码: $ argocd account update-password

3. Deploy Argo CD Applications

3. 部署 Argo CD 应用程序

You can deploy Argo CD applications via a YAML manifest, the web UI, or the CLI. 你可以通过 YAML 清单、Web UI 或 CLI 部署 Argo CD 应用程序。

Creating and Deploying an Application Using a YAML Manifest

使用 YAML 清单创建并部署应用程序

  1. Create a YAML file for the application: $ nano argocd-app.yaml

  2. 为应用程序创建一个 YAML 文件: $ nano argocd-app.yaml

  3. Apply the configuration: $ kubectl apply -f argocd-app.yaml

  4. 应用配置: $ kubectl apply -f argocd-app.yaml

  5. Check the deployment status: $ kubectl get app -n argocd

  6. 检查部署状态: $ kubectl get app -n argocd

  7. Get detailed information about the application: $ argocd app get argo-application

  8. 获取应用程序的详细信息: $ argocd app get argo-application