应用部署仓库的目录结构
一个完整的CI/CD流水线中,涉及业务代码仓库和应用部署代码仓库两类。ACK One GitOps本实践的仓库说明如下。
业务代码仓库包含2个,分别从echo-server项目和echo-web-server项目Fork得到。
应用部署代码仓库用于存放您需要部署到集群中的应用的YAML。本实践覆盖完整研发流程的开发(Dev)、预发(Staging)、生产(Production)环境的示例,包含Helm和Kustomize两种方式,实际使用中任选一种。更多信息,请参见阿里云GitOps Demo。本实践目录结构如下所示。
manifests
├── helm
│ ├── echo-server
│ │ ├── .argocd-source-app-helm-dev.yaml
│ │ ├── .argocd-source-app-helm-production.yaml
│ │ ├── .argocd-source-app-helm-staging.yaml
│ │ ├── Chart.yaml
│ │ ├── templates
│ │ │ ├── NOTES.txt
│ │ │ ├── _helpers.tpl
│ │ │ ├── deployment-echo-server.yaml
│ │ │ ├── deployment-echo-web-server.yaml
│ │ │ ├── external-secret.yaml
│ │ │ ├── hpa.yaml
│ │ │ ├── ingress.yaml
│ │ │ ├── rollout.yaml
│ │ │ ├── service-echo-server.yaml
│ │ │ ├── service-echo-web-server.yaml
│ │ │ ├── serviceaccount.yaml
│ │ │ └── tests
│ │ │ └── test-connection.yaml
│ │ ├── values-dev.yaml
│ │ ├── values-production.yaml
│ │ ├── values-staging.yaml
│ │ └── values.yaml
│ └── web-demo
│ ├── Chart.yaml
│ ├── templates
│ │ ├── deployment.yaml
│ │ └── service.yaml
│ └── values.yaml
└── kustomize
├── base
│ ├── deployment.yaml
│ ├── kustomization.yaml
│ └── service.yaml
└── overlay
├── dev
│ ├── .argocd-source-app-kust-dev.yaml
│ ├── deployment.yaml
│ └── kustomization.yaml
├── production
│ ├── .argocd-source-app-kust-production.yaml
│ ├── deployment.yaml
│ └── kustomization.yaml
└── staging
├── .argocd-source-app-kust-staging.yaml
├── deployment.yaml
└── kustomization.yaml
该应用部署仓库的目录结构中使用Helm管理的echo-server项目,包含多环境或多集群、多个Deployment、多集群Secret管理、Rollout等能力。
多环境或多集群部署
基于不同的环境,需要配置不同的信息。关于Helm管理的应用和Kustomize管理的应用的配置说明如下。
目录结构中的.argocd-source-app-helm-xxx.yaml
和.argocd-source-app-kust-xxx.yaml
文件,为应用镜像更新后,Image Updater自动将最新的镜像信息更新到Git仓库的文件,具体内容如下图所示。关于Application配置的更多信息,请参见基于ACK One GitOps和ACR构建CI/CD流水线。
敏感信息多集群差异化分发
如果您需要在多集群中实现差异化配置、并且使用数据库的用户名和密码等敏感信息,基于上述的多集群差异化部署后,您可以使用凭据管家进行加密管理,然后在各个集群中使用ack-secret-manager或csi-secrets-store-provider-alibabacloud导入阿里云KMS服务凭据。关于凭据管家的使用方式,请参见凭据管理快速入门。
使用此能力需要在应用部署仓库中添加相应的YAML(即external-secret.yaml
),在部署应用时,用于创建ExternalSecret触发从KMS中获取服务凭据,并且在deployment-echo-server.yaml
中挂载相应Secret。
本实践中在各环境对应的values.yaml
中需配置不同的信息,例如,Dev环境下,可以不开启secretManager能力。请您在实际使用中根据实际情况进行修改。
灰度发布
在预发(Staging)、生产(Production)环境中,一般需要通过Rollout能力实现滚动发布,所以需要在应用部署仓库中添加相应的YAML,用于部署Rollout资源来触发灰度、滚动升级,即目录结构中的rollout.yaml
。关于灰度发布的更多信息,请参见基于ACK One Gitops使用Argo Rollouts实现金丝雀发布和使用Kruise Rollout实现灰度发布(金丝雀&A/B Testing)。
部署仓库对应的Application
Helm
对应以上目录结构,Helm目录下的应用对应各环境下的Application如下。
Dev环境
展开查看对应的Dev环境下的Application
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: app-helm-dev
annotations:
argocd-image-updater.argoproj.io/image-list: echoserver=demo-test-registry.cn-hangzhou.cr.aliyuncs.com/cidemo/echo-server,webserver=demo-test-registry.cn-hangzhou.cr.aliyuncs.com/cidemo/echo-web-server
argocd-image-updater.argoproj.io/echoserver.helm.image-name: image.echoServer.repository
argocd-image-updater.argoproj.io/echoserver.helm.image-tag: image.echoServer.tag
argocd-image-updater.argoproj.io/echoserver.update-strategy: latest
argocd-image-updater.argoproj.io/webserver.helm.image-name: image.echoWebServer.repository
argocd-image-updater.argoproj.io/webserver.helm.image-tag: image.echoWebServer.tag
argocd-image-updater.argoproj.io/webserver.update-strategy: latest
argocd-image-updater.argoproj.io/write-back-method: git
spec:
destination:
namespace: app-helm-dev
# https://XX.XX.XX.XX:6443
server: ${url}
source:
path: manifests/helm/echo-server
repoURL: 'git@github.com:ivan-cai/gitops-demo.git'
targetRevision: stable-example
helm:
valueFiles:
- values-dev.yaml
sources: []
project: default
syncPolicy:
automated: {}
syncOptions:
- CreateNamespace=true
Staging环境
展开查看对应的Staging环境下的Application
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: app-helm-staging
annotations:
argocd-image-updater.argoproj.io/image-list: echoserver=demo-test-registry.cn-hangzhou.cr.aliyuncs.com/cidemo/echo-server,webserver=demo-test-registry.cn-hangzhou.cr.aliyuncs.com/cidemo/echo-web-server
argocd-image-updater.argoproj.io/echoserver.helm.image-name: image.echoServer.repository
argocd-image-updater.argoproj.io/echoserver.helm.image-tag: image.echoServer.tag
argocd-image-updater.argoproj.io/echoserver.update-strategy: latest
argocd-image-updater.argoproj.io/webserver.helm.image-name: image.echoWebServer.repository
argocd-image-updater.argoproj.io/webserver.helm.image-tag: image.echoWebServer.tag
argocd-image-updater.argoproj.io/webserver.update-strategy: latest
argocd-image-updater.argoproj.io/write-back-method: git
spec:
destination:
namespace: app-staging
# https://XX.XX.XX.XX:6443
server: ${url}
source:
path: manifests/helm/echo-server
repoURL: 'git@github.com:ivan-cai/gitops-demo.git'
targetRevision: stable-example
helm:
valueFiles:
- values-staging.yaml
sources: []
project: default
syncPolicy:
syncOptions:
- CreateNamespace=true
Production环境
展开查看对应的Production环境下的Application
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: app-helm-production
annotations:
argocd-image-updater.argoproj.io/image-list: echoserver=demo-test-registry.cn-hangzhou.cr.aliyuncs.com/cidemo/echo-server,webserver=demo-test-registry.cn-hangzhou.cr.aliyuncs.com/cidemo/echo-web-server
argocd-image-updater.argoproj.io/echoserver.helm.image-name: image.echoServer.repository
argocd-image-updater.argoproj.io/echoserver.helm.image-tag: image.echoServer.tag
argocd-image-updater.argoproj.io/echoserver.update-strategy: latest
argocd-image-updater.argoproj.io/webserver.helm.image-name: image.echoWebServer.repository
argocd-image-updater.argoproj.io/webserver.helm.image-tag: image.echoWebServer.tag
argocd-image-updater.argoproj.io/webserver.update-strategy: latest
argocd-image-updater.argoproj.io/write-back-method: git
spec:
destination:
namespace: app-production
# https://XX.XX.XX.XX:6443
server: ${url}
source:
path: manifests/helm/echo-server
repoURL: 'git@github.com:ivan-cai/gitops-demo.git'
targetRevision: stable-example
helm:
valueFiles:
- values-production.yaml
project: default
syncPolicy:
syncOptions:
- CreateNamespace=true
Kustomize
对应以上目录结构,Kustomize目录下的应用对应各环境下的Application如下。
Dev环境
展开查看对应的Dev环境下的Application
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
annotations:
argocd-image-updater.argoproj.io/image-list: echoserver=demo-test-registry.cn-hangzhou.cr.aliyuncs.com/cidemo/echo-server:v1.0
argocd-image-updater.argoproj.io/echoserver.kustomize.image-name: demo-test-registry.cn-hangzhou.cr.aliyuncs.com/cidemo/echo-server
argocd-image-updater.argoproj.io/echoserver.update-strategy: latest
argocd-image-updater.argoproj.io/write-back-method: git
name: app-kust-dev
spec:
destination:
namespace: app-kust-dev
# https://XX.XX.XX.XX:6443
server: ${url}
source:
path: manifests/kustomize/overlay/dev
repoURL: 'git@github.com:ivan-cai/gitops-demo.git'
targetRevision: stable-example
kustomize:
images: []
project: default
syncPolicy:
automated: {}
syncOptions:
- CreateNamespace=true
Staging环境
展开查看对应的Staging环境下的Application
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
annotations:
argocd-image-updater.argoproj.io/image-list: echoserver=demo-test-registry.cn-hangzhou.cr.aliyuncs.com/cidemo/echo-server:v1.0
argocd-image-updater.argoproj.io/echoserver.kustomize.image-name: demo-test-registry.cn-hangzhou.cr.aliyuncs.com/cidemo/echo-server
argocd-image-updater.argoproj.io/echoserver.update-strategy: latest
argocd-image-updater.argoproj.io/write-back-method: git
name: app-kust-staging
spec:
destination:
namespace: app-staging-kust
# https://XX.XX.XX.XX:6443
server: ${url}
source:
path: manifests/kustomize/overlay/staging
repoURL: 'git@github.com:ivan-cai/gitops-demo.git'
targetRevision: stable-example
kustomize:
images: []
sources: []
project: default
syncPolicy:
syncOptions:
- CreateNamespace=true
Production环境
展开查看对应的Production环境下的Application
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
annotations:
argocd-image-updater.argoproj.io/image-list: echoserver=demo-test-registry.cn-hangzhou.cr.aliyuncs.com/cidemo/echo-server:v1.0
argocd-image-updater.argoproj.io/echoserver.kustomize.image-name: demo-test-registry.cn-hangzhou.cr.aliyuncs.com/cidemo/echo-server
argocd-image-updater.argoproj.io/echoserver.update-strategy: latest
argocd-image-updater.argoproj.io/write-back-method: git
name: app-kust-production
spec:
destination:
namespace: app-production-kust
# https://XX.XX.XX.XX:6443
server: ${url}
source:
path: manifests/kustomize/overlay/production
repoURL: 'git@github.com:ivan-cai/gitops-demo.git'
targetRevision: stable-example
kustomize:
images: []
project: default
syncPolicy:
syncOptions:
- CreateNamespace=true