<p>I have below small python script </p>

<pre><code>import os
os.system('kubectl get pods --context students-cmn')
</code></pre>

<p>when i run this command manually from terminal it is working , no issue , so i configured it to run as a cron job , but when cron job triggered getting below error </p>

<pre><code>sh: kubectl: command not found
</code></pre>

<p>why , when the cronjob triggered , kubectl not working ?</p>

<p>can anyone please help </p>

Bravo
<p>First of all, I imagine you are planning on adding code to your python script and that that is why you use python. I assume you used the crontab of the user that can run the command.</p>

<p>When you execute a command in <code>cron</code> you must specify the full path to the command. To find the full path to <code>kubectl</code>, you issue the following in Terminal:</p>

<pre><code>which kubectl
</code></pre>

<p>It will print the full path.</p>

<p>Then, you edit your script (assuming the full path is "/opt/Kubernetes/bin"):</p>

<pre><code>import os
os.system('/opt/Kubernetes/bin/kubectl get pods --context students-cmn')
</code></pre>
