Kubernetes icon

Kubernetes

Interact with Kubernetes

Overview

This node allows you to interact with Kubernetes resources programmatically within an n8n workflow. Specifically, the Run operation on the Deployments resource lets you execute a containerized command by running a pod with a specified image and command inside a given namespace.

Common scenarios where this node is beneficial include:

  • Running one-off jobs or scripts inside a Kubernetes cluster without manually creating pods.
  • Automating deployment tasks that require executing commands in a container environment.
  • Testing container images by running commands dynamically.

For example, you could use this node to run a diagnostic script inside a Kubernetes cluster by specifying the container image and command to execute, then capturing the output for further processing.

Properties

Name Meaning
Image The container image to use when running the pod (e.g., nginx:latest, python:3.9).
Command The command to run inside the container, provided as a JSON array of strings (e.g., ["ls", "-la"]). Must be an array.
Namespace The Kubernetes namespace where the pod will be created and run. Defaults to "default".
Resource Name The name of the specific Kubernetes resource (deployment) to target.

Output

The node outputs JSON data containing the standard output (stdout) from the executed pod command. This output represents the result of running the specified command inside the container.

Example output structure:

{
  "stdout": "<command execution output as string>"
}

No binary data output is produced by this operation.

Dependencies

  • Requires access to a Kubernetes cluster with appropriate permissions.
  • Needs an API authentication token or credentials configured in n8n to connect securely to the Kubernetes API.
  • The node depends on an internal Kubernetes client utility to manage API requests and pod lifecycle.

Troubleshooting

  • Error: "No credentials got returned!"
    This indicates missing or misconfigured Kubernetes API credentials in n8n. Ensure that valid credentials are set up and linked to the node.

  • Error: "Command must be an array!"
    The Command property must be a valid JSON array of strings. Check that the input is correctly formatted (e.g., ["echo", "hello"]).

  • Pod creation or execution failures
    Could be due to insufficient permissions, invalid image names, or namespace issues. Verify that the specified namespace exists and the image is accessible.

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

Links and References


This summary focuses solely on the static code analysis of the run operation for the Deployments resource as requested.

Discussion