Kubernetes icon

Kubernetes

Interact with Kubernetes

Overview

This node allows you to run a command inside a Kubernetes pod by specifying the container image, command, and namespace. It is useful for automating tasks that require running scripts or commands in isolated environments within your Kubernetes cluster. Common scenarios include executing ad-hoc jobs, running maintenance scripts, or performing one-off data processing tasks directly from n8n workflows.

Practical examples:

  • Running a shell script in an Alpine Linux container.
  • Executing database migrations using a specific image.
  • Performing batch data transformations in a temporary pod.

Properties

Name Meaning
Image The name of the container image to use for the pod (e.g., alpine:latest).
Command The command to execute inside the container, provided as a JSON array (e.g., ["ls", "-la"]). Must be an array.
Namespace The Kubernetes namespace where the pod will be created. Defaults to default.

Output

The output is a JSON object with the following structure:

{
  "stdout": "<output of the executed command>"
}
  • stdout: Contains the standard output produced by the command executed inside the pod.

Dependencies

  • Kubernetes Cluster: You must have access to a Kubernetes cluster.
  • Credentials: Requires n8n credentials of type kubernetesCredentialsApi.
  • n8n Configuration: Ensure the Kubernetes credentials are set up in n8n.

Troubleshooting

  • No credentials got returned!
    This error occurs if the required Kubernetes credentials are not configured or cannot be found.
    Resolution: Check that you have added valid Kubernetes credentials in n8n and selected them in the node.

  • Command must be an array!
    This error appears if the "Command" property is not a valid JSON array.
    Resolution: Make sure to enter the command as a JSON array, e.g., ["echo", "hello world"].

  • Pod fails to start or run
    If the specified image does not exist or the command is invalid, the pod may fail.
    Resolution: Verify the image name and ensure the command is correct for the chosen image.

Links and References

Discussion