Spark-on-k8s-operator: SparkApplication is not injecting env variables

Created on 16 Jul 2020  路  2Comments  路  Source: GoogleCloudPlatform/spark-on-k8s-operator

I am following the doc here: https://github.com/GoogleCloudPlatform/spark-on-k8s-operator/blob/master/docs/user-guide.md#specifying-environment-variables

my manifest:

apiVersion: "sparkoperator.k8s.io/v1beta2"
kind: SparkApplication
metadata:
  name: spark-search-indexer
  namespace: spark-operator
spec:
  type: Scala
  mode: cluster
  image: "gcr.io/spark-operator/spark:v2.4.5"
  imagePullPolicy: Always
  mainClass: com.quid.indexer.news.jobs.ESIndexingJob
  mainApplicationFile: "https://lala.com/baba-0.0.43.jar"
  arguments:
    - "--esSink"
    - "http://something:9200/mo-sn-{yyyy-MM}-v0.0.43/searchable-article"
    - "-streaming"
    - "--kafkaTopics"
    - "annotated_blogs,annotated_ln_news,annotated_news"
    - "--kafkaBrokers"
    - "10.1.1.1:9092"
  sparkVersion: "2.4.5"
  restartPolicy:
    type: Never
  volumes:
    - name: "test-volume"
      hostPath:
        path: "/tmp"
        type: Directory
  driver:
    cores: 1
    coreLimit: "1200m"
    memory: "512m"
    env:
      - name: "DEMOGRAPHICS_ES_URI"
        value: "somevalue"
    labels:
      version: 2.4.5
    volumeMounts:
      - name: "test-volume"
        mountPath: "/tmp"
  executor:
    cores: 1
    instances: 1
    memory: "512m"
    env:
      - name: "DEMOGRAPHICS_ES_URI"
        value: "somevalue"
    labels:
      version: 2.4.5
    volumeMounts:
      - name: "test-volume"
        mountPath: "/tmp"

Environment Variables set at pod:

Environment:
      SPARK_DRIVER_BIND_ADDRESS:   (v1:status.podIP)
      SPARK_LOCAL_DIRS:           /var/data/spark-1ed8539d-b157-4fab-9aa6-daff5789bfb5
      SPARK_CONF_DIR:             /opt/spark/conf

I followed the exact step in the doc but env variables are still not injected in executor or driver pod. Please help

Most helpful comment

Have you enabled the webhook? Using env or envFrom requires the webhook to be enabled. If all you need is a way to specify normal environment variables as key-value pairs, you can also use envVars, which doesn't need the webhook. Simply replace env with envVars.

All 2 comments

Have you enabled the webhook? Using env or envFrom requires the webhook to be enabled. If all you need is a way to specify normal environment variables as key-value pairs, you can also use envVars, which doesn't need the webhook. Simply replace env with envVars.

I haven't enabled webhooks. The following approach worked, thank you @liyinan926

   spec:
       executor:
           envVars:
               DEMOGRAPHICS_ES_URI: "somevalue"
Was this page helpful?
0 / 5 - 0 ratings