本文共 1200+ 字,阅读约需 6 分钟。 当你的集群、镜像仓库、CI 都已经完成之后 下一步不是“继续部署”,而是: 👉 让部署自动发生
在前面的实验中,已经完成:
但现在的部署流程还是:
Jenkins 构建 → 手动 kubectl apply
👉 本质问题:
我们要实现:
Git → ArgoCD → Kubernetes
👉 最终效果:
只需要改 Git,系统自动部署
部分人做到这里会卡住👇

The CustomResourceDefinition "applicationsets.argoproj.io" is invalid:
metadata.annotations: Too long: may not be more than 262144 bytes
问题不是 YAML 错,而是:
👉 Kubernetes 限制 annotation 最大 256KB
之前使用的是:
kubectl apply
它会自动做一件事:
写入 last-applied-configuration
但:
👉 ArgoCD 的 CRD 非常大(尤其 applicationsets)
最终导致:
超过 256KB → API 拒绝
kubectl create -f https://ghfast.top/https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml -n argocd
命令 | 行为 |
|---|---|
apply | 写 annotation ❌ |
create | 不写 annotation ✅ |
💡 经验总结
遇到 CRD 超大组件(ArgoCD / Istio),优先避免使用
kubectl apply
kubectl get pod -n argocd

👉 判断标准:
RunningCrashLoopBackOffkubectl edit svc argocd-server -n argocd
修改:
type: NodePort
kubectl get svc -n argocd

访问:
https://<NodeIP>:<NodePort>

kubectl get secret argocd-initial-admin-secret -n argocd \
-o jsonpath="{.data.password}" | base64 -d
账号:
admin

为了符合“私有云实验”主线:
👉 我们继续使用自建 Git 服务:Gitea
docker run -d \
--name gitea \
-p 3000:3000 -p 222:22 \
-v /data/gitea:/data \
swr.cn-north-4.myhuaweicloud.com/ddn-k8s/docker.io/gitea/gitea:1.25.4
访问并进行初始配置:
http://你的IP:3000

gitops-demo/
└── nginx/
├── deployment.yaml
└── service.yaml之前有一个报错:
app path does not exist
👉 本质原因:
ArgoCD 中填写的 Path 和仓库实际路径不一致

ArgoCD 对接私钥

ssh://git@IP:2222/xxx/gitops-demo.git

进入 ArgoCD UI:

关键字段:
Name: nginx-demo
Repo: Git 地址
Path: nginx
Cluster: 默认
Namespace: default
Sync: Automatic

kubectl get pod
kubectl get svc

replicas: 2 → 3
git commit -am "scale to 3"
git push

kubectl get pod

❗ 整个过程,没有执行任何 kubectl apply
人 → kubectl → 集群
Git → ArgoCD → 集群
👉 核心变化:
维度 | 改变 |
|---|---|
操作入口 | 人 → Git |
状态来源 | 集群 → Git |
部署方式 | 手动 → 自动 |
现在已经具备:
代码提交
↓
Jenkins 构建镜像
↓
推送 Harbor
↓
修改 Git(版本号)
↓
ArgoCD 自动部署argocd app sync nginx-demo
argocd app get nginx-demo
重点检查:
当“部署”不再通过人执行,而是通过 Git 驱动时,你的系统才真正具备工程化能力。