Skip to content

Commit

Permalink
Adding source code for blog post "Get Running With Flink on Kubernete…
Browse files Browse the repository at this point in the history
…s" (#34)
  • Loading branch information
gunnarmorling authored Jan 21, 2025
1 parent 37e287d commit 15d51a5
Show file tree
Hide file tree
Showing 23 changed files with 1,590 additions and 0 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@ _Decodable provides a managed PyFlink service. Learn more [here](https://docs.de
| [Decodable CI/CD](declarative-cicd) | An example of using Decodable with GitHub Actions|
| [Decodable CLI Docker image](cli-docker) | An example Dockerfile for running the Decodable CLI under Docker.|

### Kubernetes

| Example | Description |
|-------------------------------------------------------|-------------|
| [Fink on Kubernetes](flink-on-kubernetes) | An example of running Flink via the Flink Kubernetes Operator|

## License

This code base is available under the Apache License, version 2.
5 changes: 5 additions & 0 deletions flink-on-kubernetes/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Get Running With Flink on Kubernetes

An extensive example showing how to run Flink on Kubernetes.

Touching on a range of topics such as installation and set-up, creating container images for your own Flink jobs, fault tolerance and high availability, savepoint management, observability, and more.
45 changes: 45 additions & 0 deletions flink-on-kubernetes/flink/basic.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
################################################################################
# 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.
################################################################################

apiVersion: flink.apache.org/v1beta1
kind: FlinkDeployment
metadata:
name: basic-example
spec:
image: flink:1.20-java17
flinkVersion: v1_20
flinkConfiguration:
taskmanager.numberOfTaskSlots: "2"
serviceAccount: flink
jobManager:
resource:
memory: "2048m"
cpu: 1
taskManager:
resource:
memory: "2048m"
cpu: 1
job:
jarURI: local:///opt/flink/examples/streaming/StateMachineExample.jar
parallelism: 2
upgradeMode: stateless
ingress:
template: "localhost/{{name}}(/|$)(.*)"
className: "nginx"
annotations:
nginx.ingress.kubernetes.io/rewrite-target: "/$2"
70 changes: 70 additions & 0 deletions flink-on-kubernetes/flink/custom-job-ha.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
################################################################################
# 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.
################################################################################

apiVersion: flink.apache.org/v1beta1
kind: FlinkDeployment
metadata:
name: custom-job-ha
spec:
image: decodable-examples/hello-world-job:1.0
flinkVersion: v1_20
flinkConfiguration:
taskmanager.numberOfTaskSlots: "2"

s3.access.key: minio
s3.secret.key: minio123
s3.endpoint: http://minio-service.default.svc.cluster.local:9000
s3.path.style.access: "true"
s3.entropy.key: _entropy_
s3.entropy.length: "4"

execution.checkpointing.interval: "5000"

state.backend: rocksdb
state.backend.incremental: "true"
state.checkpoints.dir: s3://flink-data/_entropy_/checkpoints
state.savepoints.dir: s3://flink-data/savepoints

high-availability.type: kubernetes
high-availability.storageDir: s3://flink-data/ha
serviceAccount: flink
jobManager:
resource:
memory: "2048m"
cpu: 1
taskManager:
resource:
memory: "2048m"
cpu: 1
podTemplate:
spec:
containers:
- name: flink-main-container
env:
- name: ENABLE_BUILT_IN_PLUGINS
value: "flink-s3-fs-presto-1.20.0.jar"
job:
jarURI: local:///opt/flink-jobs/hello-world-job-1.0.jar
parallelism: 2
upgradeMode: savepoint
state: running
ingress:
template: "localhost/{{name}}(/|$)(.*)"
className: "nginx"
annotations:
nginx.ingress.kubernetes.io/rewrite-target: "/$2"
70 changes: 70 additions & 0 deletions flink-on-kubernetes/flink/custom-job-s3.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
################################################################################
# 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.
################################################################################

apiVersion: flink.apache.org/v1beta1
kind: FlinkDeployment
metadata:
name: custom-job-s3
spec:
image: decodable-examples/hello-world-job:1.0
flinkVersion: v1_20
flinkConfiguration:
taskmanager.numberOfTaskSlots: "2"

s3.access.key: minio
s3.secret.key: minio123
s3.endpoint: http://minio-service.default.svc.cluster.local:9000
s3.path.style.access: "true"
s3.entropy.key: _entropy_
s3.entropy.length: "4"

execution.checkpointing.interval: "5000"

state.backend: rocksdb
state.backend.incremental: "true"
state.checkpoints.dir: s3://flink-data/_entropy_/checkpoints
state.savepoints.dir: s3://flink-data/savepoints

high-availability.type: kubernetes
high-availability.storageDir: s3://flink-data/ha
serviceAccount: flink
jobManager:
resource:
memory: "2048m"
cpu: 2
taskManager:
resource:
memory: "2048m"
cpu: 2
podTemplate:
spec:
containers:
- name: flink-main-container
env:
- name: ENABLE_BUILT_IN_PLUGINS
value: "flink-s3-fs-presto-1.20.0.jar"
job:
jarURI: s3://job-files/hello-world-job-1.0.jar
parallelism: 2
upgradeMode: savepoint
state: running
ingress:
template: "localhost/{{name}}(/|$)(.*)"
className: "nginx"
annotations:
nginx.ingress.kubernetes.io/rewrite-target: "/$2"
45 changes: 45 additions & 0 deletions flink-on-kubernetes/flink/custom-job.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
################################################################################
# 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.
################################################################################

apiVersion: flink.apache.org/v1beta1
kind: FlinkDeployment
metadata:
name: custom-job
spec:
image: decodable-examples/hello-world-job:1.0
flinkVersion: v1_20
flinkConfiguration:
taskmanager.numberOfTaskSlots: "2"
serviceAccount: flink
jobManager:
resource:
memory: "2048m"
cpu: 1
taskManager:
resource:
memory: "2048m"
cpu: 1
job:
jarURI: local:///opt/flink-jobs/hello-world-job-1.0.jar
parallelism: 1
upgradeMode: stateless
ingress:
template: "localhost/{{name}}(/|$)(.*)"
className: "nginx"
annotations:
nginx.ingress.kubernetes.io/rewrite-target: "/$2"
111 changes: 111 additions & 0 deletions flink-on-kubernetes/flink/logging-job.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
################################################################################
# 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.
################################################################################

apiVersion: flink.apache.org/v1beta1
kind: FlinkDeployment
metadata:
name: logging-job
spec:
image: decodable-examples/hello-world-job:1.0
flinkVersion: v1_20
flinkConfiguration:
taskmanager.numberOfTaskSlots: "2"
serviceAccount: flink
jobManager:
resource:
memory: "2048m"
cpu: 1
taskManager:
resource:
memory: "2048m"
cpu: 1
job:
jarURI: local:///opt/flink/examples/streaming/StateMachineExample.jar
parallelism: 2
upgradeMode: stateless
logConfiguration:
log4j-console.properties: |+
################################################################################
# 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.
################################################################################
# This affects logging for both user code and Flink
rootLogger.level = INFO
rootLogger.appenderRef.console.ref = ConsoleAppender
rootLogger.appenderRef.rolling.ref = RollingFileAppender
# Uncomment this if you want to _only_ change Flink's logging
#logger.flink.name = org.apache.flink
#logger.flink.level = INFO
# The following lines keep the log level of common libraries/connectors on
# log level INFO. The root logger does not override this. You have to manually
# change the log levels here.
logger.akka.name = akka
logger.akka.level = INFO
logger.kafka.name= org.apache.kafka
logger.kafka.level = INFO
logger.hadoop.name = org.apache.hadoop
logger.hadoop.level = INFO
logger.zookeeper.name = org.apache.zookeeper
logger.zookeeper.level = INFO
# Log all infos to the console
appender.console.name = ConsoleAppender
appender.console.type = CONSOLE
appender.console.layout.type = JsonTemplateLayout
# Log all infos in the given rolling file
appender.rolling.name = RollingFileAppender
appender.rolling.type = RollingFile
appender.rolling.append = false
appender.rolling.fileName = ${sys:log.file}
appender.rolling.filePattern = ${sys:log.file}.%i
appender.rolling.layout.type = PatternLayout
appender.rolling.layout.pattern = %d{yyyy-MM-dd HH:mm:ss,SSS} %-5p %-60c %x - %m%n
appender.rolling.policies.type = Policies
appender.rolling.policies.size.type = SizeBasedTriggeringPolicy
appender.rolling.policies.size.size=100MB
appender.rolling.strategy.type = DefaultRolloverStrategy
appender.rolling.strategy.max = 10
# Suppress the irrelevant (wrong) warnings from the Netty channel handler
logger.netty.name = org.apache.flink.shaded.akka.org.jboss.netty.channel.DefaultChannelPipeline
logger.netty.level = OFF
# The monitor interval in seconds to enable log4j automatic reconfiguration
# monitorInterval = 30
ingress:
template: "localhost/{{name}}(/|$)(.*)"
className: "nginx"
annotations:
nginx.ingress.kubernetes.io/rewrite-target: "/$2"
10 changes: 10 additions & 0 deletions flink-on-kubernetes/flink/savepoint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
apiVersion: flink.apache.org/v1beta1
kind: FlinkStateSnapshot
metadata:
name: example-savepoint
spec:
backoffLimit: 1
jobReference:
kind: FlinkDeployment
name: custom-job-ha
savepoint: {}
Loading

0 comments on commit 15d51a5

Please sign in to comment.