Debugging kubectl commands in Bamboo

Still need help?

The Atlassian Community is here for you.

Ask the community

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

Summary

This article explains how to debug the kubectl command execution in Bamboo.

Environment

  • Bamboo 9.3 and later

Diagnosis

When using Ephemeral Agents, Bamboo utilises the kubectl as an external component to interact with a Kubernetes cluster. This interaction is restricted to running the kubectl command and expecting specific output. Bamboo does not launch direct requests to the Kubernetes cluster, instead, all instructions are expected to be delivered and retrieved by kubectl. This design provides customers with the flexibility to run and update kubectl as per their needs. However, it does not allow further debugging. This guide outlines techniques to enable detailed information when invoking the kubectl command.

Solution

All the additional logs are stored in <bamboo-home>/logs/atlassian-bamboo.log.

Enable extended logging on the Ephemeral Agent class in Bamboo

This method offers a controlled way to understand Bamboo's operations and the default responses from each invocation of the kubectl command.

In Bamboo, follow the instructions on Configuring the level of logging on the Bamboo server and set the following class Logging to DEBUG or ALL, depending on the level of detail you require:

  • com.atlassian.bamboo.agent.ephemeral

After enabling the extra Log levels, execute the desired Kubernetes instructions and monitor the logs for extended log entries. Remember to restore the class's Log level to WARN after troubleshooting.

Run kubectl with verbosity enabled

Unlike running Bamboo with verbose logs only on the Ephemeral Agent's class, this method also runs the actual kubectl command with verbosity. This is typically recommended when you need to identify a failing command and want to understand the exact action Bamboo is executing and its output. Running this allows you to replicate the exact instruction to run on the command line and find a solution.

Before proceeding with this method, ensure you have followed the instructions on "Enable extended logging on the Ephemeral Agent class in Bamboo" as this is a prerequisite to use from this method.

When executed, kubectl expects the -v  property to be provided to print more detailed messages. Each selected debug level will provide more detailed logs.

Bamboo expects the kubectl command to produce formatted JSON output. Adding more verbose output to the command execution may result in unexpected outputs that will likely result in a failed execution in Bamboo. You should use the methods below only when handling edge cases where additional kubectl verbosity is necessary to investigate an infrastructure or connectivity case not appearing on the generic logs. Expect Bamboo to fail the kubectl command. Use the wrapper script with care. Feel free to extend it to consider only specific arguments if you wish to troubleshoot only a particular process.

After the troubleshooting, make sure to restore the configuration back to its original state or remove any extra verbose property flags from the wrapper script in case you decide to keep it.

There are two strategies you can follow

1. Create a wrapper script and modify the Kubernetes server Capability to use it

  • This method does not require changes to the original kubectl file on the server
  • You need to create or modify the Kubernetes/kubectl capability in Bamboo Administration >> Server Capabilities >> Add capability
  • The kubectl capability must point to a shell script wrapper hosted on the server containing the following content. For example:

    Make sure to set the executable permissions to the wrapper script
    #!/bin/bash
    /location/of/kubectl -v=9 "$@"
  • After this, Bamboo will invoke the wrapper instead of the original kubectl file. The wrapper script will append a -v=9 to every execution, forcing more verbose logs.

2. Create a wrapper script that will replace the original kubectl command

  • This method allows you to replace the original kubectl binary with the wrapper script
  • You must move the original kubectl to a new location such as kubectl.orig
  • There is no need to modify any server capabilities in Bamboo, as it will still reference the original binary location
  • The wrapper script content should be the following:

    Make sure to set the executable permissions to the wrapper script
    #!/bin/bash
    /location/of/kubectl.orig -v=9 "$@"

Last modified on Jan 7, 2025

Was this helpful?

Yes
No
Provide feedback about this article
Powered by Confluence and Scroll Viewport.