Spark Gateway uses a YAML configuration file that can be passed to both gateway and sparkManager processes via the --conf flag.
List of Kubernetes clusters where SparkApplications can be submitted. Each cluster must have a unique configuration.
Note: Due to the constraint around SparkApplication name length (see Design Doc), and to allow admins the ability to keep their K8s cluster names arbitrary, we use cluster
ids to make lookups easier while staying within the character limit. Thus, an example SparkApplication name will look likeclusterid-namespaceid-<UUID>.
Each cluster in the clusters list has the following attributes:
name- The cluster's name as specified in the kubeconfig fileid- A user-defined identifier which must be unique per cluster and contain only lowercase letters and numbers (max 12 characters)masterURL- The Kubernetes API server hostnameroutingWeight- Weight for load balancing (defaults to 1.0 if not specified)namespaces- List of namespaces supported by the cluster.certificateAuthorityB64File- Path to a file containing the base64 encoded certificate authority (only used ifsparkManager.clusterAuthTypeis set toserviceaccount)
Certificate Authority Options (certificateAuthorityB64File config):
- Set to
inclusteror leave unset. This is the default option, Spark Gateway will read the CA from/var/run/secrets/kubernetes.io/serviceaccount/ca.crt. Use this option if Spark Gateway is deployed on the same cluster to which it submits SparkApplications. - Set to
insecureto disable certificate validation (unencrypted, insecure traffic to Kube API Server) - Set to a file path containing the base64 encoded certificate authority (typically mounted to pod via K8s Secret). Use this option if Spark Gateway is deployed on a different K8s cluster than where the SparkApplications are submitted.
Note: It is not recommended to change a cluster's
idonce jobs are deployed to that cluster. If theidis updated, Gateway will lose track of jobs that were submitted using the olderid.
Each namespace in a cluster has:
name- The Kubernetes namespace nameid- A user-defined identifier (max 12 characters, lowercase alphanumeric only)routingWeight- Weight for load balancing within the namespace (defaults to 1.0 if not specified)
clusters:
- name: dev-k8s-cluster
id: dev1
masterURL: your.k8s.api.server
routingWeight: 10
certificateAuthorityB64File: /etc/certificate-authority
namespaces:
- name: team-a-spark
id: teama
routingWeight: 1Configuration for routing SparkApplications to clusters.
random- Random selection between available clustersweightBased- Weight-based selection using Prometheus metrics (WIP)weightBasedRandom- Weight-based random selection (default)
type- Primary router typefallbackType- Router type to use if primary fails (recommended:randomorweightBasedRandom)dimension- Routing dimension:namespaceorcluster. This determines whethernamespaceorclusterlevel metrics are used to determine the best cluster to route a new SparkApplication to during the cluster selection process at submission time. For instance, iftypeis set toweightBased,dimensionis set tonamespaceandprometheusQuery.metricis set tospark_application_count, then Spark Gateway will use the number of spark applications in the namespace specified in the submitted SparkApp to determine the best cluster to route to. However, if the dimension is set tocluster, then Spark Gateway will use the number of spark applications in the cluster including all namespaces in the cluster, to determine the best cluster to route to.prometheusQuery- Configuration for Prometheus metrics queries
clusterRouter:
type: weightBased
fallbackType: weightBasedRandom
dimension: namespace # Equivalent to `spark_application_count{"namespace":"specified-NS"}` PromQL
prometheusQuery:
metric: spark_application_count # Should be a gauge metricThe default number of lines to return when getting logs from a driver if the lines query parameter is not provided with the request.
Operating mode of the Spark Gateway. Common values include local for development.
Used to label and filter SparkApplications managed by Spark Gateway:
- Spark Gateway adds "
selectorKey=selectorValue" labels to all SparkApplications it creates - Gateway endpoints only recognize SparkApplications with these labels
- SparkManager only monitors SparkApplications with these labels, reducing memory footprint
selectorKey: "spark-gateway/owned"
selectorValue: "true"selectorKey: ""
selectorValue: ""Defines the port used by the SparkManager server.
Gateway server configuration.
Defines the port used by the Gateway server.
List of middleware to apply to Gateway requests. Available middleware types:
RegexBasicAuthAllowMiddleware- Checks the user from the Authorization header against the list of regex patterns specified in its configuration. The request is allowed only if the user matches at least one pattern; otherwise, it is denied.RegexBasicAuthDenyMiddleware- Checks the user from the Authorization header against the list of regex patterns specified in its configuration. If the user matches any of these patterns, the request is denied.HeaderAuthMiddleware- Authenticate based on HTTP headersServiceTokenAuthMiddleware- Authenticate using service tokens
Regex Basic Auth:
middleware:
- type: RegexBasicAuthAllowMiddleware
conf:
allow:
- .*Header Auth:
middleware:
- type: HeaderAuthMiddleware
conf:
headers:
- key: Auth-UserService Token Auth:
middleware:
- type: ServiceTokenAuthMiddleware
conf:
serviceTokenMapFile: /conf/service-auth-config.yamlTemplates for generating status URLs. Any field from v1beta2.SparkApplication can be used for templating.
See SparkApplication API Docs
and the SparkApplication struct
for reference.
statusUrlTemplates:
sparkUI: "{{.Status.DriverInfo.WebUIIngressAddress}}"
sparkHistoryUI: "https://spark-history-{{.ObjectMeta.Namespace}}.example.com/history/{{.Status.SparkApplicationID}}/jobs"
logsUI: "https://kibana.example.com/app/discover#/?_g=(filters:!(),refreshInterval:(pause:!t,value:0),time:(from:now-1d,to:now))&_a=(interval:auto,query:(language:lucene,query:'host:%20%22{{.ObjectMeta.Name}}-driver%22'),sort:!(!('@timestamp',desc)))"Enables Swagger UI for REST API Docs. The UI will be accessible at /docs endpoint.
Example: enableSwaggerUI: true
SparkManager server configuration.
Authentication type for accessing Kubernetes clusters:
serviceaccount- Use service account credentials (recommended for production). See all certificate authority options in Cluster Configurations section.kubeconfig- Use local kubeconfig (typically for development)
Database configuration for persisting submission requests and SparkApplication specs.
Connection string format: postgres://{username}:{password}@{hostname}:{port}/{databaseName}
Configuration Options:
enable- Enable database functionalitydatabaseName- Database namehostname- Database hostnameport- Database portusername- Database username (can useDB_USERNAMEenvironment variable)password- Database password (can useDB_PASSWORDenvironment variable)
Setting Database Credentials:
Username and password can be set via configuration or environment variables. If database.username and database.password are not present, DB_USERNAME and DB_PASSWORD environment variables will be used.
For security reasons, it's recommended to use environment variables for production deployments.
Metrics server configuration for Prometheus metrics.
metricsServer:
endpoint: "/metrics"
port: "9090"Allows developers to set custom ports for different SparkManagers to avoid port collisions during local development.
debugPorts:
cluster-name:
sparkManagerPort: "8085"
metricsPort: "9095"See configurations in configs/local.yaml