我正在嘗試使用 spark 3.2.1 映像向 Kubernetes 集群運行 spark-submit,它正在運行。現在我的問題是,我可以與 spark-submit 一起執行一個 init 容器嗎?我試圖實作的是初始化容器檢查另一個服務是否啟動,它是啟動然后 spark-submit 將運行還是失敗。
我可以看到 spark 版本 2.3 的 conf 引數“spark.kubernetes.initContainer.image”但不是 3.2.1(https://spark.apache.org/docs/2.3.0/running-on-kubernetes.html )
在我提交 Spark 作業之前,是否有任何機制可以用來檢查其他服務是否啟動?
我可以在下面的鏈接中看到 spark 的 init 容器使用情況,但它沒有提供準確的答案
https://docs.bitnami.com/kubernetes/infrastructure/spark/configuration/configure-sidecar-init-containers/ https://doc.lucidworks.com/spark-guide/11153/running-spark-on-kubernetes
任何幫助將不勝感激,謝謝。
uj5u.com熱心網友回復:
我發現提交 Spark 作業的最佳方式是 sparkoperator,更多詳細資訊可以在GitHub 鏈接中找到
有一個選項可以包含一個 init 容器和一個 sidecar 容器。
uj5u.com熱心網友回復:
您沒有提及其他服務是否在同一個容器中,但原理是相同的。它在此處的檔案中進行了介紹,并給出了這個示例,該示例定義了一個具有兩個 init 容器的簡單 Pod。第一個等待 myservice,第二個等待 mydb。一旦兩個 init 容器都完成,Pod 就會從其規范部分運行應用程式容器。
apiVersion: v1
kind: Pod
metadata:
name: myapp-pod
labels:
app: myapp
spec:
containers:
- name: myapp-container
image: busybox:1.28
command: ['sh', '-c', 'echo The app is running! && sleep 3600']
initContainers:
- name: init-myservice
image: busybox:1.28
command: ['sh', '-c', "until nslookup myservice.$(cat /var/run/secrets/kubernetes.io/serviceaccount/namespace).svc.cluster.local; do echo waiting for myservice; sleep 2; done"]
- name: init-mydb
image: busybox:1.28
command: ['sh', '-c', "until nslookup mydb.$(cat /var/run/secrets/kubernetes.io/serviceaccount/namespace).svc.cluster.local; do echo waiting for mydb; sleep 2; done"]
uj5u.com熱心網友回復:
您可以為您的 pod 定義一個 pod 模板
./bin/spark-submit --master k8s://50.1.0.4:6443 --deploy-mode cluster --name spark-pi --conf spark.kubernetes.authenticate.driver.serviceAccountName=spark --class org.apache.spark.examples.SparkPi --conf spark.executor.instances=1 --conf spark.kubernetes.container.image=spark:v3.2.1
--conf spark.kubernetes.driver.podTemplateFile=//path/my_pod_template.yaml
--conf spark.kubernetes.executor.podTemplateFile=//path/my_pod_template.yaml
--conf local:///opt/spark/examples/jars/spark-examples_2.12-3.2.1.jar
my_pod_template.yaml:
類似于艾倫的回答
spec:
containers:
- name: myapp-container
image: busybox:1.28
command: ['sh', '-c', 'echo The app is running! && sleep 3600']
initContainers:
- name: init-myservice
image: busybox:1.28
command: ['sh', '-c', "until nslookup myservice.$(cat /var/run/secrets/kubernetes.io/serviceaccount/namespace).svc.cluster.local; do echo waiting for myservice; sleep 2; done"]
- name: init-mydb
image: busybox:1.28
command: ['sh', '-c', "until nslookup mydb.$(cat /var/run/secrets/kubernetes.io/serviceaccount/namespace).svc.cluster.local; do echo waiting for mydb; sleep 2; done"]
來源: https ://spark.apache.org/docs/latest/running-on-kubernetes.html#pod-template
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/429919.html
標籤:阿帕奇火花 Kubernetes
