"Cannot run program "kubectl": error=2, No such file or directory" errors in Bamboo logs
Platform Notice: Data Center - This article applies to Atlassian products on the Data Center platform.
Note that this knowledge base article was created for the Data Center version of the product. Data Center knowledge base articles for non-Data Center-specific features may also work for Server versions of the product, however they have not been tested. Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.
*Except Fisheye and Crucible
The steps outlined on this article are provided AS-IS. This means we've had reports of them working for some customers — under certain circumstances — yet are not officially supported, nor can we guarantee they'll work for your specific scenario.
You may follow through and validate them on your own non-prod environments prior to production or fall back to supported alternatives if they don't work out.
We also invite you to reach out to our Community for matters that fall beyond Atlassian's scope of support!
Summary
The <bamboo-home>/logs/atlassian-bamboo.log shows exceptions related to kubectl similar to the one below:
Cannot run program "kubectl": error=2, No such file or directory
Build plans also show the following error:
KubePreJobActionImpl: com.atlassian.buildeng.kubernetes.metrics.KubePreJobActionImpl
(java.lang.NullPointerException : )
Environment
Observed on Bamboo 8.2.5 with the Per-build Container plugin manually installed.
Diagnosis
- The following stack traces are present in the <bamboo-home>/logs/atlassian-bamboo.log file:
2022-11-30 13:09:55,873 ERROR [PluginSchedulerTask-KubernetesIsolatedDockerImpl] [KubernetesWatchdog] Exception caught and swallowed to preserve rescheduling of the task
com.atlassian.buildeng.kubernetes.KubernetesClient$KubectlException: java.io.IOException: Cannot run program "kubectl": error=2, No such file or directory
at com.atlassian.buildeng.kubernetes.KubernetesClient.executeKubectl(KubernetesClient.java:110)
at com.atlassian.buildeng.kubernetes.KubernetesClient.executeKubectlAsJson(KubernetesClient.java:82)
at com.atlassian.buildeng.kubernetes.KubernetesClient.getPodStream(KubernetesClient.java:151)
at com.atlassian.buildeng.kubernetes.KubernetesClient.getPods(KubernetesClient.java:129)
at com.atlassian.buildeng.kubernetes.KubernetesWatchdog.executeImpl(KubernetesWatchdog.java:156)
at com.atlassian.buildeng.kubernetes.KubernetesWatchdog.execute(KubernetesWatchdog.java:107)
at com.atlassian.sal.core.scheduling.TimerPluginScheduler$PluginTimerTask.run(TimerPluginScheduler.java:75)
at java.util.TimerThread.mainLoop(Timer.java:555)
at java.util.TimerThread.run(Timer.java:505)
Caused by: java.io.IOException: Cannot run program "kubectl": error=2, No such file or directory
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048)
at com.atlassian.buildeng.kubernetes.KubernetesClient.executeKubectl(KubernetesClient.java:105)
... 8 more
Caused by: java.io.IOException: error=2, No such file or directory
at java.lang.UNIXProcess.forkAndExec(Native Method)
at java.lang.UNIXProcess.<init>(UNIXProcess.java:247)
at java.lang.ProcessImpl.start(ProcessImpl.java:134)
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1029)
... 9 more
2022-11-30 13:37:20,845 ERROR [10-BAM::PlanExec:pool-12-thread-1] [ChainPluginSupportImpl] file:<bamboo-home>/caches/plugins/transformed-plugins/plugin.5572800778696711854.bamboo-kubernetes-metrics-plugin-2.72_1668542061660.jar, KubePreJobActionImpl: com.atlassian.buildeng.kubernetes.metrics.KubePreJobActionImpl: null
java.lang.NullPointerException
at java.util.concurrent.ConcurrentHashMap.putVal(ConcurrentHashMap.java:1011)
at java.util.concurrent.ConcurrentHashMap.put(ConcurrentHashMap.java:1006)
at com.atlassian.buildeng.kubernetes.metrics.KubePreJobActionImpl.execute(KubePreJobActionImpl.java:35)
at com.atlassian.bamboo.chains.ChainPluginSupportImpl.lambda$null$8(ChainPluginSupportImpl.java:212)
at com.atlassian.bamboo.chains.ChainPluginSupportImpl$1.call(ChainPluginSupportImpl.java:97)
at com.atlassian.bamboo.chains.ChainPluginSupportImpl$1.call(ChainPluginSupportImpl.java:93)
at com.atlassian.bamboo.plugin.BambooPluginUtils.callUnsafeCode(BambooPluginUtils.java:55)
at com.atlassian.bamboo.chains.ChainPluginSupportImpl.callActionFunction(ChainPluginSupportImpl.java:93)
at com.atlassian.bamboo.chains.ChainPluginSupportImpl.lambda$buildStarted$9(ChainPluginSupportImpl.java:212)
at com.atlassian.bamboo.variable.CustomVariableContextImpl.withVariableSubstitutor(CustomVariableContextImpl.java:107)
at com.atlassian.bamboo.variable.CustomVariableContextRunnerImpl.execute(CustomVariableContextRunnerImpl.java:31)
at com.atlassian.bamboo.chains.ChainPluginSupportImpl.buildStarted(ChainPluginSupportImpl.java:211)
[...]
- Some build plans might show system errors related to kubectl:
java.lang.NullPointerException
at java.base/java.util.concurrent.ConcurrentHashMap.putVal(ConcurrentHashMap.java:1011)
at java.base/java.util.concurrent.ConcurrentHashMap.put(ConcurrentHashMap.java:1006)
at com.atlassian.buildeng.kubernetes.metrics.KubePreJobActionImpl.execute(KubePreJobActionImpl.java:35)
at com.atlassian.bamboo.chains.ChainPluginSupportImpl.lambda$null$8(ChainPluginSupportImpl.java:212)
at com.atlassian.bamboo.chains.ChainPluginSupportImpl$1.call(ChainPluginSupportImpl.java:97)
at com.atlassian.bamboo.chains.ChainPluginSupportImpl$1.call(ChainPluginSupportImpl.java:93)
at com.atlassian.bamboo.plugin.BambooPluginUtils.callUnsafeCode(BambooPluginUtils.java:55)
[...]
- By accessing the Bamboo administration > Manage apps page, the Per-build Container apps are listed under the User-installed apps section:
Cause
This is caused by the Per-build Container third-party apps being installed and the Kubernetes tools not being configured.
Solution
This problem is related to a third party plugin, and therefore not supported by Atlassian. See Atlassian Supported Plugins for more information.
Configure the plugin and Kubernetes tools as per the app's official documentation, as well as define the Kubernetes Metrics configuration under Bamboo administration > Overview > PBC Kubernetes Metrics.
If the plugin is not being used, you can remove it from Bamboo by heading to Bamboo administration > Manage apps.