Flink官方架构图: Flink官网架构图 Flink集群架构主要看 运行时 的集群架构,运行时的集群架构主要由 两种 类型的 进程 构成:JobManager,只能有一个(HA情况下,可以有多个,但是 active只有一个,即一个leader,其他都是standby)TaskManager,一个或多个进程启动方式 这两种进程(JM和TM)根据不同的部署模式,启动方式不同。standalone模式 一键启停整个Flink集群(包括JM和NM)bin/start-cluster.sh bin/stop-cluster.sh 单独启动JobManager(或向现有集群添加JobManager)bin/jobmanager.sh ((start|start-foreground) [args] [webui-port])|stop|stop-all 单独启动TaskManager(或向现有集群添加TaskManager)bin/taskmanager.sh start|start-foreground|stop|stop-allFlink on K8s 准备好k8s环境及flink docker镜像 Session mode 1.启动 Kubernetes session$ ./bin/kubernetes-session.sh -Dkubernetes.cluster-id=my-first-flink-cluster 2.提交Job$ ./bin/flink run --target kubernetes-session -Dkubernetes.cluster-id=my-first-flink-cluster ./examples/streaming/TopSpeedWindowing.jar 3.删除集群$ kubectl delete deployment/my-first-flink-cluster Application Mode application mode需要将待执行的job代码打在flink镜像中: 1.基于Flink镜像制作镜像FROM flink RUN mkdir -p $FLINK_HOME/usrlib COPY /path/of/my-flink-job.jar $FLINK_HOME/usrlib/my-flink-job.jar 2.启动application mode$ ./bin/flink run-application --target kubernetes-application -Dkubernetes.cluster-id=my-first-application-cluster -Dkubernetes.container.image=custom-image-name local:///opt/flink/usrlib/my-flink-job.jar Per-job Mode 已过时,1.6中已废弃Flink on Yarn Session Mode on yarn上的session mode有两种操作:attached mode(默认),客户端提交后并不与集群断开,持续追踪集群状态;如果集群失败,client接收到error信息,如果client主动结束,client会给集群发送shut down指令。./bin/flink run -t yarn-session -Dyarn.application.id=application_XXXX_YY ./examples/streaming/TopSpeedWindowing.jardetached mode (-d or --detached),client提交后与集群分离,后续需要通过yarn命令或着重启一个flink client来结束集群。 # (0) export HADOOP_CLASSPATH export HADOOP_CLASSPATH=`hadoop classpath` # (1) Start YARN Session ./bin/yarn-session.sh --detached # (2) You can now access the Flink Web Interface through the # URL printed in the last lines of the command output, or through # the YARN ResourceManager web UI. # (3) Submit example job ./bin/flink run ./examples/streaming/TopSpeedWindowing.jar # (4) Stop YARN session (replace the application id based # on the output of the yarn-session.sh command) echo "stop" | ./bin/yarn-session.sh -id application_XXXXX_XXX Application Mode./bin/flink run-application -t yarn-application ./examples/streaming/TopSpeedWindowing.jar 启动后查看# List running job on the cluster ./bin/flink list -t yarn-application -Dyarn.application.id=application_XXXX_YY # Cancel running job ./bin/flink cancel -t yarn-application -Dyarn.application.id=application_XXXX_YY