github.com/wmuizelaar/kpt@v0.0.0-20221018115725-bd564717b2ed/site/reference/annotations/depends-on/README.md (about)

     1  ---
     2  title: "`depends-on`"
     3  linkTitle: "depends-on"
     4  type: docs
     5  description: >
     6    Specify one or more resource dependencies.
     7  ---
     8  
     9  The `config.kubernetes.io/depends-on` annotation specifies one or more resource
    10  dependencies.
    11  
    12  ### Schema
    13  
    14  The annotation value accepts a list of resource references, delimited by commas.
    15  
    16  #### Resource reference
    17  
    18  A resource reference is a string that uniquely identifies a resource.
    19  
    20  It consists of the group, kind, name, and optionally the namespace, delimited by
    21  forward slashes.
    22  
    23  | Resource Scope | Format |
    24  | -------------- | ------ |
    25  | namespace-scoped | `<group>/namespaces/<namespace>/<kind>/<name>` |
    26  | cluster-scoped   | `<group>/<kind>/<name>` |
    27  
    28  For resources in the "core" group, the empty string is used instead
    29  (for example: `/namespaces/test/Pod/pod-a`).
    30  
    31  ### Example
    32  
    33  In this example, pod-b depends on pod-a.
    34  
    35  Create a new kpt package:
    36  
    37  ```shell
    38  mkdir my-pkg
    39  cd my-pkg
    40  kpt pkg init
    41  ```
    42  
    43  Configure two pods, with one that depends on the other:
    44  
    45  ```shell
    46  cat > pods.yaml << EOF
    47  kind: Pod
    48  apiVersion: v1
    49  metadata:
    50    name: pod-a
    51    namespace: test
    52  spec:
    53    containers:
    54    - name: nginx
    55      image: nginx:1.21
    56      ports:
    57      - containerPort: 80
    58  ---
    59  kind: Pod
    60  apiVersion: v1
    61  metadata:
    62    name: pod-b
    63    namespace: test
    64    annotations:
    65      config.kubernetes.io/depends-on: /namespaces/test/Pod/pod-a
    66  spec:
    67    containers:
    68    - name: nginx
    69      image: nginx:1.21
    70      ports:
    71      - containerPort: 80
    72  EOF
    73  ```
    74  
    75  Create a namespace for your package:
    76  
    77  ```shell
    78  kubectl create namespace test
    79  ```
    80  
    81  Initialize the package inventory:
    82  
    83  ```shell
    84  kpt live init
    85  ```
    86  
    87  Apply the package to your Kubernetes cluster:
    88  
    89  ```shell
    90  kpt live apply
    91  ```
    92  
    93  If all goes well, the output should look like this:
    94  
    95  ```
    96  pod/pod-a created
    97  1 resource(s) applied. 1 created, 0 unchanged, 0 configured, 0 failed
    98  pod/pod-b created
    99  1 resource(s) applied. 1 created, 0 unchanged, 0 configured, 0 failed
   100  ```
   101  
   102  Delete the package from your Kubernetes cluster:
   103  
   104  ```shell
   105  kpt live destroy
   106  ```
   107  
   108  If all goes well, the output should look like this:
   109  
   110  ```
   111  pod/pod-b deleted
   112  1 resource(s) deleted, 0 skipped
   113  pod/pod-a deleted
   114  1 resource(s) deleted, 0 skipped
   115  ```