Kubernetes icon

Kubernetes

Interact with Kubernetes

Overview

This node enables interaction with Kubernetes resources, specifically supporting operations on StatefulSets among other resource types. The Exec operation allows executing commands inside a container of a specified StatefulSet pod within a Kubernetes cluster.

Common scenarios include:

  • Running diagnostic or maintenance commands inside pods managed by StatefulSets.
  • Executing scripts or commands dynamically without needing to SSH into the nodes.
  • Automating operational tasks such as log inspection, configuration checks, or triggering application-specific commands inside containers.

For example, you might use this node to run a shell command inside a pod of a StatefulSet to check application status or retrieve runtime information.

Properties

Name Meaning
Image The container image name used when running or restarting pods (required for some operations).
Namespace The Kubernetes namespace where the StatefulSet resides. Defaults to "default".
Resource Name The name of the specific StatefulSet resource to target for the operation.

Note: For the Exec operation, the node expects the Resource property to be set to "statefulsets" and requires specifying the Namespace and Resource Name to identify the target StatefulSet.

Output

The output is a JSON array containing the result of the executed command inside the StatefulSet pod. The structure includes:

  • stdout: The standard output returned from the command execution inside the pod.

If the node supports binary data output (not explicitly shown in the provided code), it would typically represent files or streams retrieved from the pod, but here only JSON output with command results is returned.

Dependencies

  • Requires access to a Kubernetes cluster with appropriate permissions to execute commands inside pods.
  • Needs an API authentication token or API key credential configured in n8n to authenticate against the Kubernetes API.
  • The node uses an internal Kubernetes client utility (K8SClient) to interact with the cluster.

Troubleshooting

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

  • Command must be an array!
    The command input must be a JSON array of strings representing the command and its arguments. Providing a string or invalid JSON will cause this error.

  • Resource not found or permission denied
    If the specified StatefulSet or namespace does not exist or the credentials lack sufficient permissions, the operation will fail. Verify resource names, namespaces, and RBAC permissions.

  • Empty or no output returned
    If the command executes but returns no output, verify the command correctness and container state.

Links and References

Discussion