Skip to content
This repository was archived by the owner on Jan 9, 2020. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import com.google.common.base.Charsets
import com.google.common.io.Files
import io.fabric8.kubernetes.client.{Config, ConfigBuilder, DefaultKubernetesClient}

import org.apache.spark.deploy.kubernetes.constants._

private[spark] object KubernetesClientBuilder {
private val API_SERVER_TOKEN = new File(Config.KUBERNETES_SERVICE_ACCOUNT_TOKEN_PATH)
private val CA_CERT_FILE = new File(Config.KUBERNETES_SERVICE_ACCOUNT_CA_CRT_PATH)
Expand All @@ -32,12 +34,13 @@ private[spark] object KubernetesClientBuilder {
* are picked up from canonical locations, as they are injected
* into the pod's disk space.
*/
def buildFromWithinPod(
kubernetesMaster: String,
kubernetesNamespace: String): DefaultKubernetesClient = {
def buildFromWithinPod(kubernetesNamespace: String, useSsl: Boolean): DefaultKubernetesClient = {
val kubernetesHost = System.getenv(ENV_KUBERNETES_SERVICE_HOST)
val kubernetesPort = System.getenv(ENV_KUBERNETES_SERVICE_PORT)
val urlScheme = if (useSsl) "https" else "http"
var clientConfigBuilder = new ConfigBuilder()
.withApiVersion("v1")
.withMasterUrl(kubernetesMaster)
.withMasterUrl(s"$urlScheme://$kubernetesHost:$kubernetesPort")
Copy link
Member

@foxish foxish Feb 15, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be https always. Even if the user uses the insecure endpoint to access the apiserver from outside the cluster, KUBERNETES_SERVICE_PORT should point to the secure endpoint.

.withNamespace(kubernetesNamespace)

if (CA_CERT_FILE.isFile) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ package object constants {
private[spark] val ENV_EXECUTOR_MEMORY = "SPARK_EXECUTOR_MEMORY"
private[spark] val ENV_APPLICATION_ID = "SPARK_APPLICATION_ID"
private[spark] val ENV_EXECUTOR_ID = "SPARK_EXECUTOR_ID"
private[spark] val ENV_KUBERNETES_SERVICE_HOST = "KUBERNETES_SERVICE_HOST"
private[spark] val ENV_KUBERNETES_SERVICE_PORT = "KUBERNETES_SERVICE_PORT"

// Miscellaneous
private[spark] val DRIVER_CONTAINER_NAME = "spark-kubernetes-driver"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ private[spark] class KubernetesClusterSchedulerBackend(
private val EXECUTOR_MODIFICATION_LOCK = new Object
private val runningExecutorPods = new scala.collection.mutable.HashMap[String, Pod]

private val kubernetesMaster = "https://kubernetes"
private val executorDockerImage = conf.get(EXECUTOR_DOCKER_IMAGE)
private val kubernetesNamespace = conf.get(KUBERNETES_NAMESPACE)
private val executorPort = conf.getInt("spark.executor.port", DEFAULT_STATIC_PORT)
Expand Down Expand Up @@ -76,8 +75,9 @@ private[spark] class KubernetesClusterSchedulerBackend(
private implicit val requestExecutorContext = ExecutionContext.fromExecutorService(
ThreadUtils.newDaemonCachedThreadPool("kubernetes-executor-requests"))

private val kubernetesUseSsl = Client.resolveK8sMaster(sc.master).startsWith("https")
private val kubernetesClient = KubernetesClientBuilder
.buildFromWithinPod(kubernetesMaster, kubernetesNamespace)
.buildFromWithinPod(kubernetesNamespace, kubernetesUseSsl)

private val driverPod = try {
kubernetesClient.pods().inNamespace(kubernetesNamespace).
Expand Down