UnitedDeployment

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

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

UnitedDeployment用户手册

创建UnitedDeployment

  • 利用deployment template创建一个UnitedDeployment
  1. $ cat <<EOF | kubectl apply -f -
  2. apiVersion: apps.openyurt.io/v1alpha1
  3. kind: UnitedDeployment
  4. metadata:
  5. labels:
  6. controller-tools.k8s.io: "1.0"
  7. name: ud-test
  8. spec:
  9. selector:
  10. matchLabels:
  11. app: ud-test
  12. workloadTemplate:
  13. deploymentTemplate:
  14. metadata:
  15. labels:
  16. app: ud-test
  17. spec:
  18. template:
  19. metadata:
  20. labels:
  21. app: ud-test
  22. spec:
  23. containers:
  24. - name: nginx
  25. image: nginx:1.19.3
  26. topology:
  27. pools:
  28. - name: beijing
  29. nodeSelectorTerm:
  30. matchExpressions:
  31. - key: apps.openyurt.io/nodepool
  32. operator: In
  33. values:
  34. - beijing
  35. replicas: 1
  36. - name: hangzhou
  37. nodeSelectorTerm:
  38. matchExpressions:
  39. - key: apps.openyurt.io/nodepool
  40. operator: In
  41. values:
  42. - hangzhou
  43. replicas: 2
  44. tolerations:
  45. - effect: NoSchedule
  46. key: apps.openyurt.io/example
  47. operator: Exists
  48. revisionHistoryLimit: 5
  49. EOF
  • 查看UnitedDeployment
  1. $ kubectl get ud
  2. NAME READY WORKLOADTEMPLATE AGE
  3. ud-test 3 Deployment 120m

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

  1. $ kubectl get deploy
  2. NAME READY UP-TO-DATE AVAILABLE AGE
  3. ud-test-beijing-fp58z 1/1 1 1 122m
  4. ud-test-hangzhou-xv454 2/2 2 2 122m
  5. $ kubectl get pod -l app=ud-test
  6. NAME READY STATUS RESTARTS AGE
  7. ud-test-beijing-fp58z-787d5b6b54-g4jk6 1/1 Running 0 100m
  8. ud-test-hangzhou-xv454-5cd9c4f6b5-b5tsr 1/1 Running 0 124m
  9. ud-test-hangzhou-xv454-5cd9c4f6b5-gmbgp 1/1 Running 0 124m

为UnitedDeployment添加patch功能

  • 在文件uniteddeployment_deployment_test.yaml中添加patch字段,如下所示,文件36到41行
  1. $ kubectl get ud ud-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能够使得由UnitedDeployment创建的位于北京节点池的deployment和pod中nginx镜像版本为1.19.0,而其他地区的nginx镜像版本为1.19.3。
  1. $ kubectl get deploy ud-test-beijing-fp58z -o yaml
  2. containers:
  3. - image: nginx:1.19.0
  4. $ kubectl get deploy ud-test-hangzhou-xv454 -o yaml
  5. containers:
  6. - image: nginx:1.19.3
  • 删除后,所有由UnitedDeployment创建的pod又恢复使用相同的镜像nginx1.19.3
  1. $ kubectl get pod ud-test-beijing-fp58z-787d5b6b54-g4jk6 -o yaml
  2. containers:
  3. - image: nginx:1.19.3
  4. $ kubectl get pod ud-test-hangzhou-xv454-5cd9c4f6b5-b5tsr -o yaml
  5. containers:
  6. - image: nginx:1.19.3
  • 结论:Patch功能解决了nodepool单属性的升级和应用完整发布。