Execute Kubectl Command

Overview

The Execute Kubectl Command action allows users to execute Kubernetes commands (kubectl) on a specified Kubernetes cluster. This action is ideal for performing various Kubernetes management tasks, such as querying resources, applying changes, and monitoring deployments directly from the bot workflow.

Prerequisites

  • kubectl CLI installed on the Linux agent. For installation instructions, refer to the kubectl CLI Installation Guide.
  • Access to the target Kubernetes cluster.

How to Use This Action?

To use the Execute Kubectl Command action, follow these steps:

  • In your bot workflow, navigate to Kubernetes Actions under the Library section.

    Navigate to Kubernetes Action

  • Search for Execute Kubectl Command and drag it into your workflow.

  • Select the Kubernetes integration that is connected to the agent for executing kubectl commands.

  • Under the Parameters section, specify the required parameter values. For details on additional parameters, refer to the Parameter Details section.

  • Provide the following parameters:

    • kubectl_command: The main kubectl command to execute. This parameter is required and supports commands like get, apply, delete, and more. JSON output will be added automatically for supported commands.
    • kubeconfig_path: Optional. Provide this only if the Kubernetes configuration file is stored at a custom location other than the default path (~/.kube). If not specified, the default location will be used.
  • Manual Entry: You can enter the kubectl_command manually by typing in the command you wish to execute.

    Manual Entry Screenshot

  • AI Assistance: Alternatively, use AI assistance to receive command suggestions based on your input.

    AI Assistance Screenshot

  • Save or update the bot, then click on Run to execute the bot. View the results in the execution details to confirm successful execution or troubleshoot if there are any errors.

Parameter Details

ParameterRequiredDescription
kubectl_commandYesSpecifies the kubectl command to execute. Ensure the command is valid and follows kubectl <subcommand>. JSON output is automatically added if supported.
kubeconfig_pathNoPath to the Kubernetes configuration file on the agent, if different from the default (~/.kube).
run_as_userYesThe user under which the command will execute (default is ubuntu).
execution_timeoutYesMaximum allowed time (in seconds) for command execution (default is 120).

Example Use Case

Scenario: Retrieve Pods Information

Suppose you need to retrieve information about all running pods in a specific namespace for monitoring or troubleshooting. Using the Execute Kubectl Command action, you can execute the following command:

Sample kubectl_command:

kubectl get pods -n my-namespace