Version: v1.0

Attach Traits

All traits in the KubeVela system works well with the simple template based Component.

In this sample, we will attach two traits, scaler and virtualgroup to a component

  1. apiVersion: core.oam.dev/v1beta1
  2. kind: Application
  3. metadata:
  4. name: myapp
  5. namespace: default
  6. spec:
  7. components:
  8. - name: mycomp
  9. type: kube-worker
  10. properties:
  11. image: nginx:1.14.0
  12. traits:
  13. - type: scaler
  14. properties:
  15. replicas: 2
  16. - type: virtualgroup
  17. properties:
  18. group: "my-group1"
  19. type: "cluster"

Verify

Deploy the application and verify traits work.

Check the scaler trait.

  1. $ kubectl get manualscalertrait
  2. NAME AGE
  3. demo-podinfo-scaler-3x1sfcd34 2m
  1. $ kubectl get deployment mycomp -o json | jq .spec.replicas
  2. 2

Check the virtualgroup trait.

  1. $ kubectl get deployment mycomp -o json | jq .spec.template.metadata.labels
  2. {
  3. "app.cluster.virtual.group": "my-group1",
  4. "app.kubernetes.io/name": "myapp"
  5. }

Update an Application

After the application is deployed and workloads/traits are created successfully, you can update the application, and corresponding changes will be applied to the workload.

Let’s make several changes on the configuration of the sample application.

  1. apiVersion: core.oam.dev/v1beta1
  2. kind: Application
  3. metadata:
  4. name: myapp
  5. namespace: default
  6. spec:
  7. components:
  8. - name: mycomp
  9. type: kube-worker
  10. properties:
  11. image: nginx:1.14.1 # 1.14.0 => 1.14.1
  12. traits:
  13. - type: scaler
  14. properties:
  15. replicas: 4 # 2 => 4
  16. - type: virtualgroup
  17. properties:
  18. group: "my-group2" # my-group1 => my-group2
  19. type: "cluster"

Apply the new configuration and check the results after several seconds.

After updating, the workload instance name will be updated from mycomp-v1 to mycomp-v2.

Check the new property value.

  1. $ kubectl get deployment mycomp -o json | jq '.spec.template.spec.containers[0].image'
  2. "nginx:1.14.1"

Check the scaler trait.

  1. $ kubectl get deployment mycomp -o json | jq .spec.replicas
  2. 4

Check the virtualgroup trait.

  1. $ kubectl get deployment mycomp -o json | jq .spec.template.metadata.labels
  2. {
  3. "app.cluster.virtual.group": "my-group2",
  4. "app.kubernetes.io/name": "myapp"
  5. }