Spark-operator離線部署
一、 準備材料
離線安裝包:spark-operator-install.zip
網盤:https://cloud.189.cn/t/6FJjiuFZFviy (訪問碼:n1ct)
二、 環境規劃
本次部署依賴於K8s1.21.2叢集,具體環境搭建參考《離線搭建K8s1.21.2叢集》
K8s版本:1.21.2
Spark版本:3.0.0
Spark-operator版本:latest
三、 部署過程
# 解壓spark-operator-install.zip包,進入解壓後的資料夾
# jmx_prometheus_javaagent-0.11.0.jar、spark-3.0.0-gcs-prometheus.tar可不理會,是為後面監控做準備的,本文暫不使用
# 載入spark-operator映象(所有節點均需要載入)
[root@k8s-master spark-operator-install]# docker load < spark-operator-latest.tar
# 載入spark3.0.0映象(所有節點均需要載入)
[root@k8s-master spark-operator-install]# docker load < spark-base-t1-1129.tar
# 解壓並進入spark-on-k8s-operator-master.zip
[root@k8s-master spark-operator-install]# unzip spark-on-k8s-operator-master.zip
# 檢視manifest目錄結構,後面需要使用
# 編輯manifest/spark-operator-install/spark-operator.yaml檔案,主要修改image、imagePullPolicy兩個屬性,改為自己的spark-operator映象,imagePullPolicy改為只使用本地映象,如下
[root@k8s-master spark-on-k8s-operator-master]# vim manifest/spark-operator-install/spark-operator.yaml
# 依次執行如下命令
[root@k8s-master spark-on-k8s-operator-master]# kubectl apply -k manifest/crds/
[root@k8s-master spark-on-k8s-operator-master]# kubectl apply -k manifest/spark-application-rbac/
[root@k8s-master spark-on-k8s-operator-master]# kubectl apply -k manifest/spark-operator-install/
# 執行後效果
#如果要回退,可以使用命令:kubectl delete -k manifest/spark-operator-install/
# 檢視容器是否跑起來
[root@k8s-master spark-on-k8s-operator-master]# kubectl get pods -n spark-operator
# 第二種方式檢視是否成功,去視覺化介面選擇明明空間spark-operator,選擇pods,是否出現新的容器,再檢視容器日誌,沒有報錯,即成功
四、 執行示例
# 修改examples/spark-pi.yaml中的容器映象為我們之前建立的spark映象
# 如下所示, 主要修改spec.image 和 imagePullPolicy
# 其中,需要注意namespace和serviceAccount的對應關係,如果執行不成功,大概率是這兩個導致的許可權問題,
#本次namespace: spark-operator、serviceAccountName: sparkoperator,可以去manifest/spark-operator-install/spark-operator.yaml裡檢視
[root@k8s-master spark-on-k8s-operator-master]# vim examples/spark-pi.yaml
# 完整內容如下:
# ======↓↓↓↓↓↓======
apiVersion: "sparkoperator.k8s.io/v1beta2"
kind: SparkApplication
metadata:
name: spark-pi
namespace: spark-operator
spec:
type: Scala
mode: cluster
image: "spark-base-t1:v3.0.0"
imagePullPolicy: Never
mainClass: org.apache.spark.examples.JavaSparkPi
mainApplicationFile: "local:///opt/spark/examples/jars/spark-examples_2.12-3.0.0.jar"
sparkVersion: "3.0.0"
restartPolicy:
type: Never
volumes:
- name: "test-volume"
hostPath:
path: "/tmp"
type: Directory
driver:
cores: 1
coreLimit: "1200m"
memory: "512m"
labels:
version: 3.0.0
serviceAccount: sparkoperator
volumeMounts:
- name: "test-volume"
mountPath: "/tmp"
executor:
cores: 1
instances: 1
memory: "512m"
labels:
version: 3.0.0
volumeMounts:
- name: "test-volume"
mountPath: "/tmp"
# ======↑↑↑↑↑↑======
# 然後執行kubectl執行建立任務
[root@k8s-master spark-on-k8s-operator-master]# kubectl apply -f examples/spark-pi.yaml
# 檢視執行容器
[root@k8s-master spark-on-k8s-operator-master]# kubectl get pods -n spark-operator
#可以看到spark-pi-driver,狀態Completed,即執行完成了
#或者可以去瀏覽器看
#至此,部署結束,至於spark的指標監控,有時間再出教程