|
| 1 | += Configuration & Environment Overrides |
| 2 | + |
| 3 | +The cluster definition also supports overriding configuration properties and environment variables, either per role or per role group, where the more specific override (role group) has precedence over the less specific one (role). |
| 4 | + |
| 5 | +IMPORTANT: Overriding operator-set properties (such as the ports) can interfere with the operator and can lead to problems. |
| 6 | + |
| 7 | + |
| 8 | +== Configuration Properties |
| 9 | + |
| 10 | +For a role or role group, at the same level of `config`, you can specify `configOverrides` for the following files: |
| 11 | + |
| 12 | +* `spark-env.sh` |
| 13 | +* `security.properties` |
| 14 | + |
| 15 | +NOTE: `spark-defaults.conf` is not required here, because the properties defined in {crd-docs}/spark.stackable.tech/sparkhistoryserver/v1alpha1/#spec-sparkConf[`sparkConf` (SparkHistoryServer)] and {crd-docs}/spark.stackable.tech/sparkapplication/v1alpha1/#spec-sparkConf[`sparkConf` (SparkApplication)] are already added to this file. |
| 16 | + |
| 17 | +For example, if you want to set the `networkaddress.cache.ttl`, it can be configured in the SparkHistoryServer resource like so: |
| 18 | + |
| 19 | +[source,yaml] |
| 20 | +---- |
| 21 | +nodes: |
| 22 | + roleGroups: |
| 23 | + default: |
| 24 | + configOverrides: |
| 25 | + security.properties: |
| 26 | + networkaddress.cache.ttl: "30" |
| 27 | + replicas: 1 |
| 28 | +---- |
| 29 | + |
| 30 | +Just as for the `config`, it is possible to specify this at the role level as well: |
| 31 | + |
| 32 | +[source,yaml] |
| 33 | +---- |
| 34 | +nodes: |
| 35 | + configOverrides: |
| 36 | + security.properties: |
| 37 | + networkaddress.cache.ttl: "30" |
| 38 | + roleGroups: |
| 39 | + default: |
| 40 | + replicas: 1 |
| 41 | +---- |
| 42 | + |
| 43 | +All override property values must be strings. |
| 44 | + |
| 45 | +The same applies to the `job`, `driver` and `executor` roles of the SparkApplication. |
| 46 | + |
| 47 | +=== The spark-env.sh file |
| 48 | + |
| 49 | +The `spark-env.sh` file is used to set environment variables. |
| 50 | +Usually, environment variables are configured in `envOverrides` or {crd-docs}/spark.stackable.tech/sparkapplication/v1alpha1/#spec-env[`env` (SparkApplication)], but both options only allow static values to be set. |
| 51 | +The values in `spark-env.sh` are evaluated by the shell. |
| 52 | +For instance, if a SAS token is stored in a Secret and should be used for the Spark History Server, this token could be first stored in an environment variable via `podOverrides` and then added to the `SPARK_HISTORY_OPTS`: |
| 53 | + |
| 54 | +[source,yaml] |
| 55 | +---- |
| 56 | +podOverrides: |
| 57 | + spec: |
| 58 | + containers: |
| 59 | + - name: spark-history |
| 60 | + env: |
| 61 | + - name: SAS_TOKEN |
| 62 | + valueFrom: |
| 63 | + secretKeyRef: |
| 64 | + name: adls-spark-credentials |
| 65 | + key: sas-token |
| 66 | +configOverrides: |
| 67 | + spark-env.sh: |
| 68 | + SPARK_HISTORY_OPTS: >- |
| 69 | + $SPARK_HISTORY_OPTS |
| 70 | + -Dspark.hadoop.fs.azure.sas.fixed.token.mystorageaccount.dfs.core.windows.net=$SAS_TOKEN |
| 71 | +---- |
| 72 | + |
| 73 | +NOTE: The given properties are written to `spark-env.sh` in the form `export KEY="VALUE"`. |
| 74 | +Make sure to escape the value already in the specification. |
| 75 | +Be aware that some environment variables may already be set, so prepend or append a reference to them in the value, as it is done in the example. |
| 76 | + |
| 77 | +=== The security.properties file |
| 78 | + |
| 79 | +The `security.properties` file is used to configure JVM security properties. |
| 80 | +It is very seldom that users need to tweak any of these, but there is one use-case that stands out, and that users need to be aware of: the JVM DNS cache. |
| 81 | + |
| 82 | +The JVM manages its own cache of successfully resolved host names as well as a cache of host names that cannot be resolved. |
| 83 | +Some products of the Stackable platform are very sensitive to the contents of these caches and their performance is heavily affected by them. |
| 84 | +As of version 3.4.0, Apache Spark may perform poorly if the positive cache is disabled. |
| 85 | +To cache resolved host names, and thus speed up queries, you can configure the TTL of entries in the positive cache like this: |
| 86 | + |
| 87 | +[source,yaml] |
| 88 | +---- |
| 89 | +spec: |
| 90 | + nodes: |
| 91 | + configOverrides: |
| 92 | + security.properties: |
| 93 | + networkaddress.cache.ttl: "30" |
| 94 | + networkaddress.cache.negative.ttl: "0" |
| 95 | +---- |
| 96 | + |
| 97 | +NOTE: The operator configures DNS caching by default as shown in the example above. |
| 98 | + |
| 99 | +For details on the JVM security see https://docs.oracle.com/en/java/javase/11/security/java-security-overview1.html |
| 100 | + |
| 101 | + |
| 102 | +== Environment Variables |
| 103 | + |
| 104 | +Similarly, environment variables can be (over)written. For example per role group: |
| 105 | + |
| 106 | +[source,yaml] |
| 107 | +---- |
| 108 | +nodes: |
| 109 | + roleGroups: |
| 110 | + default: |
| 111 | + envOverrides: |
| 112 | + MY_ENV_VAR: "MY_VALUE" |
| 113 | + replicas: 1 |
| 114 | +---- |
| 115 | + |
| 116 | +or per role: |
| 117 | + |
| 118 | +[source,yaml] |
| 119 | +---- |
| 120 | +nodes: |
| 121 | + envOverrides: |
| 122 | + MY_ENV_VAR: "MY_VALUE" |
| 123 | + roleGroups: |
| 124 | + default: |
| 125 | + replicas: 1 |
| 126 | +---- |
| 127 | + |
| 128 | +In a SparkApplication, environment variables can also be defined with the {crd-docs}/spark.stackable.tech/sparkapplication/v1alpha1/#spec-env[`env`] property for the job, driver and executor pods at once. |
| 129 | +The result is basically the same as with `envOverrides`, but `env` also allows to reference Secrets and so on: |
| 130 | + |
| 131 | +[source,yaml] |
| 132 | +---- |
| 133 | +--- |
| 134 | +apiVersion: spark.stackable.tech/v1alpha1 |
| 135 | +kind: SparkApplication |
| 136 | +spec: |
| 137 | + env: |
| 138 | + - name: SAS_TOKEN |
| 139 | + valueFrom: |
| 140 | + secretKeyRef: |
| 141 | + name: adls-spark-credentials |
| 142 | + key: sas-token |
| 143 | + ... |
| 144 | +---- |
| 145 | + |
| 146 | + |
| 147 | +== Pod overrides |
| 148 | + |
| 149 | +The Spark operator also supports Pod overrides, allowing you to override any property that you can set on a Kubernetes Pod. |
| 150 | +Read the xref:concepts:overrides.adoc#pod-overrides[Pod overrides documentation] to learn more about this feature. |
0 commit comments