跳到主要内容

ArgoCD 示例

简介

本问介绍了如何使用提供的示例通过 ArgoCD 部署一个完整的 OceanBase 环境。该示例遵循“App of Apps”模式,即由一个父级 ArgoCD 应用程序(oceanbase-stack)管理所有其他子应用程序的部署,通过同步阶段(Sync Phases)和同步波次(Sync Waves)的组合来确保它们以正确的顺序创建。

前提条件

在开始之前,请确保您已具备以下条件:

  • 一个正在运行的 Kubernetes 集群。
  • 在您的集群上安装了 ArgoCD。您可以在 ArgoCD 官方文档 中找到安装说明。
  • 安装了 kubectl 并已配置为连接到您的集群。

安装

安装过程涉及将 manifest 应用到您的 ArgoCD 集群,将部署所有必要的组件。

第一步:配置自定义健康检查

为了让 ArgoCD 准确报告所有资源的状态,您必须将自定义健康检查脚本添加到 argocd-cm ConfigMap 中。

  1. 创建一个名为 argocd-health-patch.yaml 的文件,其内容如下:

    data:
    resource.customizations.health.argoproj.io_Application: |
    hs = {}
    hs.status = "Progressing"
    hs.message = ""
    if obj.status ~= nil then
    if obj.status.health ~= nil then
    hs.status = obj.status.health.status
    if obj.status.health.message ~= nil then
    hs.message = obj.status.health.message
    end
    end
    end
    return hs
    resource.customizations.health.oceanbase.oceanbase.com_OBCluster: |
    hs = {}
    if obj.status == nil or obj.status.status == nil then
    hs.status = "Progressing"
    hs.message = "Waiting for status"
    return hs
    end

    local current_status = obj.status.status
    if current_status == "running" then
    hs.status = "Healthy"
    hs.message = "Cluster is running"
    elseif current_status == "failed" then
    hs.status = "Degraded"
    hs.message = "Cluster has failed"
    else
    hs.status = "Progressing"
    hs.message = "Cluster is " .. current_status
    end
    return hs
    resource.customizations.health.oceanbase.oceanbase.com_OBTenant: |
    hs = {}
    if obj.status == nil or obj.status.status == nil then
    hs.status = "Progressing"
    hs.message = "Waiting for status"
    return hs
    end

    local current_status = obj.status.status
    if current_status == "running" then
    hs.status = "Healthy"
    hs.message = "Tenant is running"
    elseif current_status == "failed" then
    hs.status = "Degraded"
    hs.message = "Tenant has failed"
    else
    hs.status = "Progressing"
    hs.message = "Tenant is " .. current_status
    end
    return hs
  2. 将此配置 patch 到您的 argocd-cm ConfigMap:

    kubectl patch configmap argocd-cm -n argocd --patch-file argocd-health-patch.yaml

第二步:准备仓库

示例文件默认配置为从上游的 ob-operator 仓库进行部署。如果您是从自己 fork 的仓库进行部署,则必须首先更新应用程序清单中的 repoURL

以下文件需要更新以指向您的 Git 仓库:

  • example/argocd/oceanbase-stack.yaml
  • example/argocd/apps/secrets.yaml
  • example/argocd/apps/obcluster.yaml
  • example/argocd/apps/obtenant.yaml
  • example/argocd/apps/ob-configserver.yaml
  • example/argocd/apps/obproxy.yaml

在每个文件中,将 repoURL 更改为您的 fork 仓库的 URL。

第三步:部署应用栈

oceanbase-stack 应用程序是管理所有其他组件的父应用程序。使用以下命令将其部署到您的 ArgoCD 实例:

kubectl apply -f example/argocd/oceanbase-stack.yaml -n argocd

第四步:监控部署

创建 oceanbase-stack 应用程序后,您可以在 ArgoCD UI 中监控部署过程。部署遵循特定的顺序以确保满足依赖关系:

  • Pre-Sync 阶段: 首先部署以下应用程序以设置基础组件。ArgoCD 将等待这些应用完成并变为 Healthy 状态后才会继续。

    • ob-operator: 安装 OceanBase operator 及其 CRD。
    • secrets: 创建必要的密码密钥。
    • ob-configserver: 部署配置服务器。
  • Wave 1: Pre-Sync 阶段成功后,此波次将部署主集群组件。

    • obcluster: 部署 OceanBase 集群。
    • obproxy: 部署代理。
  • Wave 2: Wave 1 健康后,最后一个波次将部署租户。

    • obtenant: 部署租户。

验证

同步过程完成后,ArgoCD UI 中的所有应用程序都应处于 SyncedHealthy 状态。

您还可以使用 kubectl 进行验证:

  • 检查 oceanbaseoceanbase-system 命名空间中的 pod,确保所有组件都在运行。
  • 检查 OBClusterOBTenant 自定义资源的状态。

访问数据库

一旦所有应用程序都处于 SyncedHealthy 状态,oceanbase-stack 就提供了一个功能齐全且与 MySQL 兼容的 OceanBase 租户。您可以从 Kubernetes 集群中的其他应用程序连接到此数据库实例。

连接详情:

  • 主机 (Host): obproxy.oceanbase.svc.cluster.local
  • 端口 (Port): 2883
  • 用户名 (Username): root@obtenant
  • 密码 (Password): 密码是自动生成的,并存储在 Kubernetes secret 中。

要检索密码,请运行以下命令:

kubectl get secret tenant-root-password -n oceanbase -o jsonpath='{.data.password}' | base64 -d

您可以使用这些详细信息来配置任何与 MySQL 兼容的客户端或应用程序以连接到您的 OceanBase 租户。

问题排查

网络问题导致的同步失败: ArgoCD 服务器需要能够连接到 Git 仓库和 Helm 仓库。如果您看到 Unknown 的同步状态或 context deadline exceeded 之类的错误,这表明您的 ArgoCD 实例与互联网之间存在网络问题。请确保防火墙、代理和网络策略已配置为允许此流量。