Hi everybody! I'm a Flink newbie! I am deploying ...
# troubleshooting
j
Hi everybody! I'm a Flink newbie! I am deploying the Flink stateful app using the below-mentioned YAML file. (I'm using the Flink Kubernetes Operator)
Copy code
apiVersion: flink.apache.org/v1beta1
kind: FlinkDeployment
metadata:
  name: basic
spec:
  image: flink:1.17
  flinkVersion: v1_17
  ingress:
    template: "{{name}}.{{namespace}}.flink.k8s.io"
    className: "nginx"
    annotations:
      nginx.ingress.kubernetes.io/proxy-body-size: 50m
  flinkConfiguration:
    taskmanager.numberOfTaskSlots: "1"
  serviceAccount: flink
  jobManager:
    resource:
      memory: "1024m"
      cpu: 1
  taskManager:
    replicas: 1
    resource:
      memory: "1024m"
      cpu: 1
Flink Jobs are running perfectly. For auto-scaling I created HPA using the following code.
Copy code
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
  name: basic-hpa
  namespace: default
spec:
  minReplicas: 1
  maxReplicas: 3
  metrics:
  - type: Resource
    resource:
      name: cpu
      target:
        type: Utilization
        averageValue: 40
  scaleTargetRef:
    apiVersion: flink.apache.org/v1beta1
    kind: FlinkDeployment
    name: basic
While describing the auto scaling I am getting below mentioned error.
Copy code
Events:
  Type     Reason                        Age                    From                       Message
  ----     ------                        ----                   ----                       -------
  Warning  FailedComputeMetricsReplicas  6m23s (x12 over 9m8s)  horizontal-pod-autoscaler  selector is required
  Warning  SelectorRequired              4m8s (x21 over 9m8s)   horizontal-pod-autoscaler  selector is required`
And when doing a "kubectl describe hpa simple-flink" I get the following status info:
Copy code
status:
  conditions:
  - lastTransitionTime: "2023-12-19T13:42:00Z"
    message: the HPA controller was able to get the target's current scale
    reason: SucceededGetScale
    status: "True"
    type: AbleToScale
  - lastTransitionTime: "2023-12-19T13:42:00Z"
    message: the HPA target's scale is missing a selector
    reason: InvalidSelector
    status: "False"
    type: ScalingActive`
I've tried as suggested in this other thread: https://stackoverflow.com/questions/73075996/flink-kubernetes-deployment-the-hpa-controller-was-unable-to-get-the-targets to execute the following to update the CRD to the last version:
Copy code
git clone https://github.com/apache/flink-kubernetes-operator
cd flink-kubernetes-operator
kubectl replace -f helm/flink-kubernetes-operator/crds/flinkdeployments.flink.apache.org-v1.yml
After that I recreated the deployment and the HPA but I get the same error. I'm not sure if HPA is supported with the flink-kubernetes-operator. Thanks a lot for any suggestion on how to fix this problem
g
HPA is not supported for the defaul native deployment mode. But I think you are better off without it and instead try the much more advanced autoscaler functionality built directly into the operator
So basically, remove the HPA and enable the autoscaler instead 馃檪
thank me later 馃槃
j
Dear Gyula, thank you very much for your response!!!! I was very lost with this. I read the documentation several times last week, but I haven't really understood whether the built-in autoscaler functionality will start TaskManager pods or make the TaskManagers run all the time and adjust the speed at which they run (the comment about back pressure). That's why I thought of using HPA first, but if I can achieve the same with the autoscaler, i.e. I would like to start for example a maximum of 10 TaskManager pods when there is high load and none when there is no load that would be great. Thank you very much again!!
g
In the native mode , task managers are started on demand depending on the parallelism set by the autoscaler
You can simply set the max vertex parallelism in the autoscaler configuration to limit the maximum scale up
j
Thanks a lot! I'll try it!!
Hi! I've tried this configuration to limit the amount of taksManagers to run to 1. In a side note I'm using a Session cluster configuration (I'd like to have one job manager and submit many jobs to it)
Copy code
flinkConfiguration:
    parallelism.default: "1"
    taskmanager.numberOfTaskSlots: "1"
    state.savepoints.dir: file:///flink-data/savepoints
    state.checkpoints.dir: file:///flink-data/checkpoints
    high-availability.type: kubernetes
    high-availability.storageDir: file:///flink-data/ha
    rest.client-max-content-length: "1004857600"
    job.autoscaler.enabled: "true"
    job.autoscaler.stabilization.interval: 1m
    job.autoscaler.metrics.window: 1m
    job.autoscaler.target.utilization: "0.7"
    job.autoscaler.target.utilization.boundary: "0.2"
    job.autoscaler.restart.time: 2m
    job.autoscaler.catch-up.duration: 5m
    pipeline.max-parallelism: "1"
Then I tried to run this job using a parallelism of 6
Copy code
./bin/flink run --jobmanager flink.default.flink.k8s.io:80 -pyexec python3 -p6 -pyclientexec python3 --python ./original/python/table/basic_operations.py
But I expected that I get only one task manager running but I got 6 instead of the expected 1.
Copy code
NAME                                         READY   STATUS    RESTARTS   AGE
flink-68476b87dd-29bpq               1/1     Running   0          34m
flink-taskmanager-1-10               1/1     Running   0          8s
flink-taskmanager-1-11               1/1     Running   0          8s
flink-taskmanager-1-12               1/1     Running   0          8s
flink-taskmanager-1-7                1/1     Running   0          8s
flink-taskmanager-1-8                1/1     Running   0          8s
flink-taskmanager-1-9                1/1     Running   0          8s
What I'd like is to limit the amount of taskManagers to a fixed max amount even if the jobs sent to the jobmanager set different parallelisms to avoid exceding the resource limits of the Kubernetes namespace. Thanks for any advice! 馃榾
g
The autoscaler doesn鈥檛 work for session clusters
It works on the job level but also that a completely different question . You have a very specific number of TMs in mind
This is not a very common setup
I am not sure if you can limit the number of TMs in native mode
In that case the cluster is fully elastic, as new jobs come in new TMs are started
You can check the config page maybe there is a limit setting
The alternative is to use standalone mode where the number of replicas is controlled by you fully
The autoscaler is not really a good fit in this particular setup unfortunately
j
Excellent!! Thanks a lot for your responses, it gives me a path to follow. I really appreciate the time you've used in giving me guidance. 馃榾