Skip to content

SparkKubernetesClientFactory Utility

SparkKubernetesClientFactory is a Spark-opinionated builder for Kubernetes clients.

Creating KubernetesClient

  master: String,
  namespace: Option[String],
  kubernetesAuthConfPrefix: String,
  clientType: ClientType.Value,
  sparkConf: SparkConf,
  defaultServiceAccountToken: Option[File],
  defaultServiceAccountCaCert: Option[File]): KubernetesClient

createKubernetesClient utility takes the OAuth token-related configuration properties from the input SparkConf:

  • kubernetesAuthConfPrefix.oauthTokenFile (or defaults to the input defaultServiceAccountToken)
  • kubernetesAuthConfPrefix.oauthToken

createKubernetesClient takes the spark.kubernetes.context configuraiton property (kubeContext).

createKubernetesClient takes the certificate-related configuration properties from the input SparkConf:

  • kubernetesAuthConfPrefix.caCertFile (or defaults to the input defaultServiceAccountCaCert)
  • kubernetesAuthConfPrefix.clientKeyFile
  • kubernetesAuthConfPrefix.clientCertFile

createKubernetesClient prints out the following INFO message to the logs:

Auto-configuring K8S client using [context [kubeContext] | current context] from users K8S config file

createKubernetesClient builds a Kubernetes Config (based on the configuration properties).

createKubernetesClient builds an OkHttpClient with a custom kubernetes-dispatcher dispatcher.

In the end, createKubernetesClient creates a Kubernetes DefaultKubernetesClient (with the OkHttpClient and Config).

createKubernetesClient is used when:


createKubernetesClient throws an IllegalArgumentException when an OAuth token is specified through a file and a value:

Cannot specify OAuth token through both a file [oauthTokenFileConf] and a value [oauthTokenConf].


Enable ALL logging level for org.apache.spark.deploy.k8s.SparkKubernetesClientFactory logger to see what happens inside.

Add the following line to conf/

Refer to Logging.

Back to top