How to properly scale to 0 (and save costs) in EKS?

When I go to the EKS cluster, and then the compute tab, and then change the minimum/desired size to 0 for my various node groups, AWS then goes and “Terminates” all of the instances. This works for cost savings, as I’m not being charged for these instances, however what if I have an application running in EKS on those servers? Do I then need to redeploy that application?

What is the proper way to essentially “turn off” a cluster when not in use to save costs? I was hoping to just shut down the hosts rather than terminate them but the auto-scaling groups won’t let me do that, they just get recreated.

Your k8s deployments are saved in the control plane. As long as your control plane still exists ($70/mo) and your container repo still holds your images, you can redeploy by scaling above 0.

Scaling down your deployments/replica sets to zero, and deleting your node groups is effective as a cost saving measure. Don’t touch the ASGs or EC2 instances directly. It’s all managed via the EKS Node Groups.

BTW: you are aware you can have a node group that only spins up SPOT instances right? Split the instances across zones and similar types (t3/t3a, m6a/m6i/m5) and you’ll always have capacity. RI/Savings plans covers the regular node group EC2s.

Given that the control plane runs 24/7 and costs around $70/month, I don’t think there is an easy “off switch” that you are looking for.

You might consider fargate instead, as ECS has no added cost and scaling all services to zero leads to near zero cost.

Azure has a means to just shut off the cluster, I’m just looking for a way to turn off costs while not in use. There is really no solution to that?

I’m not sure if the application we run on these servers supports running on fargate, but I’ll look into it.

There is really no solution to that?

No. Likewise, Azure charges you for VMs that are shut off, AWS doesn’t. Every platform has pros/cons.

I’m not sure if the application we run on these servers supports running on fargate, but I’ll look into it.

EKS or ECS is just the control plane. Underneath they’re both just docker containers, so I’d be very surprised if you couldn’t convert it to ECS Fargate.

Are you using managed or unmanaged node groups?

You can scale down to 0 and also scale up from 0, but as other comments stated the control plane will be running 24/7 unless you destroy it.

I don’t believe there’s an EKS/AWS-native method of scaling down at a given time, but there are posts online about how people achieved it.

What is the use case for using a scale down to 0 node EKS cluster? Development environment?

Most of the time, Kubernetes is used for long term application hosting use cases, both stateful and stateless.

There are a few potential ways to scale this using KEDA or AWS’s own autoscaler for Kubernetes.

If your application is stateless and doesn’t require storage or long lasting sessions between services, Fargate is a great option to reduce costs.

If the consensus is to continue using EKS, I’d recommend evaluating the instances used and see where you can fit in Spot Instances to help reduce your cost for compute.

The beauty of Kubernetes is, the control plane manages the application deployments between the nodes via the kubelets, so regardless of what instance is backing the cluster, the control plane will scale the app per your specifications/affinities, etc. per node availability.

No, there’s no way to do that. There’s an ongoing cost for the control plane that you can’t just turn off.

You’ll be paying for the managed control plane, even without any running instances. So, about $70/month.

If you want to scale your nodes to zero, you can use a scheduling in the auto scaling group. But, again, it’s not true zero.

Your application is still deployed at that point, it just can’t run and schedule because there’s no nodes in the cluster. Once a node comes back into play, Kubernetes will start your your application back up

The control pane isn’t expensive though right? I’m more concerned about the 6 ec2 instances that are not small and their on-demand costs. I can’t just shut down the ec2 instances when not in use?

As I mentioned, the control plane is $72/month. This is either a ton or basically nothing depending on your situation lol

Edit:
The control plane is 24/7 unless you delete the cluster
Your EC2 Auto Scaling Group can be scaled down to 0 and all of your apps will fail to create pods until you scale up

As they’ve pointed out the flat cost for the cluster is about $74/month. You can shut down all the worker nodes whenever you’d like and those just get charged as normal EC2 instances. If you’re concerned about price you can always use spot instances for your dev and test clusters.

As they’ve pointed out the flat cost for the cluster is about $74/month.

Understood, we’re willing to eat that cost

You can shut down all the worker nodes whenever you’d like and those just get charged as normal EC2 instances

This is what I don’t understand how to do. This is a proof-of-concept / experimental deployment so it doesn’t need to be up anywhere near 24/7. I don’t understand how to only turn off the ec2 instances associated with this cluster. Whenever I scale them down, they terminate rather than shut off. Wouldn’t that effectively destroy any application I have running on them?

This is either a ton or basically nothing depending on your situation lol

Yea for my organization, this is not a big deal. We are really just concerned with the ~6 ec2 instances and their on-demand cost that come with our setup.

I have set the auto scaling groups’ minimum / desired scale values to 0 but that just terminates the instance. Would that not delete the application that is running on them?

I just need a way to manage ec2 costs, as this application / environment only needs to be up about 7-8 hours a day.

It would terminate all running pods, but the moment you scale up your apps again they will return to a healthy state as soon as the instances stabilize.

Just make sure you setup your PVs and PVCs correctly such that any persistent data can survive a instance termination.

Ok I think I understand. So something is saving the state of those pods at the time of scale-down, so when the underlying ec2-instances are “Terminated”, the pods - and by extension any application running on them - will still exist on scale-up?

This kinda sounds like a lift and shift situation from a VM environment. You will probably want to look at the stateful set deployment type, but be weary that this “persistent data” I mentioned normally only applies to certain directories that do NOT overlap with the application code (that will be in the container). For example, MySQL’s data directory can be persistent but the MySQL server itself will not be stored.

Depends on your application. Whether you terminate the instances or shut them down your pods still get terminated and your application goes down. If you have state that needs to be maintained then use a StatefulSet with the EBS CSI driver so when you bring your nodes back up the pods can be scheduled and use the same EBS volumes.

Scaling down EKS cluster to 0 with master nodes going down - is called destroying the cluster and recreating when needed.

Where are those stupid questions even comming from.

They’re coming from ignorance - hence the reason I’m posting here to ask a question.