<p>In kubernetes, if I desired to have pods for a specific task not always required is it possible to have the system spin pods up for a given task when needed? Can this be managed through the backend code (in my instance python)? Do services need to be defined in a certain way in advance?</p>
<p>I found an api for docker management in <a href="https://docker-py.readthedocs.io/en/stable/" rel="nofollow noreferrer">Python</a>, would this work for Kubernetes?</p>

<p>If i have understood correctly you want to run the PODs when required not all the time.</p>
<p>in that case you can use the python client library of Kubernetes and manage the PODs or replicas of deployment.</p>
<p>you can deploy your service with replica count zero and once required you can scale up the pods using the client to as much required.</p>
<p>Kubernetes python client: <a href="https://github.com/kubernetes-client/python" rel="nofollow noreferrer">https://github.com/kubernetes-client/python</a></p>
<p>if your service is already running you can use this API :</p>
<pre><code>GET /apis/extensions/v1beta1/namespaces/{namespace}/deployments/{name}/scale
</code></pre>
<p>here using just curl also you can spin up the replicas</p>
<pre><code>API_URL=&quot;http://kubernetes:8080/apis/extensions/v1beta1/namespaces/{namespace}/deployments/{name}/scale&quot;
curl  -H 'Accept: application/json' $API_URL &gt; scale.json
# edit scale.json
curl -X PUT -d@scale.json -H 'Content-Type: application/json' $API_URL
</code></pre>
