depends-on アノテーションを使用して明示的な依存関係を設定することもできます。たとえば、WordPress のデプロイの前に MySQL StatefulSet を起動し、WordPress の開始前にデータベースを適用して準備できます。
要件
RootSync API と RepoSync API を有効にする必要があります。kubectl を使用して Config Sync を手動でインストールしていて、RootSync API と RepoSync API が有効になっていない場合は、ConfigManagement オブジェクトを移行する必要があります。
オブジェクトが作動(適用またはプルーニング)してから、コントローラによってオブジェクトが調整されるまで時間がかかることがあります。たとえば、Deployment が適用されている場合、基盤となる Pod がすぐには準備されない場合があります。基盤となる Pod の準備ができると、Deployment が調整されます。オブジェクトのタイプごとに、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"]],["最終更新日 2025-09-04 UTC。"],[],[],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`."]]