YurtAppDaemon

背景介绍

在边缘场景中,来自同一区域的边缘节点被分配到同一个节点池中,此时,一般需要在节点池维度部署一些系统组件,例如CoreDNS。 创建节点池时,我们希望自动创建这些系统组件,而无需任何手动操作。

YurtAppDaemon 确保所有或部分节点池以 Deployment 或 StatefulSet 作为模板运行副本。 随着节点池的创建,这些子部署或状态集也被添加到集群中,子部署或状态集的创建/更新由 YurtAppDaemon 控制器实现。 这些子 Deployments 或 Statefulsets 将在节点池 从集群中移除时被回收,删除 YurtAppDaemon CR 将清理它创建的 Deployments 或 StatefulSets。 YurtAppDaemon 的行为类似于 K8S Daemonset,不同之处在于 YurtAppDaemon 从节点池维度自动创建 K8S 工作负载。

img

用户使用:

  • 创建test1节点池
  1. cat <<EOF | kubectl apply -f -
  2. apiVersion: apps.openyurt.io/v1alpha1
  3. kind: NodePool
  4. metadata:
  5. name: test1
  6. spec:
  7. selector:
  8. matchLabels:
  9. apps.openyurt.io/nodepool: test1
  10. type: Edge
  11. EOF
  • 创建test2节点池
  1. cat <<EOF | kubectl apply -f -
  2. apiVersion: apps.openyurt.io/v1alpha1
  3. kind: NodePool
  4. metadata:
  5. name: test2
  6. spec:
  7. selector:
  8. matchLabels:
  9. apps.openyurt.io/nodepool: test2
  10. type: Edge
  11. EOF
  • 将节点加入到节点池
  1. kubectl label node cn-beijing.172.23.142.31 apps.openyurt.io/desired-nodepool=test1
  2. kubectl label node cn-beijing.172.23.142.32 apps.openyurt.io/desired-nodepool=test1
  3. kubectl label node cn-beijing.172.23.142.34 apps.openyurt.io/desired-nodepool=test2
  4. kubectl label node cn-beijing.172.23.142.35 apps.openyurt.io/desired-nodepool=test2
  • 创建YurtAppDaemon
  1. cat <<EOF | kubectl apply -f -
  2. apiVersion: apps.openyurt.io/v1alpha1
  3. kind: YurtAppDaemon
  4. metadata:
  5. name: daemon-1
  6. namespace: default
  7. spec:
  8. selector:
  9. matchLabels:
  10. app: daemon-1
  11. workloadTemplate:
  12. deploymentTemplate:
  13. metadata:
  14. labels:
  15. app: daemon-1
  16. spec:
  17. replicas: 1
  18. selector:
  19. matchLabels:
  20. app: daemon-1
  21. template:
  22. metadata:
  23. labels:
  24. app: daemon-1
  25. spec:
  26. containers:
  27. - image: nginx:1.18.0
  28. imagePullPolicy: Always
  29. name: nginx
  30. nodepoolSelector:
  31. matchLabels:
  32. yurtappdaemon.openyurt.io/type: "nginx"
  33. EOF
  • 为test1节点池打标签
  1. kubectl label np test1 yurtappdaemon.openyurt.io/type=nginx
  2. # Check the Deployment
  3. kubectl get deployments.apps
  4. # Check the Deployment nodeselector
  5. # Check the Pod
  • 为test2节点池打标签
  1. kubectl label np test2 yurtappdaemon.openyurt.io/type=nginx
  2. # Check the Deployment
  3. kubectl get deployments.apps
  4. # Check the Deployment nodeselector
  5. # Check the Pod
  • 改变YurtAppDaemon
  1. # Change yurtappdaemon workloadTemplate replicas to 2
  2. # Change yurtappdaemon workloadTemplate image to nginx:1.19.0
  3. # Check the Pod
  • 移除节点池标签
  1. # Remove the nodepool test1 label
  2. kubectl label np test1 yurtappdaemon.openyurt.io/type-
  3. # Check the Deployment
  4. # Check the Pod
  5. # Remove the nodepool test2 label
  6. kubectl label np test2 yurtappdaemon.openyurt.io/type-
  7. # Check the Deployment
  8. # Check the Pod