Kubernetes icon

Kubernetes

Interact with Kubernetes

Overview

This node enables interaction with a Kubernetes cluster by performing various operations on Kubernetes resources. It is useful for automating management tasks such as patching resources, running pods, retrieving resource details, and more within Kubernetes environments.

For the Patch operation specifically, the node allows users to modify existing Kubernetes resources by applying partial updates. This can be beneficial when you want to update configurations or metadata of resources like pods, deployments, or services without replacing the entire resource definition.

Practical examples include:

  • Updating labels or annotations on a pod or deployment.
  • Changing the number of replicas in a deployment by patching its spec.
  • Modifying container images or environment variables in running pods.

Properties

Name Meaning
Image The container image name used when running, restarting, executing commands, or patching.
Namespace The Kubernetes namespace where the target resource resides. Defaults to "default".
Resource Name The specific name of the Kubernetes resource to operate on (e.g., pod name).

Note: These properties are shown for the Patch operation and related operations like run, restart, and exec.

Output

The node outputs JSON data representing the result of the Kubernetes API call corresponding to the operation performed. For the Patch operation, this typically includes the updated resource object returned by the Kubernetes API after the patch is applied.

The output JSON structure reflects the standard Kubernetes resource schema, including metadata, spec, status, and other relevant fields depending on the resource type patched.

No binary data output is indicated for this operation.

Dependencies

  • Requires an API authentication token or credentials to connect to the Kubernetes cluster.
  • The node depends on a Kubernetes client utility internally to communicate with the Kubernetes API.
  • Proper permissions must be granted to the provided credentials to perform patch operations on the specified resources and namespaces.

Troubleshooting

  • Missing Credentials Error: If no credentials are provided or retrieved, the node throws an error indicating missing credentials. Ensure that valid Kubernetes API credentials are configured in n8n.
  • Invalid Command Format: For operations requiring commands (not directly relevant to Patch), the node expects commands as arrays; otherwise, it throws an error.
  • Resource Not Found: If the specified resource name or namespace does not exist, the Kubernetes API will return an error. Verify resource names and namespaces.
  • Insufficient Permissions: Patch operations require appropriate RBAC permissions. Lack of permissions will cause API errors.
  • Malformed Patch Data: Although not explicitly shown in the code snippet, ensure that any patch payloads conform to Kubernetes patch formats (JSON Merge Patch, Strategic Merge Patch, or JSON Patch) to avoid API rejections.

Links and References

Discussion