Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flink Kubernetes Support #2

Open
wants to merge 13 commits into
base: release-1.7
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 10 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
6 changes: 6 additions & 0 deletions flink-dist/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,12 @@ under the License.
</exclusions>
</dependency>

<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-kubernetes_${scala.binary.version}</artifactId>
<version>${project.version}</version>
</dependency>

<!-- Default file system support. The Hadoop and MapR dependencies -->
<!-- are optional, so not being added to the dist jar -->

Expand Down
2 changes: 2 additions & 0 deletions flink-dist/src/main/flink-bin/bin/flink-console.sh
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ case $SERVICE in
;;
esac

CLASS_TO_RUN=${FLINK_CLASS_TO_RUN:-$CLASS_TO_RUN}

FLINK_TM_CLASSPATH=`constructFlinkClassPath`

log_setting=("-Dlog4j.configuration=file:${FLINK_CONF_DIR}/log4j-console.properties" "-Dlogback.configurationFile=file:${FLINK_CONF_DIR}/logback-console.xml")
Expand Down
65 changes: 65 additions & 0 deletions flink-kubernetes/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Flink On Kubernetes

## Job manager
Job manager is run as a pod of corresponding deployment which is supposed to be prepared beforehand.
To create the deployment and a service for it the following templates (under `flink-kubernets/templates` path)
should be used:
```
jobmanager-deployment.yaml
jobmanager-service.yaml
```
Example:
```
kubectl create -f jobmanager-deployment.yaml
kubectl create -f jobmanager-service.yaml

Choose a reason for hiding this comment

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

jobmanager-exposer-deployment.yaml ?
Also, a question сomes up instantly how exactly it exposes?

Copy link
Author

Choose a reason for hiding this comment

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

That creates the deployment with one job manager and service around it that exposes
(ClusterIP/NodePort/LoadBalancer/ExternalName) the job manager
https://kubernetes.io/docs/concepts/services-networking/service/#publishing-services-service-types

```
That creates the deployment with one job manager and a service around it that exposes the job manager.

## Task Manager
Task manager is a temporary essence and is created (and deleted) by a job manager for a particular slot.
No deployments/jobs/services are created for a task manager only pods.

Choose a reason for hiding this comment

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

"for a task manager, only pods" comma missing?

A template for a task manager is hardcoded into the implementation
(`org.apache.flink.kubernetes.client.DefaultKubernetesClient`).

For every slot request the job manager passes a resource profile to a resource manager
(`org.apache.flink.kubernetes.KubernetesResourceManager`). The resource profile contains specific hardware requirements
(CPU, Memory and other). All these requirements are included into the pod template as labels thus they could be used for
binding specific pods onto specific VMs.

## Resource Profile
A resource profile might be set to a `StreamTransformation` by calling a corresponding method. A resource profile has
cpu cores, heap memory, direct memory, native memory, network memory and extended resources (GPU and user defined).
Only `StreamTransformation.minResources` is used for a pod template.

### Resource Profile Configuration Example
TBD

## Kubernetes Resource Management
Resource management uses a default service account every pod contains. It should has admin privileges to be able

Choose a reason for hiding this comment

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

"should have"

to create and delete pods:
```
kubectl create clusterrolebinding serviceaccounts-cluster-admin \
--clusterrole=cluster-admin \
--group=system:serviceaccounts
```

## Build and run
The implementation is based on existing mechanism of packaging (maven) and containerization (docker).

Prepare a package first:
```mvn clean package -DskipTests```
Then in needs to be containerized:
```cd flink-contrib/docker-flink/
sh build.sh --from-local-dist --image-name flink-mmx
```
If minikube is used then a container image should be uploaded into minikube node.
So before building a container image a docker env is supposed to be exported:
```
eval $(minikube docker-env)
```
Job manager deployment and service:
```
cd ../../flink-kubernetes/templates/
kubectl create -f jobmanager-deployment.yaml
kubectl create -f jobmanager-service.yaml
```
215 changes: 215 additions & 0 deletions flink-kubernetes/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,215 @@
<!--
~ Licensed to the Apache Software Foundation (ASF) under one
~ or more contributor license agreements. See the NOTICE file
~ distributed with this work for additional information
~ regarding copyright ownership. The ASF licenses this file
~ to you under the Apache License, Version 2.0 (the
~ "License"); you may not use this file except in compliance
~ with the License. You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.apache.flink</groupId>
<artifactId>flink-parent</artifactId>
<version>1.7-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>

<artifactId>flink-kubernetes_${scala.binary.version}</artifactId>
<name>flink-kubernetes</name>
<packaging>jar</packaging>

<properties>
<kubernetes.version>1.0.1</kubernetes.version>
</properties>

<dependencies>

<!-- set all Flink dependencies to provided, so they and their transitive -->
<!-- dependencies do not get promoted to direct dependencies during shading -->

<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-clients_${scala.binary.version}</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-runtime_${scala.binary.version}</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
</dependency>

<dependency>
<groupId>io.kubernetes</groupId>
<artifactId>client-java</artifactId>
<version>4.0.0</version>
<scope>compile</scope>
</dependency>

<!-- test dependencies -->

<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-test-utils-junit</artifactId>
</dependency>

</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<executions>
<execution>
<id>dependency-convergence</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<skip>true</skip>
</configuration>
</execution>
</executions>
</plugin>

<!-- Scala Compiler -->
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<executions>
<!-- Run scala compiler in the process-resources phase, so that dependencies on
scala classes can be resolved later in the (Java) compile phase -->
<execution>
<id>scala-compile-first</id>
<phase>process-resources</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>

<!-- Run scala compiler in the process-test-resources phase, so that dependencies on
scala classes can be resolved later in the (Java) test-compile phase -->
<execution>
<id>scala-test-compile</id>
<phase>process-test-resources</phase>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
<configuration>
<jvmArgs>
<jvmArg>-Xms128m</jvmArg>
<jvmArg>-Xmx512m</jvmArg>
</jvmArgs>
</configuration>
</plugin>

<!-- Eclipse Integration -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.8</version>
<configuration>
<downloadSources>true</downloadSources>
<projectnatures>
<projectnature>org.scala-ide.sdt.core.scalanature</projectnature>
<projectnature>org.eclipse.jdt.core.javanature</projectnature>
</projectnatures>
<buildcommands>
<buildcommand>org.scala-ide.sdt.core.scalabuilder</buildcommand>
</buildcommands>
<classpathContainers>
<classpathContainer>org.scala-ide.sdt.launching.SCALA_CONTAINER</classpathContainer>
<classpathContainer>org.eclipse.jdt.launching.JRE_CONTAINER</classpathContainer>
</classpathContainers>
<excludes>
<exclude>org.scala-lang:scala-library</exclude>
<exclude>org.scala-lang:scala-compiler</exclude>
</excludes>
<sourceIncludes>
<sourceInclude>**/*.scala</sourceInclude>
<sourceInclude>**/*.java</sourceInclude>
</sourceIncludes>
</configuration>
</plugin>

<!-- Adding scala source directories to build path -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.7</version>
<executions>
<!-- Add src/main/scala to eclipse build path -->
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>src/main/scala</source>
</sources>
</configuration>
</execution>
<!-- Add src/test/scala to eclipse build path -->
<execution>
<id>add-test-source</id>
<phase>generate-test-sources</phase>
<goals>
<goal>add-test-source</goal>
</goals>
<configuration>
<sources>
<source>src/test/scala</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>

<!-- Scala Code Style, most of the configuration done via plugin management -->
<plugin>
<groupId>org.scalastyle</groupId>
<artifactId>scalastyle-maven-plugin</artifactId>
<configuration>
<configLocation>${project.basedir}/../tools/maven/scalastyle-config.xml</configLocation>
</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.flink.kubernetes;

import org.apache.flink.configuration.Configuration;

/**
* Parameters that will be used in Flink on k8s cluster.
* */
public class FlinkKubernetesOptions {

private Configuration configuration;

public Configuration getConfiguration() {
return configuration;
}

public FlinkKubernetesOptions(Configuration configuration) {
this.configuration = configuration;
}
}
Loading