Kubernetes icon

Kubernetes

Interact with Kubernetes

Overview

This node enables interaction with Kubernetes clusters, specifically allowing users to run a CronJob by creating and executing a pod based on a specified container image and command. It is useful in scenarios where you want to programmatically trigger a Kubernetes CronJob or test its execution without waiting for the scheduled time.

For example, you can use this node to:

  • Run a CronJob immediately to verify its behavior.
  • Execute a specific command inside a new pod created from a given image within a namespace.
  • Automate running batch jobs or scripts on demand in your Kubernetes environment.

Properties

Name Meaning
Image The container image to use when running the pod (e.g., nginx:latest).
Command A JSON array representing the command and arguments to execute inside the container.
Namespace The Kubernetes namespace where the CronJob/pod will be run. Defaults to "default".
Resource Name The name of the specific resource (CronJob) to target. Optional but used for filtering.

Output

The node outputs JSON data containing the standard output (stdout) from the pod that was run. This output reflects the result of executing the specified command inside the container image.

The structure of the output JSON is an array of objects, each representing the execution result for an input item, for example:

[
  {
    "stdout": "<command output here>"
  }
]

No binary data output is produced by this operation.

Dependencies

  • Requires valid Kubernetes API credentials configured in n8n to authenticate and interact with the cluster.
  • Depends on the Kubernetes client utility bundled as K8SClient for managing API calls.
  • The node expects the Kubernetes cluster to allow pod creation and execution in the specified namespace.

Troubleshooting

  • Error: "No credentials got returned!"
    This indicates missing or invalid Kubernetes API credentials. Ensure you have properly set up and selected the required API authentication token or key in n8n credentials.

  • Error: "Command must be an array!"
    The Command property must be a valid JSON array. Check that the command is formatted correctly, e.g., ["/bin/sh", "-c", "echo Hello"].

  • Pod creation or execution failures
    These may occur due to insufficient permissions, incorrect namespace, or invalid image names. Verify that the Kubernetes user has rights to create pods and that the image exists and is accessible.

  • Empty or no output
    If the command produces no output, the stdout field will be empty. Confirm the command runs correctly inside the container image manually if needed.

Links and References

Discussion