执行对象(应用或删减)后,该对象可能需要一段时间才能由其控制器进行协调。例如,应用部署后,底层 Pod 可能无法立即准备就绪。底层 Pod 准备就绪后,便可以对该部署进行协调。对于不同类型的对象,Config Sync 会检查不同类型的条件,以验证对象是否经过协调。如需了解详情,请参阅 sigs.k8s.io/cli-utils。
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["很难理解","hardToUnderstand","thumb-down"],["信息或示例代码不正确","incorrectInformationOrSampleCode","thumb-down"],["没有我需要的信息/示例","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-09-04。"],[],[],null,["# Declare dependencies between resource objects\n\nThis guide teaches you how dependencies work in Config Sync\nand how to specify your own dependencies.\n\nConfig Sync automatically detects implicit dependencies\nbetween specific objects when syncing them to the cluster.\nFor example, the Namespace objects are always applied before any\nobjects in those Namespaces, and a CustomResourceDefinition (CRD) object is always applied before\nany custom resource of this type is applied. Likewise, deletion ordering is\nreverse for these implicit dependencies: Namespaces are deleted after objects\nin that namespace, and CRDs are deleted after Custom Resources of that type.\n\nYou can also set explicit dependencies by using the `depends-on` annotation.\nFor example, you might want your MySQL StatefulSet to start up before your\nWordpress Deployment, so that your database is applied and ready before\nWordpress starts.\n\nRequirements\n------------\n\n- RootSync and RepoSync APIs need to be enabled.\n If you installed Config Sync manually using kubectl, and don't have\n RootSync and RepoSync APIs enabled, you need to\n [migrate your ConfigManagement object](/kubernetes-engine/enterprise/config-sync/docs/how-to/migrate-multi-repo).\n\n- **Limitation:** Dependencies must be in the same as\n their dependent. Dependencies must be managed by the same RootSync or RepoSync\n object as their dependents, which ensures all resources are in the same\n ResourceGroup.\n\nApply group\n-----------\n\nWhen syncing resources to the cluster, Config Sync divides resources that have direct or indirect dependencies into different apply groups. One apply group only consists of resources without direct or indirect dependencies on each others. The apply group in which resources do not have any dependencies will be applied first.\n\nActuation and reconciliation\n----------------------------\n\nWhen an object is actuated (either applied or pruned), it\ncan take a while for the object\nto be reconciled by its controller. For example, when a Deployment is applied,\nthe underlying Pods might not be ready immediately. After the underlying Pods\nare ready, the Deployment is reconciled. For different types of objects,\nConfig Sync checks different types of conditions to verify\nif an object is reconciled. More details can be found in\n[sigs.k8s.io/cli-utils](https://github.com/kubernetes-sigs/cli-utils/tree/master/pkg/kstatus)\n\nWith the `depends-on` annotation, Config Sync not only applies objects in the\norder that you want, it also verifies\nthat the dependency object is reconciled before applying the dependent object.\n\nIf the dependecy object does not reconcile within the default reconcile timeout of 5 minutes, Config Sync will not apply the dependent object until next sync period. You can override the default reconcile timeout by setting [`spec.override.reconcileTimeout`](/kubernetes-engine/enterprise/config-sync/docs/reference/rootsync-reposync-fields#reconcile-timeout).\n\nAdd the `depends-on` annotation to an object\n--------------------------------------------\n\nTo specify a dependency, add the `config.kubernetes.io/depends-on` annotation\non the dependent object with a value that references the\ndependency objects.\n\nFor the Wordpress example, the annotation in Wordpress Deployment\nresembles the following: \n\n # deployment.yaml\n apiVersion: apps/v1\n kind: Deployment\n metadata:\n name: wordpress\n namespace: default\n labels:\n app: wordpress\n annotations:\n config.kubernetes.io/depends-on: apps/namespaces/default/StatefulSet/wordpress-mysql\n\nWhen Config Sync applies the objects, it first applies the dependency, the\nobject `wordpress-mysql` StatefulSet. When the dependency has been reconciled,\nConfig Sync applies the dependent, the\n`wordpress` Deployment.\n\nObject references\n-----------------\n\nObject references use the following syntax:\n\n- For namespaced objects:\n\n \u003cvar translate=\"no\"\u003eGROUP\u003c/var\u003e/namespaces/\u003cvar translate=\"no\"\u003eNAMESPACE\u003c/var\u003e/\u003cvar translate=\"no\"\u003eKIND\u003c/var\u003e/\u003cvar translate=\"no\"\u003eNAME\u003c/var\u003e\n\n- For cluster-scoped objects:\n\n \u003cvar translate=\"no\"\u003eGROUP\u003c/var\u003e/\u003cvar translate=\"no\"\u003eKIND\u003c/var\u003e/\u003cvar translate=\"no\"\u003eNAME\u003c/var\u003e\n\n Replace the following:\n - \u003cvar translate=\"no\"\u003eGROUP\u003c/var\u003e: The group of the dependency object.\n - \u003cvar translate=\"no\"\u003eNAMESPACE\u003c/var\u003e: The namespace of the namespace-scoped dependency object.\n - \u003cvar translate=\"no\"\u003eKIND\u003c/var\u003e: The kind of the dependency object. This field is case sensitive. For example, use \"Pod\" instead of \"pod\".\n - \u003cvar translate=\"no\"\u003eNAME\u003c/var\u003e: The name of the dependency object.\n\nFor objects in the core group,\nthe empty string is used instead, for example `/namespaces/test/Pod/pod-a`.\n\nUse `,` to separate multiple object references, for example\n`/namespaces/test/Pod/pod-a,/namespaces/test/Pod/pod-b`."]]