<p>I am trying to use VPA for autoscaling my deployed services. Due to limitation in resources in my cluster I set the min_replica option to 1. The workflow of VPA that have seen so far is that it first deletes the existing pod and then re-create the pod. This approach will cause a downtime to my services. What I want is that the VPA first create the new pod and then deletes the old pod, completely similar to the rolling updates for deployments. Is there an option or hack to reverse the flow to the desired order in my case?</p>

<p>This can be achieved by using python script or by using an IAC pipeline, you can get the metrics of the kubernetes cluster and whenever these metrics exceed a certain threshold, trigger this python code for creating new pod with the required resources and shutdown the old pod. Follow this github link for more info on <a href="https://github.com/kubernetes-client/python" rel="nofollow noreferrer">python plugin</a> for kubernetes.</p>
<p>Ansible can also be used for performing this operation. This can be achieved by triggering your ansible playbook whenever the threshold breaches a certain limit and you can specify the new sizes of the pods that need to be created. Follow this official <a href="https://docs.ansible.com/ansible/latest/collections/kubernetes/core/k8s_scale_module.html" rel="nofollow noreferrer">ansible document</a> for more information. However both these procedures involve manual analysis for selecting the desired pod size for scaling. So if you don’t want to use vertical scaling you can go for horizontal scaling.</p>
<p><strong>Note:</strong> The information is gathered from official Ansible and github pages and the urls are referred to in the post.</p>
