使用Argocd部署应用

部署helloworld

[root@master 07-argocd-basics]# kubectl apply -f 01-application-helloworld.yaml 
application.argoproj.io/spring-boot-helloworld created
[root@master 07-argocd-basics]# cat 01-application-helloworld.yaml 
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
  name: spring-boot-helloworld
  namespace: argocd
spec:
  project: default
  source:
    repoURL: https://gitee.com/mageedu/spring-boot-helloworld-deployment.git
    targetRevision: HEAD
    path: deploy/kubernetes
  destination:
    server: https://kubernetes.default.svc
    namespace: helloworld
  syncPolicy:
    automated: 
      prune: true
      selfHeal: true
      allowEmpty: false
    syncOptions:
    - Validate=false
    - CreateNamespace=true
    - PrunePropagationPolicy=foreground
    - PruneLast=true
    retry:
      limit: 5
      backoff:
        duration: 5s
        factor: 2
        maxDuration: 3m

[root@master 07-argocd-basics]# argocd app list
NAME                           CLUSTER                         NAMESPACE   PROJECT  STATUS  HEALTH       SYNCPOLICY  CONDITIONS  REPO                                                             PATH               TARGET
argocd/guestbook               https://kubernetes.default.svc  guestbook   default  Synced  Healthy      Auto        <none>      https://gitee.com/mageedu/argocd-example-apps.git                guestbook          
argocd/spring-boot-helloworld  https://kubernetes.default.svc  helloworld  default  Synced  Progressing  Auto-Prune  <none>      https://gitee.com/mageedu/spring-boot-helloworld-deployment.git  deploy/kubernetes  HEAD

已经运行正常

分别在三个名称空间部署helloworld

[root@master 07-argocd-basics]# kubectl apply -f 02-applicationset-demo.yaml 
applicationset.argoproj.io/helloworld created
[root@master 07-argocd-basics]# cat 02-applicationset-demo.yaml 
apiVersion: argoproj.io/v1alpha1
kind: ApplicationSet
metadata:
  name: helloworld
  namespace: argocd
spec:
  generators:
  - list:
      elements:
      - environment: dev
      - environment: staging
      - environment: prod
  template:
    metadata:
      name: '{{environment}}-spring-boot-helloworld'
    spec:
      project: default
      source:
        repoURL: https://gitee.com/mageedu/spring-boot-helloworld-deployment.git
        targetRevision: HEAD
        path: helloworld/{{environment}}
      destination:
        server: https://kubernetes.default.svc
        namespace: '{{environment}}'
      syncPolicy:
        automated: 
          prune: true
          selfHeal: true
          allowEmpty: false
        syncOptions:
        - Validate=false
        - CreateNamespace=true
        - PrunePropagationPolicy=foreground
        - PruneLast=true
        retry:
          limit: 5
          backoff:
            duration: 5s
            factor: 2
            maxDuration: 3m
  syncPolicy:
    preserveResourcesOnDeletion: false

[root@master 07-argocd-basics]# argocd app list
NAME                                   CLUSTER                         NAMESPACE   PROJECT  STATUS  HEALTH       SYNCPOLICY  CONDITIONS  REPO                                                             PATH                TARGET
argocd/dev-spring-boot-helloworld      https://kubernetes.default.svc  dev         default  Synced  Progressing  Auto-Prune  <none>      https://gitee.com/mageedu/spring-boot-helloworld-deployment.git  helloworld/dev      HEAD
argocd/guestbook                       https://kubernetes.default.svc  guestbook   default  Synced  Healthy      Auto        <none>      https://gitee.com/mageedu/argocd-example-apps.git                guestbook           
argocd/prod-spring-boot-helloworld     https://kubernetes.default.svc  prod        default  Synced  Progressing  Auto-Prune  <none>      https://gitee.com/mageedu/spring-boot-helloworld-deployment.git  helloworld/prod     HEAD
argocd/spring-boot-helloworld          https://kubernetes.default.svc  helloworld  default  Synced  Healthy      Auto-Prune  <none>      https://gitee.com/mageedu/spring-boot-helloworld-deployment.git  deploy/kubernetes   HEAD
argocd/staging-spring-boot-helloworld  https://kubernetes.default.svc  staging     default  Synced  Progressing  Auto-Prune  <none>      https://gitee.com/mageedu/spring-boot-helloworld-deployment.git  helloworld/staging  HEAD

 

posted @ 2022-11-12 13:40  Maniana  阅读(206)  评论(0编辑  收藏  举报