<p>I have 2 services. Service A and Service B. They correspond to deployments dA and dB. </p>

<p>I set up my cluster and start both services/deployments. Service A is reachable from the external world. External World --> Service A &lt;--> Service B.</p>

<p>How can I scale dB (change replicaCount and run kubectl apply OR kubectl scale) from within Service A that is responding to a user request. </p>

<p>For example, if a user that is being served by Service A wants some extra resource in my app, I would like to provide that by adding an extra pod to dB. How do I do this programatically? </p>

<p>Every <code>Pod</code>, unless it opts out, has a <code>ServiceAccount</code> token injected into it, which enables it to interact with the kubernetes API according to the <code>Role</code> associated with the <code>ServiceAccount</code></p>

<p>Thus, one can use any number of kubernetes libraries -- most of which are "in cluster" aware, meaning they don't need any further configuration to know about that injected <code>ServiceAccount</code> token and how to use it -- to issue scale events against any resource the <code>ServiceAccount</code>'s <code>Role</code> is authorized to use</p>

<p>You can make it as simple or as complex as you'd like, but the tl;dr is akin to:</p>

<pre class="lang-sh prettyprint-override"><code>curl --cacert /var/run/secrets/kubernetes.io/ca.crt \
    --header "Accept: application/json" \
    --header "Authorization: Bearer $(cat /var/run/secrets/kubernetes.io/token)" \
    https://${KUBERNETES_SERVICE_HOST}:${KUBERNETES_SERVICE_PORT}/api/v1/namespaces
</code></pre>
