湖南省网站备案时间,移除wordpress版本,网站备案最快,网站源码客户简介#xff1a; 弹性伸缩作为Kubernetes的核心能力之一#xff0c;但它一直是围绕这无状态的应用负载展开。而Fluid提供了分布式缓存的弹性伸缩能力#xff0c;可以灵活扩充和收缩数据缓存。 它基于Runtime提供了缓存空间、现有缓存比例等性能指标, 结合自身对于Runtime资源…简介 弹性伸缩作为Kubernetes的核心能力之一但它一直是围绕这无状态的应用负载展开。而Fluid提供了分布式缓存的弹性伸缩能力可以灵活扩充和收缩数据缓存。 它基于Runtime提供了缓存空间、现有缓存比例等性能指标, 结合自身对于Runtime资源的扩缩容能力提供数据缓存按需伸缩能力。
作者| 车漾 Fluid社区Commiter
作者| 谢远东 Fluid社区Commiter 背景
随着越来越多的大数据和AI等数据密集应用开始部署和运行在Kubernetes环境下数据密集型应用计算框架的设计理念和云原生灵活的应用编排的分歧导致了数据访问和计算瓶颈。云原生数据编排引擎Fluid通过数据集的抽象利用分布式缓存技术结合调度器为应用提供了数据访问加速的能力。 弹性伸缩作为Kubernetes的核心能力之一但它一直是围绕这无状态的应用负载展开。而Fluid提供了分布式缓存的弹性伸缩能力可以灵活扩充和收缩数据缓存。 它基于Runtime提供了缓存空间、现有缓存比例等性能指标, 结合自身对于Runtime资源的扩缩容能力提供数据缓存按需伸缩能力。 这个能力对于互联网场景下大数据应用非常重要由于多数的大数据应用都是通过端到端流水线来实现的。而这个流水线包含以下几个步骤 数据提取利用SparkMapReduce等大数据技术对于原始数据进行预处理模型训练利用第一阶段生成特征数据进行机器学习模型训练并且生成相应的模型模型评估通过测试集或者验证集对于第二阶段生成模型进行评估和测试模型推理第三阶段验证后的模型最终推送到线上为业务提供推理服务可以看到端到端的流水线会包含多种不同类型的计算任务针对每一个计算任务实践中会有合适的专业系统来处理TensorFlowPyTorchSpark Presto但是这些系统彼此独立通常要借助外部文件系统来实现把数据从一个阶段传递到下一个阶段。但是频繁的使用文件系统实现数据交换会带来大量的 I/O 开销经常会成为整个工作流的瓶颈。 而Fluid对于这个场景非常适合用户可以创建一个Dataset对象这个对象有能力将数据分散缓存到Kubernetes计算节点中作为数据交换的介质这样避免了数据的远程写入和读取提升了数据使用的效率。但是这里的问题是临时数据缓存的资源预估和预留。由于在数据生产消费之前精确的数据量预估是比较难满足过高的预估会导致资源预留浪费过低的预估会导致数据写入失败可能性增高。还是按需扩缩容对于使用者更加友好。我们希望能够达成类似page cache的使用效果对于最终用户来说这一层是透明的但是它带来的缓存加速效果是实实在在的。 我们通过自定义HPA机制通过Fluid引入了缓存弹性伸缩能力。弹性伸缩的条件是当已有缓存数据量达到一定比例时就会触发弹性扩容扩容缓存空间。例如将触发条件设置为缓存空间占比超过75%此时总的缓存空间为10G当数据已经占满到8G缓存空间的时候就会触发扩容机制。 下面我们通过一个例子帮助您体验Fluid的自动扩缩容能力。 前提条件 推荐使用Kubernetes 1.18以上因为在1.18之前HPA是无法自定义扩缩容策略的都是通过硬编码实现的。而在1.18后用户可以自定义扩缩容策略的比如可以定义一次扩容后的冷却时间。 具体步骤 1.安装jq工具方便解析json在本例子中我们使用操作系统是centos可以通过yum安装jq yum install -y jq 2.下载、安装Fluid最新版 git clone https://github.com/fluid-cloudnative/fluid.git
cd fluid/charts
kubectl create ns fluid-system
helm install fluid fluid 3.部署或配置 Prometheus 这里通过Prometheus对于AlluxioRuntime的缓存引擎暴露的 Metrics 进行收集如果集群内无 prometheus: $ cd fluid
$ kubectl apply -f integration/prometheus/prometheus.yaml 如集群内有 prometheus,可将以下配置写到 prometheus 配置文件中: scrape_configs:- job_name: alluxio runtimemetrics_path: /metrics/prometheuskubernetes_sd_configs:- role: endpointsrelabel_configs:- source_labels: [__meta_kubernetes_service_label_monitor]regex: alluxio_runtime_metricsaction: keep- source_labels: [__meta_kubernetes_endpoint_port_name]regex: webaction: keep- source_labels: [__meta_kubernetes_namespace]target_label: namespacereplacement: $1action: replace- source_labels: [__meta_kubernetes_service_label_release]target_label: fluid_runtimereplacement: $1action: replace- source_labels: [__meta_kubernetes_endpoint_address_target_name]target_label: podreplacement: $1action: replace 4.验证 Prometheus 安装成功 $ kubectl get ep -n kube-system prometheus-svc
NAME ENDPOINTS AGE
prometheus-svc 10.76.0.2:9090 6m49s
$ kubectl get svc -n kube-system prometheus-svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
prometheus-svc NodePort 172.16.135.24 none 9090:32114/TCP 2m7s 如果希望可视化监控指标您可以安装Grafana验证监控数据具体操作可以参考文档 5.部署 metrics server 检查该集群是否包括metrics-server, 执行kubectl top node有正确输出可以显示内存和CPU则该集群metrics server配置正确 kubectl top node
NAME CPU(cores) CPU% MEMORY(bytes) MEMORY%
192.168.1.204 93m 2% 1455Mi 10%
192.168.1.205 125m 3% 1925Mi 13%
192.168.1.206 96m 2% 1689Mi 11% 否则手动执行以下命令 kubectl create -f integration/metrics-server 6.部署 custom-metrics-api 组件 为了基于自定义指标进行扩展你需要拥有两个组件。第一个组件是从应用程序收集指标并将其存储到Prometheus时间序列数据库。第二个组件使用收集的度量指标来扩展Kubernetes自定义metrics API即 k8s-prometheus-adapter。第一个组件在第三步部署完成下面部署第二个组件 如果已经配置了custom-metrics-api在adapter的configmap配置中增加与dataset相关的配置 apiVersion: v1
kind: ConfigMap
metadata:name: adapter-confignamespace: monitoring
data:config.yaml: |rules:- seriesQuery: {__name__~Cluster_(CapacityTotal|CapacityUsed),fluid_runtime!,instance!,joballuxio runtime,namespace!,pod!}seriesFilters:- is: ^Cluster_(CapacityTotal|CapacityUsed)$resources:overrides:namespace:resource: namespacepod:resource: podsfluid_runtime:resource: datasetsname:matches: ^(.*)as: capacity_used_ratemetricsQuery: ceil(Cluster_CapacityUsed{.LabelMatchers}*100/(Cluster_CapacityTotal{.LabelMatchers})) 否则手动执行以下命令 kubectl create -f integration/custom-metrics-api/namespace.yaml
kubectl create -f integration/custom-metrics-api 注意因为custom-metrics-api对接集群中的Prometheous的访问地址请替换prometheous url为你真正使用的Prometheous地址。 检查自定义指标 $ kubectl get --raw /apis/custom.metrics.k8s.io/v1beta1 | jq
{kind: APIResourceList,apiVersion: v1,groupVersion: custom.metrics.k8s.io/v1beta1,resources: [{name: pods/capacity_used_rate,singularName: ,namespaced: true,kind: MetricValueList,verbs: [get]},{name: datasets.data.fluid.io/capacity_used_rate,singularName: ,namespaced: true,kind: MetricValueList,verbs: [get]},{name: namespaces/capacity_used_rate,singularName: ,namespaced: false,kind: MetricValueList,verbs: [get]}]
} 7.提交测试使用的Dataset $ catEOF dataset.yaml
apiVersion: data.fluid.io/v1alpha1
kind: Dataset
metadata:name: spark
spec:mounts:- mountPoint: https://mirrors.bit.edu.cn/apache/spark/name: spark
---
apiVersion: data.fluid.io/v1alpha1
kind: AlluxioRuntime
metadata:name: spark
spec:replicas: 1tieredstore:levels:- mediumtype: MEMpath: /dev/shmquota: 1Gihigh: 0.99low: 0.7properties:alluxio.user.streaming.data.timeout: 300sec
EOF
$ kubectl create -f dataset.yaml
dataset.data.fluid.io/spark created
alluxioruntime.data.fluid.io/spark created 8.查看这个Dataset是否处于可用状态, 可以看到该数据集的数据总量为2.71GiB 目前Fluid提供的缓存节点数为1可以提供的最大缓存能力为1GiB。此时数据量是无法满足全量数据缓存的需求。 $ kubectl get dataset
NAME UFS TOTAL SIZE CACHED CACHE CAPACITY CACHED PERCENTAGE PHASE AGE
spark 2.71GiB 0.00B 1.00GiB 0.0% Bound 7m38s 9.当该Dataset处于可用状态后查看是否已经可以从custom-metrics-api获得监控指标 kubectl get --raw /apis/custom.metrics.k8s.io/v1beta1/namespaces/default/datasets.data.fluid.io/*/capacity_used_rate | jq
{kind: MetricValueList,apiVersion: custom.metrics.k8s.io/v1beta1,metadata: {selfLink: /apis/custom.metrics.k8s.io/v1beta1/namespaces/default/datasets.data.fluid.io/%2A/capacity_used_rate},items: [{describedObject: {kind: Dataset,namespace: default,name: spark,apiVersion: data.fluid.io/v1alpha1},metricName: capacity_used_rate,timestamp: 2021-04-04T07:24:52Z,value: 0}]
} 10.创建 HPA任务 $ catEOF hpa.yaml
apiVersion: autoscaling/v2beta2
kind: HorizontalPodAutoscaler
metadata:name: spark
spec:scaleTargetRef:apiVersion: data.fluid.io/v1alpha1kind: AlluxioRuntimename: sparkminReplicas: 1maxReplicas: 4metrics:- type: Objectobject:metric:name: capacity_used_ratedescribedObject:apiVersion: data.fluid.io/v1alpha1kind: Datasetname: sparktarget:type: Valuevalue: 90behavior:scaleUp:policies:- type: Podsvalue: 2periodSeconds: 600scaleDown:selectPolicy: Disabled
EOF 首先我们解读一下从样例配置这里主要有两部分一个是扩缩容的规则另一个是扩缩容的灵敏度 规则触发扩容行为的条件为Dataset对象的缓存数据量占总缓存能力的90%; 扩容对象为AlluxioRuntime, 最小副本数为1最大副本数为4; 而Dataset和AlluxioRuntime的对象需要在同一个namespace策略 可以K8s 1.18以上的版本可以分别针对扩容和缩容场景设置稳定时间和一次扩缩容步长比例。比如在本例子, 一次扩容周期为10分钟(periodSeconds),扩容时新增2个副本数当然这也不可以超过 maxReplicas 的限制而完成一次扩容后, 冷却时间(stabilizationWindowSeconds)为20分钟; 而缩容策略可以选择直接关闭。11.查看HPA配置 当前缓存空间的数据占比为0。远远低于触发扩容的条件 $ kubectl get hpa
NAME REFERENCE TARGETS MINPODS MAXPODS REPLICAS AGE
spark AlluxioRuntime/spark 0/90 1 4 1 33s
$ kubectl describe hpa
Name: spark
Namespace: default
Labels: none
Annotations: none
CreationTimestamp: Wed, 07 Apr 2021 17:36:39 0800
Reference: AlluxioRuntime/spark
Metrics: ( current / target )capacity_used_rate on Dataset/spark (target value): 0 / 90
Min replicas: 1
Max replicas: 4
Behavior:Scale Up:Stabilization Window: 0 secondsSelect Policy: MaxPolicies:- Type: Pods Value: 2 Period: 600 secondsScale Down:Select Policy: DisabledPolicies:- Type: Percent Value: 100 Period: 15 seconds
AlluxioRuntime pods: 1 current / 1 desired
Conditions:Type Status Reason Message---- ------ ------ -------AbleToScale True ScaleDownStabilized recent recommendations were higher than current one, applying the highest recent recommendationScalingActive True ValidMetricFound the HPA was able to successfully calculate a replica count from Dataset metric capacity_used_rateScalingLimited False DesiredWithinRange the desired count is within the acceptable range
Events: none 12.创建数据预热任务 $ catEOF dataload.yaml
apiVersion: data.fluid.io/v1alpha1
kind: DataLoad
metadata:name: spark
spec:dataset:name: sparknamespace: default
EOF
$ kubectl create -f dataload.yaml
$ kubectl get dataload
NAME DATASET PHASE AGE DURATION
spark spark Executing 15s Unfinished 13.此时可以发现缓存的数据量接近了Fluid可以提供的缓存能力1GiB同时触发了弹性伸缩的条件 $ kubectl get dataset
NAME UFS TOTAL SIZE CACHED CACHE CAPACITY CACHED PERCENTAGE PHASE AGE
spark 2.71GiB 1020.92MiB 1.00GiB 36.8% Bound 5m15s 从HPA的监控可以看到Alluxio Runtime的扩容已经开始, 可以发现扩容的步长为2 $ kubectl get hpa
NAME REFERENCE TARGETS MINPODS MAXPODS REPLICAS AGE
spark AlluxioRuntime/spark 100/90 1 4 2 4m20s
$ kubectl describe hpa
Name: spark
Namespace: default
Labels: none
Annotations: none
CreationTimestamp: Wed, 07 Apr 2021 17:56:31 0800
Reference: AlluxioRuntime/spark
Metrics: ( current / target )capacity_used_rate on Dataset/spark (target value): 100 / 90
Min replicas: 1
Max replicas: 4
Behavior:Scale Up:Stabilization Window: 0 secondsSelect Policy: MaxPolicies:- Type: Pods Value: 2 Period: 600 secondsScale Down:Select Policy: DisabledPolicies:- Type: Percent Value: 100 Period: 15 seconds
AlluxioRuntime pods: 2 current / 3 desired
Conditions:Type Status Reason Message---- ------ ------ -------AbleToScale True SucceededRescale the HPA controller was able to update the target scale to 3ScalingActive True ValidMetricFound the HPA was able to successfully calculate a replica count from Dataset metric capacity_used_rateScalingLimited False DesiredWithinRange the desired count is within the acceptable range
Events:Type Reason Age From Message---- ------ ---- ---- -------Normal SuccessfulRescale 21s horizontal-pod-autoscaler New size: 2; reason: Dataset metric capacity_used_rate above targetNormal SuccessfulRescale 6s horizontal-pod-autoscaler New size: 3; reason: Dataset metric capacity_used_rate above target14.在等待一段时间之后发现数据集的缓存空间由1GiB提升到了3GiB数据缓存已经接近完成
$ kubectl get dataset
NAME UFS TOTAL SIZE CACHED CACHE CAPACITY CACHED PERCENTAGE PHASE AGE
spark 2.71GiB 2.59GiB 3.00GiB 95.6% Bound 12m同时观察HPA的状态可以发现此时Dataset对应的runtime的replicas数量为3 已经使用的缓存空间比例capacity_used_rate为85%已经不会触发缓存扩容。
$ kubectl get hpa
NAME REFERENCE TARGETS MINPODS MAXPODS REPLICAS AGE
spark AlluxioRuntime/spark 85/90 1 4 3 11m16.清理环境
kubectl delete hpa spark
kubectl delete dataset spark总结
Fluid提供了结合PrometheousKubernetes HPA和Custom Metrics能力根据占用缓存空间的比例触发自动弹性伸缩的能力实现缓存能力的按需使用。这样能够帮助用户更加灵活的使用通过分布式缓存提升数据访问加速能力后续我们会提供定时扩缩的能力为扩缩容提供更强的确定性。
原文链接
本文为阿里云原创内容未经允许不得转载。