<p>Is it possible to trigger Pub/Sub event or Google Cloud Function in the GCloud, when my Node pool is auto-scaling under high performance conditions?</p>
<p>Or is there any other analytics event which can be used to trigger Cloud Function?</p>

<p>You can be notified (in Pub/Sub) when a node pool is scaled up by setting a <a href="https://cloud.google.com/logging/docs/export" rel="nofollow noreferrer">sink on Stackdriver logs</a>, with a Pub/Sub topic as destination.</p>
<p>You have to listen to specific logs corresponding to the scale up of your node pool. There are 2 filters you can use for your sink. Any message corresponding to one of these filter will be sent to a Pub/Sub topic, meaning that you can then have a Cloud Function triggered when a message is published in that topic.</p>
<h3>Filter on instance group</h3>
<p>You can use this filter on instance group (a GKE node pool is in fact a managed instance group of Compute VMs) :</p>
<pre><code>resource.type=&quot;gce_instance_group_manager&quot; AND
resource.labels.instance_group_manager_name:&quot;gke-&lt;cluster_name&gt;-default-pool&quot; AND
protoPayload.methodName=&quot;v1.compute.instanceGroupManagers.resize&quot; AND
operation.last=&quot;true&quot;
</code></pre>
<p>(please replace <code>&lt;cluster_name&gt;</code> with the name of your cluster, and <code>&lt;node_pool_name&gt;</code> with the node pool name, like <code>default-pool</code>).</p>
<h3>Filter on cluster autoscaler logs</h3>
<p>You can also use this filter :</p>
<pre><code>resource.type=&quot;k8s_cluster&quot; AND
logName=&quot;projects/&lt;project_id&gt;/logs/container.googleapis.com%2Fcluster-autoscaler-visibility&quot; AND
jsonPayload.decision.scaleUp.increasedMigs.mig.nodepool=&quot;&lt;node_pool_name&gt;&quot;
</code></pre>
<p>(please replace <code>&lt;project_id&gt;</code> with the id of your project, and <code>&lt;node_pool_name&gt;</code> to the node pool name, like <code>default-pool</code>).</p>
<p>What's interesting with this filter is that you can know which pod have caused the scale up, and how many nodes have been added, by looking inside the <code>jsonPayload</code> :</p>
<pre><code>jsonPayload: {
    decision: {
        eventId: &quot;41ddc559-c616-4068-8ba2-2f26eadcc7bd&quot;
        decideTime: &quot;1620897027&quot;
        scaleUp: {
            increasedMigs: [
                0: {
                    mig: {
                        name: &quot;gke-&lt;cluster_name&gt;-&lt;node_pool_name&gt;-xxxxxxxx-grp&quot;
                        nodepool: &quot;&lt;node_pool_name&gt;&quot;
                        zone: &quot;&lt;zone&gt;&quot;
                    }
                    requestedNodes: 1
                }
            ]
            triggeringPods: [
                0: {
                    name: &quot;&lt;pod_name_causing_the_scale_up&gt;&quot;
                    namespace: &quot;&lt;pod_namespace&gt;&quot;
                }
            ]
            triggeringPodsTotalCount: 1
        }
    }
}
</code></pre>
