本章节介绍VKE场景下,分别通过kubectl 和 sparkctl 来管理Spark作业,也可参考:
说明
下文中:
app_name:指SparkApplication CR Metadata中的name
app_namespace:指集群namespace,与EMR集群ID相同
app_driver_pod:指Spark 的Driver Pod名称
编写spark-pi-py.yaml 文件,例如:
apiVersion: "sparkoperator.k8s.io/v1beta2" kind: SparkApplication metadata: name: spark-pi spec: type: Scala sparkVersion: 3.5.1 mainClass: org.apache.spark.examples.SparkPi mainApplicationFile: "tos://xx/xx/spark-examples_2.12-3.5.1.jar" arguments: - "1000" driver: cores: 1 coreLimit: 1000m memory: 4g executor: cores: 1 coreLimit: 1000m memory: 8g memoryOverhead: 1g instances: 3
通过下述命令创建作业
kubectl apply -f spark-pi-py.yaml -n ${app_namespace}
kubectl get sparkapp -A
kubectl describe sparkapp ${app_name} -n ${app_namespace}
kubectl edit sparkapp ${app_name} -n ${app_namespace}
输入命令后,会进入vim编辑模式,修改后,spark-operator会根据修改内容,重新提交当前任务
kubectl logs ${app_driver_pod} -n ${app_namespace}
kubectl delete sparkapp ${app_name} -n ${app_namespace}
sparkclt 是spark-opeartor官方提供的SparkApplication管理命令行。用户可通过spark-operator官方仓库获取管理命令。
编写spark-pi-py.yaml 文件,例如:
apiVersion: "sparkoperator.k8s.io/v1beta2" kind: SparkApplication metadata: name: pyspark-pi spec: type: Python pythonVersion: "3" sparkVersion: 3.5.0 mode: cluster mainApplicationFile: tos://test-ziwen/pi.py image: emr-vke-qa-cn-beijing.cr.volces.com/emr/spark:3.5.1-1.0.0.97-20240226141635 # 指定 Driver镜像 restartPolicy: type: OnFailure onFailureRetries: 3 onFailureRetryInterval: 10 onSubmissionFailureRetries: 5 onSubmissionFailureRetryInterval: 20 driver: cores: 1 coreLimit: "1200m" memory: "512m" executor: cores: 1 instances: 1 memory: "512m"
注意
sparkclt创建 SparkApplication 时,会校验是否填写了镜像,用户可以在yaml image 字段中指定镜像可从spark-operator挂载的 spark-default-conf configmap -> spark-defaults.conf -> spark.kubernetes.container.image 中找到
通过下述命令创建作业
./sparkctl create spark-pi-py.yaml -n ${app_namespace}
sparkctl list -n ${app_namespace}
sparkctl status ${app_name} -n ${app_namespace}
kubectl edit sparkapp ${app_name} -n ${app_namespace}
sparkctl log ${app_driver_pod} -n ${app_namespace}
该参数会默认查看Driver日志
可通过下述命令查看executor id
sparkctl log ${app_driver_pod} -n ${app_namespace} [-e <executor ID, e.g., 1>]
sparkctl delete ${app_name} -n ${app_namespace}