YurtAppSet

上一篇文章 中我们介绍了节点池的使用,主要是节点池的创建和管理,进一步,我们开发了基于节点池的应用单元化部署能力,提高用户的运维效率。

在这篇文章中,我们将展示yurt-app-manager如何帮助用户管理工作负载。假设我们已经拥有一个基于原生kubernetes搭建起来的OpenYurt集群,且至少有两个节点。

YurtAppSet用户手册

创建YurtAppSet

  • 通过yurtappset_test.yaml创建一个YurtAppSet
  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
  • 查看YurtAppSet
  1. $ kubectl get yas
  2. NAME READY WORKLOADTEMPLATE AGE
  3. yas-test 3 Deployment 43s

检查由yurt-app-manager组件创建的deployment

  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

为YurtAppSet添加patch功能

  • 在文件yurtappset_test.yaml中添加patch字段,如下所示,文件36到41行
  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. ***
  • patch能够使得由YurtAppSet创建的位于北京节点池的deployment和pod中nginx镜像版本为1.19.0,而其他地区的nginx镜像版本为1.19.3。
  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
  • 删除后,所有由YurtAppSet创建的pod又恢复使用相同的镜像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
  • 结论:Patch功能解决了nodepool单属性的升级和应用完整发布。