<p>Spark needs lots of resources to does its job. Kubernetes is great environment for resource management. How many Spark PODs do you run per node to have the best resource utilization? </p>

<p>Trying to run Spark Cluster on Kubernetes Cluster.</p>

<p>It depends on many factors. We need to know how much resources do you have and how much is being consumed by the pods. To do so you need to <a href="https://github.com/kubernetes-incubator/metrics-server" rel="nofollow noreferrer">setup a Metrics-server</a>.</p>

<p><a href="https://kubernetes.io/docs/tasks/debug-application-cluster/resource-metrics-pipeline/" rel="nofollow noreferrer">Metrics Server</a> is a cluster-wide aggregator of resource usage data. </p>

<p>Next step is to setup HPA.</p>

<p>The Horizontal Pod Autoscaler automatically scales the number of pods in a replication controller, deployment or replica set based on observed CPU utilization or other custom metrics. HPA normally fetches metrics from a series of aggregated APIs:</p>

<ul>
<li>metrics.k8s.io</li>
<li>custom.metrics.k8s.io</li>
<li>external.metrics.k8s.io</li>
</ul>

<p>How to make it work?</p>

<p>HPA is being supported by kubectl by default: </p>

<ul>
<li><code>kubectl create</code> - creates a new autoscaler</li>
<li><code>kubectl get hpa</code> - lists your autoscalers</li>
<li><code>kubectl describe hpa</code> - gets a detailed description of autoscalers</li>
<li><code>kubectl delete</code> - deletes an autoscaler</li>
</ul>

<p>Example:
<code>kubectl autoscale rs foo --min=2 --max=5 --cpu-percent=80</code> creates an autoscaler for replication set foo, with target CPU utilization set to 80% and the number of replicas between 2 and 5. You can and should adjust all values to your needs.</p>

<p><a href="https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands#autoscale" rel="nofollow noreferrer">Here</a> is a detailed documentation of how to use kubectl autoscale command.</p>

<p>Please let me know if you find that useful.</p>
