github.com/oam-dev/kubevela@v1.9.11/docs/examples/app-with-policy/gc-policy/keep-legacy-resources.md (about)

     1  ## How to keep legacy resources
     2  
     3  Suppose you want to keep the resources created by the old version of the app. You only need to specify garbage-collect in the policy field of the app and enable the option `keepLegacyResource`.
     4  
     5  ```yaml
     6  #app.yaml
     7  apiVersion: core.oam.dev/v1beta1
     8  kind: Application
     9  metadata:
    10    name: first-vela-app
    11  spec:
    12    components:
    13      - name: express-server
    14        type: webservice
    15        properties:
    16          image: crccheck/hello-world
    17          port: 8000
    18        traits:
    19          - type: ingress-1-20
    20            properties:
    21              domain: testsvc.example.com
    22              http:
    23                "/": 8000
    24    policies:
    25      - name: keep-legacy-resource
    26        type: garbage-collect
    27        properties:
    28          keepLegacyResource: true
    29  ```
    30  
    31  1. create app
    32  
    33  ``` shell
    34  kubectl apply -f app.yaml
    35  ```
    36  
    37  ```shell
    38  $ kubectl get app
    39  NAME             COMPONENT        TYPE         PHASE     HEALTHY   STATUS   AGE
    40  first-vela-app   express-server   webservice   running   true               29s
    41  ```
    42  
    43  2. update the app
    44  
    45  ```yaml
    46  #app1.yaml
    47  apiVersion: core.oam.dev/v1beta1
    48  kind: Application
    49  metadata:
    50    name: first-vela-app
    51  spec:
    52    components:
    53      - name: express-server-1
    54        type: webservice
    55        properties:
    56          image: crccheck/hello-world
    57          port: 8000
    58        traits:
    59          - type: ingress-1-20
    60            properties:
    61              domain: testsvc.example.com
    62              http:
    63                "/": 8000
    64    policies:
    65      - name: keep-legacy-resource
    66        type: garbage-collect
    67        properties:
    68          keepLegacyResource: true
    69  ```
    70  
    71  ``` shell
    72  kubectl apply -f app1.yaml
    73  ```
    74  
    75  ```shell
    76  $ kubectl get app
    77  NAME             COMPONENT          TYPE         PHASE     HEALTHY   STATUS   AGE
    78  first-vela-app   express-server-1   webservice   running   true               9m35s
    79  ```
    80  
    81  check whether legacy resources are reserved.
    82  
    83  ```
    84  $ kubectl get deploy
    85  NAME               READY   UP-TO-DATE   AVAILABLE   AGE
    86  express-server     1/1     1            1           10m
    87  express-server-1   1/1     1            1           40s
    88  ```
    89  
    90  ```
    91  $ kubectl get svc
    92  NAME               TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)    AGE
    93  express-server     ClusterIP   10.96.102.249   <none>        8000/TCP   10m
    94  express-server-1   ClusterIP   10.96.146.10    <none>        8000/TCP   46s
    95  ```
    96  
    97  ```
    98  $ kubectl get ingress
    99  NAME               CLASS    HOSTS                 ADDRESS   PORTS   AGE
   100  express-server     <none>   testsvc.example.com             80      10m
   101  express-server-1   <none>   testsvc.example.com             80      50s
   102  ```
   103  
   104  ```
   105  $ kubectl get resourcetrackers.core.oam.dev
   106  NAME                        AGE
   107  first-vela-app-default      12m
   108  first-vela-app-v1-default   12m
   109  first-vela-app-v2-default   2m56s
   110  ```
   111  
   112  3. delete the app
   113  
   114  ```
   115  $ kubectl delete app first-vela-app
   116  ```