专业的编程技术博客社区

网站首页 > 博客文章 正文

Argo CD实践-如何在ArgoCD中创建应用程序App

baijin 2024-11-09 11:08:45 博客文章 8 ℃ 0 评论

创建App

Application是由清单定义的一组 Kubernetes 资源

A group of Kubernetes resources as defined by a manifest. This is a Custom Resource Definition (CRD).

手顺

前提:有一个可用的Kubernetes集群。

实验环境:

  • kubernetes:1.23.*
  • argo cd:latest

访问Argo server的方式有两种:

  • 通过web ui
  • 使用argocd 客户端工具

1.登录argo cd

本次使用argocd 客户端工具

  • 通过 port forward转发到本地 linux 端口访问 argocd apiserver
kubectl port-forward svc/argocd-server -n argocd 8080:443
  • 登录
$argocd login localhost:8080

2.添加私有git

argocd repo add https://github.com/argoproj/argocd-example-apps.git --username <username> --password <password>

3.从 Git 存储库创建app

  1. 需要将当前命名空间设置为argocd
kubectl config set-context --current --namespace=argocd
  1. 通过CLI创建App
argocd app create guestbook --repo https://github.com/argoproj/argocd-example-apps.git --path guestbook --dest-server https://kubernetes.default.svc --dest-namespace default

参数说明:

--repo: 指定 Git 仓库
 --path:指定部署文件在 Git 仓库中的相对路径
 --dest-server: 集群的访问地址
 --dest-namespace:部署到哪个命名空间

仓库为空时,会出现以下错误,必须先提交代码,才能创建app

FATA[0005] rpc error: code = InvalidArgument desc = application spec for test-daoservice is invalid: InvalidSpecError: Unable to generate manifests in build-config/test/eks: rpc error: code = Unknown desc = build-config/test/eks: app path does not exist

  1. test

4.同步Application

  • 创建app后,可通过get命令获取app状态
  • 此时应用程序状态处于最初状态,因为应用程序尚未处于状态 部署,并且尚未创建 K8s资源
$ argocd app get guestbook
Name:               guestbook
Server:             https://kubernetes.default.svc
Namespace:          default
URL:                https://10.97.164.88/applications/guestbook
Repo:               https://github.com/argoproj/argocd-example-apps.git
Target:
Path:               guestbook
Sync Policy:        <none>
Sync Status:        OutOfSync from  (1ff8a67)
Health Status:      Missing

GROUP  KIND        NAMESPACE  NAME          STATUS     HEALTH
apps   Deployment  default    guestbook-ui  OutOfSync  Missing
       Service     default    guestbook-ui  OutOfSync  Missing
  1. 手动同步
argocd app sync guestbook
  1. 通过设置策略自动同步

默认每3分钟自动同步

https://argo-cd.readthedocs.io/en/stable/user-guide/auto_sync/

argocd app set guestbook --sync-policy automated

同步后,就会部署到k8s

  1. 通过用户界面同步


注意

删除path中资源文件后,argocd默认情况不删除相应的资源

--path guestbook

可通过以下命令设置自动删除

argocd app set guestbook --auto-prune

下一次同步时,删除K8s资源

Tags:

本文暂时没有评论,来添加一个吧(●'◡'●)

欢迎 发表评论:

最近发表
标签列表