一、APP创建
1.1webUI创建
1.2CLI创建
除了使用webUI创建应用外,也可以使用Argo CLI命令行工具创建
# 创建应用
root@k8s-01:~/argocd# argocd app create demo1 \
--repo http://192.168.30.181/develop/argo-demo.git \
--path manifests/ --sync-policy automatic --dest-namespace default \
--dest-server https://kubernetes.default.svc --directory-recurse
WARN[0000] Failed to invoke grpc call. Use flag --grpc-web in grpc calls. To avoid this warning message, use flag --grpc-web.
application 'demo1' created
root@k8s-01:~/argocd#
# 查看应用列表
root@k8s-01:~/argocd# argocd app list
WARN[0000] Failed to invoke grpc call. Use flag --grpc-web in grpc calls. To avoid this warning message, use flag --grpc-web.
NAME CLUSTER NAMESPACE PROJECT STATUS HEALTH SYNCPOLICY CONDITIONS REPO PATH TARGET
argocd/demo https://kubernetes.default.svc default OutOfSync Progressing Manual SharedResourceWarning(3) http://192.168.30.181/develop/argo-demo.git manifests HEAD
argocd/demo-test https://kubernetes.default.svc default OutOfSync Healthy Manual SharedResourceWarning(3) http://192.168.30.181/develop/argo-demo.git manifests/ HEAD
argocd/demo1 https://kubernetes.default.svc default default Synced Healthy Auto <none> http://192.168.30.181/develop/argo-demo.git manifests/
# 查看应用状态
root@k8s-01:~/argocd# kubectl get application -n argocd
NAME SYNC STATUS HEALTH STATUS
demo OutOfSync Progressing
demo-test OutOfSync Healthy
demo1 Synced Healthy
# 执行立即同步操作
root@k8s-01:~/argocd# argocd app sync argocd/demo
WARN[0000] Failed to invoke grpc call. Use flag --grpc-web in grpc calls. To avoid this warning message, use flag --grpc-web.
TIMESTAMP GROUP KIND NAMESPACE NAME STATUS HEALTH HOOK MESSAGE
2025-08-19T07:00:05+00:00 Service default myapp OutOfSync Healthy
2025-08-19T07:00:05+00:00 apps Deployment default myapp OutOfSync Healthy
2025-08-19T07:00:05+00:00 traefik.io IngressRoute default myapp OutOfSync
2025-08-19T07:00:05+00:00 Service default myapp Synced Healthy
2025-08-19T07:00:05+00:00 Service default myapp Synced Healthy service/myapp configured
2025-08-19T07:00:05+00:00 apps Deployment default myapp OutOfSync Healthy deployment.apps/myapp configured
2025-08-19T07:00:05+00:00 traefik.io IngressRoute default myapp OutOfSync ingressroute.traefik.io/myapp configured
2025-08-19T07:00:05+00:00 apps Deployment default myapp Synced Healthy deployment.apps/myapp configured
2025-08-19T07:00:05+00:00 traefik.io IngressRoute default myapp Synced ingressroute.traefik.io/myapp configured
Name: argocd/demo
Project: default
Server: https://kubernetes.default.svc
Namespace:
URL: https://argocd.local.com:30443/applications/argocd/demo
Source:
- Repo: http://192.168.30.181/develop/argo-demo.git
Target: HEAD
Path: manifests
SyncWindow: Sync Allowed
Sync Policy: Manual
Sync Status: Synced to HEAD (293d75f)
Health Status: Healthy
Operation: Sync
Sync Revision: 293d75f441403c3f19c888df50939ec3a9e6f1fa
Phase: Succeeded
Start: 2025-08-19 07:00:05 +0000 UTC
Finished: 2025-08-19 07:00:05 +0000 UTC
Duration: 0s
Message: successfully synced (all tasks run)
GROUP KIND NAMESPACE NAME STATUS HEALTH HOOK MESSAGE
Service default myapp Synced Healthy service/myapp configured
apps Deployment default myapp Synced Healthy deployment.apps/myapp configured
traefik.io IngressRoute default myapp Synced ingressroute.traefik.io/myapp configured
1.3yaml文件创建
[root@tiaoban ~]# cat demo.yaml
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: demo
namespace: argocd
spec:
destination:
namespace: default
server: 'https://kubernetes.default.svc'
source:
path: manifests # yaml资源清单路径
repoURL: 'http://gitlab.local.com/devops/argo-demo.git' # 同步仓库地址
targetRevision: 'master' # 分支名称
sources: []
project: default
syncPolicy:
automated:
prune: false
selfHeal: false
[root@tiaoban ~]# kubectl apply -f demo.yaml
application.argoproj.io/demo created
二、应用同步选项
2.1同步策略配置
SYNC POLICY:同步策略
Argo CD能够在检测到 Git 中所需的清单与集群中的实时状态之间存在差异时自动同步应用程序。自动同步是GitOps Pull模式的核心,好处是 CI/CD Pipeline 不再需要直接访问Argo CD API服务器来执行部署,可以通过在WEB UI的Application-SYNC POLICY中启用AUTOMATED或CLIargocd app set <APPNAME> --sync-policy automated 进行配置。
PRUNE RESOURCES :自动删除资源,开启选项后Git Repo中删除资源会自动在环境中删除对应的资源。
SELF HEAL:自动痊愈,强制以GitRepo状态为准,手动在环境修改不会生效。
2.2AutoSync自动同步
默认同步周期是180s, 可以修改argocd-cm配置文件,添加timeout.reconciliation参数。
同步流程:
1. 获取所有设置为auto-sync的apps
2. 从每个app的git存储库中获取最新状态
3. 将git状态与集群应用状态对比
4. 如果相同,不执行任何操作并标记为synced
5. 如果不同,标记为out-of-sync
2.3SyncOptions同步选项
- Validate=false:禁用Kubectl验证
- Replace=true:kubectl replace替换
- PrunePropagationPolicy=background:级联删除策略(background, foreground and orphan.)ApplyOutOfSyncOnly=true:仅同步不同步状态的资源。避免大量对象时资源API消耗
- CreateNamespace=true:创建namespace
- PruneLast=true:同步后进行修剪
- RespectlgnoreDifferences=true:支持忽略差异配置(ignoreDifferences:)
- ServerSideApply=true:部署操作在服务端运行(避免文件过大)
三、应用状态
sync status
- Synced:已同步
- OutOfSync:未同步
health status
- Progressing:正在执行
- Suspended:资源挂载暂停
- Healthy:资源健康
- Degraded:资源故障
- Missing:集群不存在资源
评论 (0)