wangyang0918 opened a new pull request #14629:
URL: https://github.com/apache/flink/pull/14629
<!--
*Thank you very much for contributing to Apache Flink - we are happy that
you want to help us improve Flink. To help the community review your
contribution in the best possible way, please go through the checklist below,
which will get the contribution into a shape in which it can be best reviewed.*
*Please understand that we do not do this to make contributions to Flink a
hassle. In order to uphold a high standard of quality for code contributions,
while at the same time managing a large number of contributions, we need
contributors to prepare the contributions well, and give reviewers enough
contextual information for the review. Please also understand that
contributions that do not follow this guide will take longer to review and thus
typically be picked up with lower priority by the community.*
## Contribution Checklist
- Make sure that the pull request corresponds to a [JIRA
issue](https://issues.apache.org/jira/projects/FLINK/issues). Exceptions are
made for typos in JavaDoc or documentation files, which need no JIRA issue.
- Name the pull request in the form "[FLINK-XXXX] [component] Title of the
pull request", where *FLINK-XXXX* should be replaced by the actual issue
number. Skip *component* if you are unsure about which is the best component.
Typo fixes that have no associated JIRA issue should be named following
this pattern: `[hotfix] [docs] Fix typo in event time introduction` or
`[hotfix] [javadocs] Expand JavaDoc for PuncuatedWatermarkGenerator`.
- Fill out the template below to describe the changes contributed by the
pull request. That will give reviewers the context they need to do the review.
- Make sure that the change passes the automated tests, i.e., `mvn clean
verify` passes. You can set up Azure Pipelines CI to do that following [this
guide](https://cwiki.apache.org/confluence/display/FLINK/Azure+Pipelines#AzurePipelines-Tutorial:SettingupAzurePipelinesforaforkoftheFlinkrepository).
- Each pull request should address only one issue, not mix up code from
multiple issues.
- Each commit in the pull request has a meaningful commit message
(including the JIRA id)
- Once all items of the checklist are addressed, remove the above text and
this checklist, leaving only the filled out template below.
**(The sections below can be removed for hotfixes of typos)**
-->
## What is the purpose of the change
Now the native K8s integration is almost production ready. We already have
the common features for deploying a Flink cluster on K8s cluster natively.
However, compared with the current supported features[1] in
flink-on-k8s-operator and the feedback from users(ML and JIRAs), I am afraid
that we still need some advanced features.
* Init containers[2]
* Sidecar containers[3]
* Arbitrary volume(PVC, hostpath, emptyDir, ConfigMap) mount[4]
* Set owner reference for the JobManager deployment[5]
* Support customizing of containers for native kubernetes setup[6]
* Pod Affinity and Anti-affinity
* Pod Security Context
* Pod Environment Variables Reference
So this PR tries to introduce a pod template[7] for all the use cases. Users
could configure a local yaml file for JobManager/TaskManager. This will let
Flink create the JobManager/TaskManager pods with the template first, not the
empty. Of course, the Flink config options for Kubernetes[8] have high priority
and could overwrite these values.
Pod template is is a typical pod yaml. You could set arbitrary fields that
is supported by K8s directly. The following is a simple example, which add the
init container, sidecar container and volume mount.
```
apiVersion: v1
kind: Pod
metadata:
name: pod-template
spec:
initContainers:
- name: artifacts-fetcher
image: busybox
imagePullPolicy: IfNotPresent
# Use wget or other tools to get user jars from remote storage
command: ['wget',
'https://flink-debug-yiqi.oss-cn-beijing.aliyuncs.com/StateMachineExample.jar',
'-O', '/flink-artifact/myjob.jar']
volumeMounts:
- mountPath: /flink-artifact
name: flink-artifact
containers:
# Do not change the main container name
- name: flink-job-manager
volumeMounts:
- mountPath: /opt/flink/volumes/hostpath
name: flink-volume-hostpath
- mountPath: /opt/flink/usrlib
name: flink-artifact
- mountPath: /opt/flink/log
name: flink-logs
# Use sidecar container to push logs to remote storage or do some other
debugging things
- name: sidecar-log-collector
image: busybox
imagePullPolicy: IfNotPresent
args:
- tail
- -F
- /flink-log/jobmanager.log
volumeMounts:
- mountPath: /flink-log
name: flink-logs
volumes:
- name: flink-volume-hostpath
hostPath:
path: /tmp
type: Directory
- name: flink-artifact
emptyDir: {}
- name: flink-logs
emptyDir: {}
```
[1]. https://github.com/GoogleCloudPlatform/flink-on-k8s-operator#features
[2]. https://issues.apache.org/jira/browse/FLINK-15641
[3]. https://issues.apache.org/jira/browse/FLINK-15871
[4]. https://issues.apache.org/jira/browse/FLINK-15649
[5]. https://issues.apache.org/jira/browse/FLINK-20359
[6]. https://issues.apache.org/jira/browse/FLINK-20324
[7]. https://issues.apache.org/jira/browse/FLINK-15656
[8].
https://ci.apache.org/projects/flink/flink-docs-master/deployment/config.html#kubernetes
## Brief change log
* Introduce the pod template
## Verifying this change
* All the new introduced functionalities are covered by new added unit test
* Manually testing
## Does this pull request potentially affect one of the following parts:
- Dependencies (does it add or upgrade a dependency): (yes / **no**)
- The public API, i.e., is any changed class annotated with
`@Public(Evolving)`: (yes / **no**)
- The serializers: (yes / **no** / don't know)
- The runtime per-record code paths (performance sensitive): (yes / **no**
/ don't know)
- Anything that affects deployment or recovery: JobManager (and its
components), Checkpointing, Kubernetes/Yarn/Mesos, ZooKeeper: (**yes** / no /
don't know)
- The S3 file system connector: (yes / **no** / don't know)
## Documentation
- Does this pull request introduce a new feature? (**yes** / no)
- If yes, how is the feature documented? (Will add a detailed
documentation about how to use pod template in a following PR)
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]