【Spark Operator】webhook的分析

Spark Operator 支持 Webhook,因为 Spark on Kubernetes 模块对 Pod 的特性支持得太有限了,这个问题主要就是如果通过 Spark Conf 传特性,那么 Spark Conf 就得膨胀,通过 Pod Template 去,又因为 Spark 本身没有对 Template 文件去校验,这样会导致调试很麻烦,而 Webhook 相对比较轻一点,但是也是需要 1.8 以上的 Kubernetes 版本才能用。Webhook 本身的代码量并不多,可以仔细看看,核心代码都在 webhook.go 文件里了。
在这里插入图片描述
另外就是 webhook 在 v1.14 里只支持 namespaceselector,也就是这个 namespace 下的 pod 都会过一遍这个 webhook,通过 patch 去调整 Pod,但如果业务使用的时候,一个 namespace 下有很多其他类型的计算任务,那么其他类型的计算任务也需要过一次 webhoo,那就是完全没必要的了。
幸好的是 v1.16 之后,支持类似于 podlabelselector 之类的功能,也就是 Pod 需要满足包含约定的 Label 的,才会过一遍 webhook。

	// NamespaceSelector decides whether to run the webhook on an object based
	// on whether the namespace for that object matches the selector. If the
	// object itself is a namespace, the matching is performed on
	// object.metadata.labels. If the object is another cluster scoped resource,
	// it never skips the webhook.
	//
	// For example, to run the webhook on any objects whose namespace is not
	// associated with "runlevel" of "0" or "1";  you will set the selector as
	// follows:
	// "namespaceSelector": {
	//   "matchExpressions": [
	//     {
	//       "key": "runlevel",
	//       "operator": "NotIn",
	//       "values": [
	//         "0",
	//         "1"
	//       ]
	//     }
	//   ]
	// }
	//
	// If instead you want to only run the webhook on any objects whose
	// namespace is associated with the "environment" of "prod" or "staging";
	// you will set the selector as follows:
	// "namespaceSelector": {
	//   "matchExpressions": [
	//     {
	//       "key": "environment",
	//       "operator": "In",
	//       "values": [
	//         "prod",
	//         "staging"
	//       ]
	//     }
	//   ]
	// }
	//
	// See
	// https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/
	// for more examples of label selectors.
	//
	// Default to the empty LabelSelector, which matches everything.
	// +optional
	NamespaceSelector *metav1.LabelSelector `json:"namespaceSelector,omitempty" protobuf:"bytes,5,opt,name=namespaceSelector"`

跟一般的 webhook 有点不一样的地方是,一般常见的 webhook 都是作为独立的服务部署在 k8s 集群里的,而 Spark Operator 的 webhook 相当于是 embeded 在 Spark Operator 里,跟 Spark Operator 在同一个 Pod 里。
在这里插入图片描述
Spark Operator 的 webhook 的第一个版本
如果给 Spark Operator 传了 enableWebhook 的参数,那么 webhook 就会在下图的流程中启动服务。个人认为,webhook 单独摘出来会比较好。
在这里插入图片描述

Reference

  1. https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/
  2. https://kubernetes.io/zh/docs/reference/access-authn-authz/extensible-admission-controllers/

我的博客即将同步至腾讯云+社区,邀请大家一同入驻:https://cloud.tencent.com/developer/support-plan?invite_code=6q5xqp08db5p

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Spark Operator是一个Kubernetes Operator,它可以在Kubernetes上运行Apache Spark应用程序。它提供了一种简单的方法来部署和管理Spark应用程序,而无需手动设置和配置。Spark Operator使用自定义资源定义(CRD)来定义Spark应用程序,这使得在Kubernetes上运行Spark应用程序变得更加容易和可靠。 以下是使用Spark Operator在Kubernetes上运行Spark应用程序的步骤: 1.安装Spark Operator:可以使用Helm Chart来安装Spark Operator,也可以使用kubectl命令手动安装。 2.创建SparkApplication:使用SparkApplication CRD来定义Spark应用程序。在SparkApplication中,您可以指定Spark应用程序的名称,镜像,主类,应用程序参数等。 3.提交Spark应用程序:使用kubectl命令提交Spark应用程序。Spark Operator将根据SparkApplication CRD中定义的规范来启动Spark应用程序。 以下是一个使用Spark Operator在Kubernetes上运行Spark应用程序的示例: ```yaml apiVersion: "sparkoperator.k8s.io/v1beta2" kind: SparkApplication metadata: name: spark-pi spec: type: Scala mode: cluster image: "gcr.io/spark-operator/spark:v3.0.0" mainClass: org.apache.spark.examples.SparkPi mainApplicationFile: "local:///opt/spark/examples/jars/spark-examples_2.12-3.0.0.jar" sparkVersion: "3.0.0" restartPolicy: type: Never driver: cores: 1 coreLimit: "1200m" memory: "512m" labels: version: 3.0.0 serviceAccount: spark executor: cores: 1 instances: 2 memory: "512m" labels: version: 3.0.0 ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值