Hi Team, I was using the terraform-aws-metaflow to...
# ask-metaflow
g
Hi Team, I was using the terraform-aws-metaflow to deploy eks clusters. I found there is no horizontal pod autoscaler in aws. In order to have eks autoscale pods for the metaflow deployment, is there a way/document we can have the metaflow scripts running on eks and enable the hpa on eks automatically? Thank you!
✅ 1
I use @kubernetes decorator but it seems not having any parameters to enable hpa when it runs on eks remotely. Will we support it in the future?
a
@great-computer-6335 - HPA is used for scaling out services. when you use @kubernetes - we run a pod that runs till completion - there isn't any utility for HPA there. Maybe I am misunderstanding your question?
g
@ancient-application-36103 thank you for your reply! My understanding is that the hpa has to target to specific deployment. So once the metaflow script runs as a deployment, we need to enable the hpa on eks. I guess under the hood, metaflow framework runs a metaflow script as deployment in a pod through calling eks api, so why can't we enable hpa at the same time when metaflow calls eks api to run the script in a pod/deployment? I mean metaflow framework probably should support this by allowing users to specify a parameter when run the script. I am super new to metaflow, let me know if my understanding is correct, thank you!
s
@great-computer-6335 metaflow runs your task as individual pods and not deployments
the resources made available to that task are governed by the attributes of the @kubernetes decorator
Copy code
from metaflow import FlowSpec, step, kubernetes

class ForeachFlow(FlowSpec):

    @step
    def start(self):
        self.titles = ['Stranger Things',
                       'House of Cards',
                       'Narcos']
        self.next(self.a, foreach='titles')

    @kubernetes(cpu=2, gpu=1)
    @step
    def a(self):
        self.title = '%s processed' % self.input
        self.next(self.join)

    @step
    def join(self, inputs):
        self.results = [input.title for input in inputs]
        self.next(self.end)

    @step
    def end(self):
        print('\n'.join(self.results))

if __name__ == '__main__':
    ForeachFlow()
in this example - we will run 3 pods for step a and each pod will get 2 vCPU shares and 1 GPU
g
So do you mean we can specify how many pods we can run for that script through specifying the number of cpu and gpu?
s
number of pods are controlled by the
foreach
attribute
g
I see
s
this line in
def start
-
self.next(self.a, foreach='titles')
- instructs metaflow to launch a pod for every element in title
g
Got it, thanks! Does that mean we cannot dynamically scale up and down for the script we run?
because we specify the #of pods statically in the script upfront
a
the number of pods are dynamic
self.titles can be the output of any function
g
hmm, but that is defined in the script, right?
I mean can we have the eks scale up and down based on the pod utilization?
a
you could do -
Copy code
from metaflow import FlowSpec, step, kubernetes, parameter

class ForeachFlow(FlowSpec):
    num_titles = Parameter(num_titles)
    @step
    def start(self):
        self.titles = range(num_titles)
        self.next(self.a, foreach='titles')

    @kubernetes(cpu=2, gpu=1)
    @step
    def a(self):
        self.title = '%s processed' % self.input
        self.next(self.join)

    @step
    def join(self, inputs):
        self.results = [input.title for input in inputs]
        self.next(self.end)

    @step
    def end(self):
        print('\n'.join(self.results))

if __name__ == '__main__':
    ForeachFlow()
yes, you can auto scale your cluster
you can use any autoscaler - karpenter etc. to autoscale - metaflow will happily submit pods, the autoscaler will bring in new nodes and take them away when the tasks have finished execution
g
yeah, the autoscaler will bring more nodes for scaling up, but HPA is for scaling up on pods level. So what we wanted is HPA 🙂
a
metaflow takes care of that
HPA applies to services, not batch workloads 🙂
metaflow is submitting batch workloads on your behalf - and you can submit as many as you would want.
g
You mean "services" is like metaflow service we installed on eks?
I kind of understand what you meant now
a
correct!
g
When we check the aws eks cluster, the HPA page shows nothing, is that normal?
I assume it should show something if HPA is enabled for the "services"
a
you would have to enable it for the services
i am not too familiar with the HPA page - is this in the aws ui?
g
yeah
It is under Resource of the EKS cluster page
I tried kubectl CLI and there is no HPA returned either
a
Hmm yeah I am not sure how that page works. Applying HPA to metaflow service should be similar to any other service..
g
Do you mean we have to manually apply HPA to the metaflow service after the cluster is setup?
It would be great if the terraform-aws-eks template has that 🙂
a
the terraform template is a starter template and is not intended to cover all varieties of deployment. we usually recommend folks to write their own templates taking inspiration from the current template
g
That sounds fair.
Btw, you mentioned we cannot scale the pods level for batch workload, what if the number of pods which run the script is not sufficient? Shouldn't eks scale up more pods for the script by HPA?
Maybe a dumb question, but just curious 🙂
a
with metaflow you can submit thousands (and millions) of pods
g
E.g. clients specify 1 pod to run a script but it is actually not enough, the job then fails and the client has to specify more pods in the script and re-run, right?
a
depends - you can scale up as well as scale out
g
OK. I will take a look. Thank you!
a
no problem! let us know if you have any more questions!
👍 1