YurtAppSet

In the previous article we introduced the use of NodePool, mainly the creation and management of NodePool. Further, we developed the ability to deploy applications unitized based on NodePool to improve the efficiency of users’ operations.

In this article, we will show how yurt-app-manager can help users manage their workload. Assume we already have an OpenYurt cluster built on native kubernetes with at least two nodes.

1) Create YurtAppSet

  • Create YurtAppSet by yurtappset_test.yaml
  1. apiVersion: apps.openyurt.io/v1alpha1
  2. kind: YurtAppSet
  3. metadata:
  4. labels:
  5. controller-tools.k8s.io: "1.0"
  6. name: yas-test
  7. spec:
  8. selector:
  9. matchLabels:
  10. app: yas-test
  11. workloadTemplate:
  12. deploymentTemplate:
  13. metadata:
  14. labels:
  15. app: yas-test
  16. spec:
  17. template:
  18. metadata:
  19. labels:
  20. app: yas-test
  21. spec:
  22. containers:
  23. - name: nginx
  24. image: nginx:1.19.3
  25. topology:
  26. pools:
  27. - name: beijing
  28. nodeSelectorTerm:
  29. matchExpressions:
  30. - key: apps.openyurt.io/nodepool
  31. operator: In
  32. values:
  33. - beijing
  34. replicas: 1
  35. - name: hangzhou
  36. nodeSelectorTerm:
  37. matchExpressions:
  38. - key: apps.openyurt.io/nodepool
  39. operator: In
  40. values:
  41. - hangzhou
  42. replicas: 2
  43. tolerations:
  44. - effect: NoSchedule
  45. key: apps.openyurt.io/example
  46. operator: Exists
  47. revisionHistoryLimit: 5
  • Check YurtAppSet
  1. $ kubectl get yas
  2. NAME READY WORKLOADTEMPLATE AGE
  3. yas-test 3 Deployment 43s

2) Check the deployments created by yurt-app-manager

  1. $ kubectl get deploy
  2. NAME READY UP-TO-DATE AVAILABLE AGE
  3. yas-test-beijing-k5st4 1/1 1 1 54s
  4. yas-test-hangzhou-2jkj5 2/2 2 2 54s
  5. $ kubectl get pod -l app=yas-test
  6. NAME READY STATUS RESTARTS AGE
  7. yas-test-beijing-k5st4-56bc98cc7d-h7h86 1/1 Running 0 72s
  8. yas-test-hangzhou-2jkj5-64588c484b-8mvn8 1/1 Running 0 72s
  9. yas-test-hangzhou-2jkj5-64588c484b-vx85t 1/1 Running 0 72s

3) Add patch to YurtAppSet

  • Add the patch field to the file yurtappset_test.yaml as follows, lines 36 to 41 of the file
  1. $ kubectl get yas yas-test -o yaml
  2. topology:
  3. pools:
  4. - name: beijing
  5. nodeSelectorTerm:
  6. matchExpressions:
  7. - key: apps.openyurt.io/nodepool
  8. operator: In
  9. values:
  10. - beijing
  11. replicas: 1
  12. patch:
  13. spec:
  14. template:
  15. spec:
  16. containers:
  17. - name: nginx
  18. image: nginx:1.19.0
  19. - name: hangzhou
  20. nodeSelectorTerm:
  21. matchExpressions:
  22. - key: apps.openyurt.io/nodepool
  23. operator: In
  24. values:
  25. - hangzhou
  26. replicas: 2
  27. tolerations:
  28. ***
  • This updates the nginx image version to 1.19.0 in the deployments and pods in Beijing NodePool, while keeping the nginx image version at 1.19.3 for the other regions
  1. $ kubectl get deploy yas-test-beijing-k5st4 -o yaml
  2. containers:
  3. - image: nginx:1.19.0
  4. $ kubectl get deploy yas-test-hangzhou-2jkj5 -o yaml
  5. containers:
  6. - image: nginx:1.19.3
  • After removing the patch, all pods created by YurtAppSet revert back to nginx1.19.3
  1. $ kubectl get pod yas-test-beijing-k5st4-974b6958c-t2kfn -o yaml
  2. containers:
  3. - image: nginx:1.19.3
  4. $ kubectl get pod yas-test-hangzhou-2jkj5-64588c484b-8mvn8 -o yaml
  5. containers:
  6. - image: nginx:1.19.3
  • Conclusion: Patch solves the upgrade of the NodePool’s single attribute and application release.