跳至正文

argocd集中管理仓库规划

ArgoCD GitOps 5 仓库架构说明

1. infra-gitops(总指挥部)

作用:存放 ArgoCD 的 Application(任务单)资源文件。 核心逻辑:不存业务代码,也不存基础组件代码,只存“指令”。例如:“去拉取 mix-project 仓库的 v1 版本到 test 集群”。 权限:Owner / 运维人员。整个系统的“发令枪”。

2. mix-infra-common(非产组件库)

作用:存放测试、开发、预发布环境的基础组件代码(Istio、Cilium、Metallb 等)。 内容:通用 Helm Charts 或纯 YAML。 目录结构:按集群划分,如 mix-cn-gz/istio/。

3. prod-infra-common(生产组件库)

作用:存放生产环境基础组件代码。 核心逻辑:与非产库物理隔离,防止测试配置误改影响生产。 权限:仅核心运维可修改。

4. mix-project(非产业务库)

作用:存放所有非生产环境业务部署 YAML(Deployment、Service、Ingress)。 核心逻辑:业务开发主要活动仓库,存放带 SHA256 镜像地址的业务配置。 关联:被 infra-gitops 中的任务单引用。

5. prod-project(生产业务库)

作用:存放生产环境业务部署 YAML。 核心逻辑:与非产库隔离。 安全性:配合 ArgoCD project-prod,改动必须人工手动 Sync 才能生效。

ArgoCD GitOps 5 仓库代码推送步骤

我们将分两个步骤:先推送 业务代码库 (mix),再推送 管理指令库 (infra-gitops)。

第一步:提交业务代码到 mix 仓库

请在你的本地 mix 仓库目录下执行:

1. 进入仓库并创建 4 层结构的目录

cd /data/git/mix  # 换成你本地 mix 仓库的实际路径
mkdir -p mix-cn-gz/test/

2. 写入业务 YAML (包含你测通的 SHA256 镜像)

cat <<EOF > mix-cn-gz/test/deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: test-podman-app
  namespace: test
spec:
  replicas: 1
  selector:
    matchLabels:
      app: test-podman
  template:
    metadata:
      labels:
        app: test-podman
    spec:
      imagePullSecrets:
        - name: harbor-pull-secret
      containers:
        - name: web
          image: harbor.infraserviceonline.com/library/test-podman-image@sha256:e7d7336179399781d7cf5dd2d3df5e84b31b07114032ccb114fdca763c9d8154
          ports:
            - containerPort: 80
          command: ["/bin/sh", "-c", "while true; do echo hello; sleep 3600; done"]
---
apiVersion: v1
kind: Service
metadata:
  name: test-podman-svc
  namespace: test
spec:
  selector:
    app: test-podman
  ports:
    - protocol: TCP
      port: 80
      targetPort: 80
EOF

3. 提交并推送 (使用 gitops-token)

git add .
git commit -m "feat: add mix-cn-gz test-env manifests"
git push origin master
请谨慎使用此类代码。

第二步:提交管理指令到 infra-gitops 仓库

1. 进入仓库并创建集群管理目录

请在你的本地 infra-gitops 仓库目录下执行:

cd /data/git/infra-gitops  # 换成你本地 infra-gitops 仓库的路径
mkdir -p mix-cn-gz/

2. 写入指挥指令 (Application 任务单)

cat <<EOF > mix-cn-gz/business-apps.yaml
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
  name: mix-gz-test-app
  namespace: argocd
spec:
  project: project-mix-cn-gz
  source:
    repoURL: https://infraserviceonline.com
    targetRevision: HEAD
    path: mix-cn-gz/test
  destination:
    server: https://default.svc
    namespace: test
  syncPolicy:
    automated:
      prune: true
      selfHeal: false
    syncOptions:
      - CreateNamespace=true
      - Replace=true
      - PruneLast=true
EOF

3. 提交并推送

git add .
git commit -m "ops: add business app task for mix-cn-gz cluster"
git push origin master

💡 接下来的最后一步:在 ArgoCD 开启“种子” 文件推上去后,需要去 ArgoCD UI 做最后一次手动操作:

  1. CONNECT REPO:确保你已经用 Group Token 注册了上述两个仓库。
  2. NEW APP:
    ◦ Name: root-mix-gz
    ◦ Project: project-mix-cn-gz
    ◦ Repository URL: https://infraserviceonline.com
    ◦ Path: mix-cn-gz/
    ◦ Dest Namespace: argocd
    ◦ Directory Recurse: 勾选 (必须勾选,它才能发现目录下的 business-apps.yaml)。
    点击 CREATE 种子应用,ArgoCD 就会自动解析 business-apps.yaml,并立刻在 UI 上变出一个名为 mix-gz-test-app 的子应用,开始在 test 空间部署 Pod!

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注