<p>How can I properly kill celery tasks running on containers inside a kubernetes environment? The structure of the whole application (all written in Python) is as follows:</p>
<ol>
<li><p>A SDK that makes requests to our API;</p>
</li>
<li><p>A Kubernetes structure with one pod running the API and other pods running celery containers to deal with some long-running tasks that can be triggered by the API. These celery containers autoscale.</p>
</li>
</ol>
<p>Suppose we call a SDK method that in turn makes a request to the API that triggers a task to be run on a celery container. What would be the correct/graceful way to kill this task if need be? I am aware that celery tasks have a <code>revoke()</code> method, but I tried using this approach and it did not work, even using <code>terminate=True</code> and <code>signal=signal.SIGKILL</code> (maybe this has something to do with the fact that I am using Azure Service Bus as a broker?)</p>
<p>Perhaps a mapping between a celery task and its corresponding container name would help, but I could not find a way to get this information as well.</p>
<p>Any help and/or ideas would be deeply appreciated.</p>

pfreire
<p>The solution I found was to write to file shared by both API and Celery containers. In this file, whenever an interruption is captured, a flag is set to <code>true</code>. Inside the celery containers I keep periodically checking the contents of such file. If the flag is set to <code>true</code>, then I gracefully clear things up and raise an error.</p>
