Skip to content

Commit e0ed9a2

Browse files
committed
[Docs] Add local Flink cluster guide for Python, update Flink version references
1 parent 8d1728e commit e0ed9a2

3 files changed

Lines changed: 215 additions & 11 deletions

File tree

contributor-docs/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ This directory contains documentation for contributors to the Apache Beam projec
2222
- [Committer Guide](committer-guide.md): Guidelines for Beam committers regarding code review, pull request objectives, merging processes, and post-merge tasks.
2323
- [Committer Onboarding](committer-onboarding.md): A checklist for new Beam committers to set up their accounts and permissions.
2424
- [Java Dependency Upgrades](java-dependency-upgrades.md): Instructions for upgrading Java dependencies in Beam, including running linkage checkers and verification tests.
25+
- [Local Flink Python Validation](local-flink-python.md): Instructions for running Python pipelines on a local Flink standalone cluster.
2526
- [Python Tips](python-tips.md): Tips and instructions for developing the Python SDK, including environment setup, running tests, and handling dependencies.
2627
- [RC Testing Guide](rc-testing-guide.md): A guide for testing Beam Release Candidates (RCs) against downstream projects for Python, Java, and Go SDKs.
2728
- [Release Guide](release-guide.md): A comprehensive guide for the Release Manager on how to perform a Beam release, from preparation to promotion.
Lines changed: 204 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,204 @@
1+
<!--
2+
Licensed under the Apache License, Version 2.0 (the "License");
3+
you may not use this file except in compliance with the License.
4+
You may obtain a copy of the License at
5+
6+
http://www.apache.org/licenses/LICENSE-2.0
7+
8+
Unless required by applicable law or agreed to in writing, software
9+
distributed under the License is distributed on an "AS IS" BASIS,
10+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
See the License for the specific language governing permissions and
12+
limitations under the License.
13+
-->
14+
15+
# Running Python pipelines on a local Flink cluster
16+
17+
This guide describes a contributor workflow for validating Python Beam pipelines
18+
against a real local Flink standalone cluster. It is useful when embedded Flink
19+
is not enough, for example when validating streaming source behavior, checkpoint
20+
boundaries, or runner-visible job state in the Flink dashboard.
21+
22+
The commands assume a Unix shell (Linux, macOS, or WSL2 on Windows) with `curl`,
23+
`tar`, and `java` on the `PATH`.
24+
25+
* [What this setup validates](#what-this-setup-validates)
26+
* [Prerequisites](#prerequisites)
27+
* [Start a local Flink cluster](#start-a-local-flink-cluster)
28+
* [Run a Beam Python pipeline](#run-a-beam-python-pipeline)
29+
* [Troubleshooting](#troubleshooting)
30+
* [Stop the cluster](#stop-the-cluster)
31+
32+
## What this setup validates
33+
34+
This setup runs three separate processes:
35+
36+
1. A Flink standalone cluster, consisting of a JobManager and a TaskManager.
37+
1. A Beam Flink Job Server, started by the Python `FlinkRunner`.
38+
1. A Python SDK harness, using `--environment_type=LOOPBACK` for local
39+
development.
40+
41+
The Flink dashboard at `http://localhost:8081` shows the submitted Beam jobs.
42+
This is different from embedded Flink mode, where the cluster is started only
43+
for the lifetime of one job and is not useful for manual dashboard inspection.
44+
45+
## Prerequisites
46+
47+
Install or prepare the following:
48+
49+
* Docker Desktop (optional), only for the alternative method of obtaining the
50+
Flink distribution.
51+
* A Unix shell: Linux, macOS, or WSL2 on Windows.
52+
* Java 11 on the `PATH`.
53+
* A Python environment with the Beam SDK dependencies installed.
54+
* A Beam source checkout for the Python code under test.
55+
* A Flink 1.20 Job Server jar built from the same Beam checkout when validating
56+
unreleased Beam changes.
57+
58+
For a source-built Job Server jar, run this command from the Beam checkout:
59+
60+
```sh
61+
./gradlew :runners:flink:1.20:job-server:shadowJar
62+
```
63+
64+
The jar is written under:
65+
66+
```text
67+
runners/flink/1.20/job-server/build/libs/
68+
```
69+
70+
## Start a local Flink cluster
71+
72+
Use a Flink distribution whose minor version matches a Flink version supported
73+
by your Beam version. See the [Flink Version Compatibility](https://beam.apache.org/documentation/runners/flink/#flink-version-compatibility)
74+
table in the Flink Runner documentation, and confirm the exact patch version on
75+
the [Flink downloads page](https://flink.apache.org/downloads.html). This guide
76+
uses Flink 1.20.
77+
78+
Download and unpack the binary distribution:
79+
80+
```sh
81+
FLINK_VERSION=1.20.1
82+
curl -fLO "https://archive.apache.org/dist/flink/flink-${FLINK_VERSION}/flink-${FLINK_VERSION}-bin-scala_2.12.tgz"
83+
tar -xzf "flink-${FLINK_VERSION}-bin-scala_2.12.tgz" -C "$HOME"
84+
export FLINK_HOME="$HOME/flink-${FLINK_VERSION}"
85+
```
86+
87+
Ensure these settings exist in `$FLINK_HOME/conf/config.yaml`:
88+
89+
```yaml
90+
jobmanager.rpc.address: localhost
91+
rest.address: localhost
92+
taskmanager.numberOfTaskSlots: 2
93+
```
94+
95+
Start the cluster. The JobManager and TaskManager run as background daemons:
96+
97+
```sh
98+
"$FLINK_HOME/bin/start-cluster.sh"
99+
```
100+
101+
Verify that the JobManager and TaskManager are available:
102+
103+
```sh
104+
curl -fsS http://localhost:8081/overview
105+
```
106+
107+
Expected output includes one TaskManager and two slots:
108+
109+
```json
110+
{"taskmanagers":1,"slots-total":2,"slots-available":2,"jobs-running":0}
111+
```
112+
113+
You can also open the Flink dashboard in a browser:
114+
115+
```text
116+
http://localhost:8081
117+
```
118+
119+
### Alternative: extract Flink from the Docker image
120+
121+
If a direct download is not available, copy the distribution out of the Flink
122+
Docker image with `docker cp`:
123+
124+
```sh
125+
docker create --name flink-dist flink:1.20
126+
docker cp flink-dist:/opt/flink "$HOME/flink-1.20"
127+
docker rm flink-dist
128+
export FLINK_HOME="$HOME/flink-1.20"
129+
```
130+
131+
A distribution copied out of a Docker image can contain the container hostname in
132+
`conf/config.yaml`; see [Troubleshooting](#troubleshooting).
133+
134+
## Run a Beam Python pipeline
135+
136+
For local Python development, use `FlinkRunner`, point it at the standalone
137+
cluster, and use `LOOPBACK` so the Python SDK harness runs in the local process.
138+
139+
Use a source checkout on `PYTHONPATH` when validating unreleased Python changes.
140+
Set paths for your environment:
141+
142+
```sh
143+
export BEAM_CHECKOUT="$HOME/beam"
144+
export PYTHON="$HOME/beamenv/bin/python"
145+
export FLINK_JOB_SERVER_JAR="$(find "$BEAM_CHECKOUT/runners/flink/1.20/job-server/build/libs" \
146+
-name 'beam-runners-flink-1.20-job-server-*.jar' | head -n 1)"
147+
```
148+
149+
Run a small pipeline:
150+
151+
```sh
152+
printf 'to be or not to be\nbeam runs on flink\n' > /tmp/beam-flink-input.txt
153+
154+
PYTHONPATH="$BEAM_CHECKOUT/sdks/python" "$PYTHON" -m apache_beam.examples.wordcount \
155+
--runner=FlinkRunner \
156+
--flink_master=localhost:8081 \
157+
--flink_version=1.20 \
158+
--flink_job_server_jar="$FLINK_JOB_SERVER_JAR" \
159+
--environment_type=LOOPBACK \
160+
--input=/tmp/beam-flink-input.txt \
161+
--output=/tmp/beam-flink-counts
162+
```
163+
164+
For released Beam, omit `--flink_job_server_jar` and the `PYTHONPATH` prefix; the
165+
`FlinkRunner` downloads a Job Server matching `--flink_version` automatically. The
166+
source checkout and built jar are only needed to test unreleased changes.
167+
168+
Check the dashboard or REST API after the run:
169+
170+
```sh
171+
curl -fsS http://localhost:8081/jobs/overview
172+
```
173+
174+
The job should be `FINISHED`.
175+
176+
## Troubleshooting
177+
178+
If the TaskManager does not register, check `$FLINK_HOME/conf/config.yaml`.
179+
When a distribution is copied out of a Docker image, the file might contain the
180+
container hostname. Replace it with:
181+
182+
```yaml
183+
jobmanager.rpc.address: localhost
184+
```
185+
186+
If a Python job fails on native Windows with an invalid path containing `:`,
187+
run the Python driver and Job Server from WSL2. Some staged artifact names used
188+
by the portable runner are valid on Linux but invalid as native Windows file
189+
names.
190+
191+
On WSL2, keep at least one shell open in the distribution while the cluster runs.
192+
Closing the last shell can stop the distribution and its background daemons.
193+
194+
If the job starts but the Python transforms do not execute, check the
195+
environment type. `LOOPBACK` is intended for local development. For a remote
196+
or multi-machine Flink cluster, use a containerized environment instead.
197+
198+
## Stop the cluster
199+
200+
Stop the local cluster when you finish collecting results:
201+
202+
```sh
203+
"$FLINK_HOME/bin/stop-cluster.sh"
204+
```

website/www/site/content/en/documentation/runners/flink.md

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ from the [compatibility table](#flink-version-compatibility) below. For example:
9393
{{< highlight java >}}
9494
<dependency>
9595
<groupId>org.apache.beam</groupId>
96-
<artifactId>beam-runners-flink-1.18</artifactId>
96+
<artifactId>beam-runners-flink-1.20</artifactId>
9797
<version>{{< param release_latest >}}</version>
9898
</dependency>
9999
{{< /highlight >}}
@@ -166,7 +166,7 @@ If you have a Flink `JobManager` running on your local machine you can provide `
166166
To run a pipeline on Flink, set the runner to `FlinkRunner`
167167
and `flink_master` to the master URL of a Flink cluster.
168168
In addition, optionally set `environment_type` set to `LOOPBACK`. For example,
169-
after starting up a [local flink cluster](https://ci.apache.org/projects/flink/flink-docs-release-1.18/getting-started/tutorials/local_setup.html),
169+
after starting up a [local flink cluster](https://nightlies.apache.org/flink/flink-docs-release-1.20/docs/try-flink/local_installation/),
170170
one could run:
171171
{{< /paragraph >}}
172172

@@ -196,9 +196,8 @@ The optional `flink_version` option may be required as well for older versions o
196196

197197
{{< paragraph class="language-portable" >}}
198198
Starting with Beam 2.18.0, pre-built Flink Job Service Docker images are available at Docker Hub:
199-
[Flink 1.16](https://hub.docker.com/r/apache/beam_flink1.16_job_server).
200-
[Flink 1.17](https://hub.docker.com/r/apache/beam_flink1.17_job_server).
201-
[Flink 1.18](https://hub.docker.com/r/apache/beam_flink1.18_job_server).
199+
[Flink 1.19](https://hub.docker.com/r/apache/beam_flink1.19_job_server).
200+
[Flink 1.20](https://hub.docker.com/r/apache/beam_flink1.20_job_server).
202201
{{< /paragraph >}}
203202

204203
<!-- TODO(BEAM-10214): Use actual lists here and below. -->
@@ -207,7 +206,7 @@ To run a pipeline on an embedded Flink cluster:
207206
{{< /paragraph >}}
208207

209208
{{< paragraph class="language-portable" >}}
210-
(1) Start the JobService endpoint: `docker run --net=host apache/beam_flink1.18_job_server:latest`
209+
(1) Start the JobService endpoint: `docker run --net=host apache/beam_flink1.20_job_server:latest`
211210
{{< /paragraph >}}
212211

213212
{{< paragraph class="language-portable" >}}
@@ -217,7 +216,7 @@ You might encounter an error message like `Caused by: java.io.IOException: Insuf
217216
This can be resolved by providing a Flink configuration file to override the default settings.
218217
You can find an example configuration file [here](https://github.com/apache/beam/blob/master/runners/flink/src/test/resources/flink-conf.yaml).
219218
To start the Job Service endpoint with your custom configuration, mount a local directory containing your Flink configuration to the `/flink-conf` path in the Docker container and pass this as `--flink-conf-dir`:
220-
`docker run --net=host -v <your_flink_conf_dir>:/flink-conf beam-flink-runner apache/beam_flink1.18_job_server:latest --flink-conf-dir /flink-conf`
219+
`docker run --net=host -v <your_flink_conf_dir>:/flink-conf beam-flink-runner apache/beam_flink1.20_job_server:latest --flink-conf-dir /flink-conf`
221220
{{< /paragraph >}}
222221

223222
{{< paragraph class="language-portable" >}}
@@ -240,15 +239,15 @@ with beam.Pipeline(options) as p:
240239
<!-- Span implicitly ended -->
241240

242241
{{< paragraph class="language-portable" >}}
243-
To run on a separate [Flink cluster](https://ci.apache.org/projects/flink/flink-docs-release-1.18/getting-started/tutorials/local_setup.html):
242+
To run on a separate [Flink cluster](https://nightlies.apache.org/flink/flink-docs-release-1.20/docs/try-flink/local_installation/):
244243
{{< /paragraph >}}
245244

246245
{{< paragraph class="language-portable" >}}
247246
(1) Start a Flink cluster which exposes the Rest interface (e.g. `localhost:8081` by default).
248247
{{< /paragraph >}}
249248

250249
{{< paragraph class="language-portable" >}}
251-
(2) Start JobService with Flink Rest endpoint: `docker run --net=host apache/beam_flink1.18_job_server:latest --flink-master=localhost:8081`.
250+
(2) Start JobService with Flink Rest endpoint: `docker run --net=host apache/beam_flink1.20_job_server:latest --flink-master=localhost:8081`.
252251
{{< /paragraph >}}
253252

254253
{{< paragraph class="language-portable" >}}
@@ -316,8 +315,8 @@ reference.
316315
## Flink Version Compatibility
317316

318317
The Flink cluster version has to match the minor version used by the FlinkRunner.
319-
The minor version is the first two numbers in the version string, e.g. in `1.18.0` the
320-
minor version is `1.18`.
318+
The minor version is the first two numbers in the version string, e.g. in `1.20.0` the
319+
minor version is `1.20`.
321320

322321
We try to track the latest version of Apache Flink at the time of the Beam release.
323322
A Flink version is supported by Beam for the time it is supported by the Flink community.

0 commit comments

Comments
 (0)