迁移 ConfigManagement 对象
本页面介绍如何将 ConfigManagement 对象迁移到 RootSync 对象。从 ConfigManagement 对象迁移到 RootSync 对象会启用 RootSync
和 RepoSync
API。您可以利用这些 API 启用其他功能。例如,您可以呈现 Kustomize 配置和 Helm 图表,以及替换系统值,例如更改资源限制和更新要提取的 Git 提交数量。即使您只想使用根代码库并且不想使用任何命名空间代码库,您也可以启用这些 API。
迁移 ConfigManagement 设置
使用 nomos migrate
从 1.10.0 版开始,nomos
提供了 nomos migrate
命令来启用 RootSync
和 RepoSync
API。您需要将 nomos
更新为 1.10.0 及更高版本。
如需详细了解如何运行该命令,请按照从 ConfigManagement 对象迁移到 RootSync 对象进行操作。
手动迁移
如果您的 nomos
版本低于 1.10.0,则可以手动迁移设置。您需要在 ConfigManagement 对象中将 spec.enableMultiRepo
设置为 true
,并创建一个 RootSync 对象以将根代码库同步到集群。根代码库可以是非结构化代码库,也可以是分层代码库。在迁移到使用 RootSync 对象后,您可以将代码库拆分为多个代码库,并且可以配置从多个代码库同步。
如需通过迁移配置来配置根代码库,请完成以下任务:
- 打开您的 ConfigManagement 对象。
- 复制
spec.git
字段中的值。您在创建 RootSync 对象时会用到这些值。 - 从 ConfigManagement 对象中移除所有
spec.git
字段(包括git:
)。 在 ConfigManagement 对象中,将
spec.enableMultiRepo
字段设置为true
:# config-management.yaml apiVersion: configmanagement.gke.io/v1 kind: ConfigManagement metadata: name: config-management spec: enableMultiRepo: true
应用更改:
kubectl apply -f config-management.yaml
等待 RootSync CRD 创建完成。
kubectl wait --for=condition=established crd rootsyncs.configsync.gke.io
使用从 ConfigManagement 对象复制的值创建 RootSync 对象。例如:
# root-sync.yaml apiVersion: configsync.gke.io/v1beta1 kind: RootSync metadata: name: root-sync namespace: config-management-system spec: sourceFormat: ROOT_FORMAT git: repo: ROOT_REPOSITORY revision: ROOT_REVISION branch: ROOT_BRANCH dir: "ROOT_DIRECTORY" auth: ROOT_AUTH_TYPE gcpServiceAccountEmail: ROOT_EMAIL # secretRef should be omitted if the auth type is none, gcenode, or gcpserviceaccount. secretRef: name: git-creds
请替换以下内容:
ROOT_FORMAT
:添加unstructured
以使用非结构化代码库,或添加hierarchy
以使用分层代码库。 这些值区分大小写。 此字段是可选字段,默认值为hierarchy
。我们建议您添加unstructured
,因为您可以采用这种格式以最适合您的方式整理配置。ROOT_REPOSITORY
:添加要用作根代码库的 Git 代码库的网址。您可以输入使用 HTTPS 或 SSH 协议的网址。例如,https://github.com/GoogleCloudPlatform/anthos-config-management-samples
使用 HTTPS 协议。如果您不输入协议,则网址会被视为 HTTPS 网址。此字段是必填字段。ROOT_REVISION
:添加要签出的 Git 修订版本(标记或哈希)。此字段是可选字段,默认值为HEAD
。ROOT_BRANCH
:添加要从中同步的代码库的分支。此字段是可选字段,默认值为master
。ROOT_DIRECTORY
:添加 Git 代码库中指向您要同步的配置所在的根目录的路径。此字段是可选字段,默认值为代码库的根目录 (/
)。ROOT_AUTH_TYPE
:添加以下身份验证类型之一:none
:不使用身份验证ssh
:使用 SSH 密钥对cookiefile
:使用cookiefile
token
:使用令牌gcpserviceaccount
:使用 Google 服务帐号访问 Cloud Source Repositories 中的代码库。gcenode
:使用 Google 服务帐号访问 Cloud Source Repositories 中的代码库。请仅在集群中未启用 Workload Identity 时选择此选项。如需详细了解这些身份验证类型,请参阅授予 Config Sync 对 Git 的只读权限。
此字段是必填字段。
ROOT_EMAIL
:如果您已将gcpserviceaccount
添加为ROOT_AUTH_TYPE
,请添加您的 Google 服务帐号电子邮件地址。例如acm@PROJECT_ID.iam.gserviceaccount.com
。
应用更改:
kubectl apply -f root-sync.yaml
ConfigManagement 和 RootSync 对照表
下表简要介绍了 ConfigMangent 对象中的字段如何映射到 RootSync 对象中的字段。
ConfigManagement 字段 | RootSync 字段 |
---|---|
spec.git.gcpServiceAccountEmail |
spec.git.gcpServiceAccountEmail |
spec.git.syncRepo |
spec.git.repo |
spec.git.syncBranch |
spec.git.branch |
spec.git.policyDir |
spec.git.dir |
spec.git.syncWait |
spec.git.period |
spec.git.syncRev |
spec.git.revision |
spec.git.secretType |
spec.git.auth |
git-creds (这是 ConfigManagement 对象中的固定值) |
spec.git.secretRef.name |
spec.sourceFormat |
spec.sourceFormat |
spec.git.proxy.httpProxy 或 spec.git.proxy.httpsProxy
|
spec.git.proxy |