apache flink kubernetes 运行试用

类似docker-compose 运行模式,使用的是deploy 的模式

deploy yaml 文件

deploy-k8s-yaml
apiVersion: extensions/v1beta1
kind: Deployment
metadata:  
  name: jobmanager
  namespace: big-data
  labels:
    app: jobmanager
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: jobmanager
    spec:
      containers:
      - name: jobmanager
        image: flink
        imagePullPolicy: IfNotPresent
        ports:
        - containerPort: 6123
        - containerPort: 8081
        args: ["jobmanager"]
        env:
        - name: JOB_MANAGER_RPC_ADDRESS
          value: jobmanager

---

# 暴露service 方便taskmanager 连接
 apiVersion: v1
kind: Service
metadata:
  name: jobmanager
  namespace: big-data
  labels:
    app: jobmanager
spec:
  type: NodePort
  ports:
  - port: 8081
    targetPort: 8081
    protocol: TCP
    name: http
  - port: 6123
    targetPort: 6123
    protocol: TCP
    name: rpc
  - port: 6124
    targetPort: 6124
    protocol: TCP
    name: blob
  - port: 6125
    targetPort: 6125
    protocol: TCP
    name: query
  selector:
    app: jobmanager
---

# 访问地址使用ingress
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: jobmanager
  namespace: big-data
spec:
  rules:
  - host: flink.data.com
    http:
      paths:
      - backend:
          serviceName: jobmanager
          servicePort: 8081
        path: /

---

apiVersion: extensions/v1beta1
kind: Deployment
metadata:  
  name: taskmanager
  namespace: big-data
  labels:
    app: taskmanager
spec:
  replicas: 3
  template:
    metadata:
      labels:
        app: taskmanager
    spec:
      containers:
      - name: taskmanager
        image: flink
        imagePullPolicy: IfNotPresent
        ports:
        - containerPort: 6121
        - containerPort: 6122
        args: ["taskmanager"]
        env:
        - name: JOB_MANAGER_RPC_ADDRESS
          value: jobmanager

部署

kubectl apply -f  deploy-k8s-yaml

访问

简单batchjob demo

具体代码参考 https://github.com/rongfengliang/flink-docker-compose-demo/tree/master/flink-app

运行效果




参考资料

https://github.com/rongfengliang/flink-docker-compose-demo
https://github.com/apache/flink/tree/master/flink-examples/flink-examples-batch/src/main/java/org/apache/flink/examples/java/wordcount

posted on 2018-08-29 13:43  荣锋亮  阅读(2745)  评论(0编辑  收藏  举报

导航