github.com/wmuizelaar/kpt@v0.0.0-20221018115725-bd564717b2ed/site/book/06-deploying-packages/03-handling-dependencies.md (about) 1 Sometimes resources within a package have dependencies that require 2 one resource to be applied and reconciled before another resource. 3 For example, a package that includes both Wordpress and MySQL might 4 require that the MySQL `StatefulSet` is running before the Wordpress 5 `Deployment` is started. 6 7 In kpt, this is supported by declaring dependencies with the 8 `config.kubernetes.io/depends-on` annotation. 9 10 Let's take a look at the `wordpress-with-dependencies` package, a modified 11 version of the `wordpress` package used earlier: 12 13 ```shell 14 $ kpt pkg get https://github.com/GoogleContainerTools/kpt.git/package-examples/wordpress-with-dependencies@v0.1 15 ``` 16 17 You can see that the resources belonging to wordpress have 18 the `depends-on` annotation referencing the MySQL `StatefulSet`: 19 20 ```yaml 21 # wordpress-with-dependencies/deployment/deployment.yaml (Excerpt) 22 apiVersion: apps/v1 23 kind: Deployment 24 metadata: 25 name: wordpress 26 namespace: default 27 labels: 28 app: wordpress 29 annotations: 30 config.kubernetes.io/depends-on: apps/namespaces/default/StatefulSet/wordpress-mysql 31 ``` 32 33 The syntax for the resource references are: 34 * For namespaced resources: `<group>/namespaces/<namespace>/<kind>/<name>` 35 * For cluster-scoped resources: `<group>/<kind>/<name>` 36 37 Before you can deploy the package, you need to initialize it and create a `Secret` 38 containing the mysql password: 39 40 ```shell 41 $ kpt live init wordpress-with-dependencies 42 initializing Kptfile inventory info (namespace: default)...success 43 44 $ kubectl create secret generic mysql-pass --from-literal=password=YOUR_PASSWORD 45 ``` 46 47 You can deploy the package just like other packages. You can see that the MySQL `StatefulSet` 48 and `Service` are created and reconciled before the Wordpress `Deployment` and `Service` are applied. 49 50 ```shell 51 $ kpt live apply wordpress-with-dependencies --reconcile-timeout=2m 52 service/wordpress-mysql created 53 statefulset.apps/wordpress-mysql created 54 service/wordpress-mysql reconcile pending 55 statefulset.apps/wordpress-mysql reconcile pending 56 service/wordpress-mysql reconciled 57 statefulset.apps/wordpress-mysql reconciled 58 service/wordpress created 59 deployment.apps/wordpress created 60 4 resource(s) applied. 4 created, 0 unchanged, 0 configured, 0 failed 61 service/wordpress reconcile pending 62 deployment.apps/wordpress reconcile pending 63 service/wordpress reconciled 64 deployment.apps/wordpress reconciled 65 4 resource(s) reconciled, 0 skipped, 0 failed to reconcile, 0 timed out 66 ``` 67 68 When you delete the package from the cluster, you can see that 69 resources are deleted in reverse order: 70 ```shell 71 $ kpt live destroy wordpress-with-dependencies 72 deployment.apps/wordpress deleted 73 service/wordpress deleted 74 deployment.apps/wordpress reconciled 75 service/wordpress reconciled 76 statefulset.apps/wordpress-mysql deleted 77 service/wordpress-mysql deleted 78 4 resource(s) deleted, 0 skipped, 0 failed to delete 79 statefulset.apps/wordpress-mysql reconcile pending 80 service/wordpress-mysql reconcile pending 81 statefulset.apps/wordpress-mysql reconciled 82 service/wordpress-mysql reconciled 83 4 resource(s) reconciled, 0 skipped, 0 failed to reconcile, 0 timed out 84 ``` 85 86 See [depends-on] for more information. 87 88 [depends-on]: 89 /reference/annotations/depends-on/