Portainer icon

Portainer

Interact with Portainer via API

Actions190

Kubernetes → Create Kubernetes Namespace

AI-generated

Overview

This node operation allows you to create a new Kubernetes Namespace by sending the namespace configuration details to a Kubernetes environment. It is useful when you want to programmatically manage Kubernetes namespaces, for example, to isolate resources, organize clusters, or prepare environments for different applications or teams.

Practical examples include:

  • Automating the setup of namespaces during CI/CD pipelines.
  • Creating isolated environments for development, testing, or production.
  • Managing multi-tenant Kubernetes clusters by dynamically provisioning namespaces.

Properties

Name Meaning
Id Environment identifier (a numeric ID representing the target Kubernetes environment).
Body Namespace configuration details in JSON string format. This should contain the specification of the namespace you want to create, such as metadata and labels.

Output

The node outputs JSON data representing the response from the Kubernetes API after attempting to create the namespace. This typically includes details about the created namespace object, such as its name, status, and metadata.

If the operation succeeds, the output JSON will confirm the namespace creation with relevant information. If it fails, the output may contain error details.

The node does not output binary data.

Dependencies

  • Requires access to a Kubernetes cluster API endpoint.
  • Needs an API authentication token or credentials configured in n8n to authorize requests to the Kubernetes API.
  • The user must provide the environment identifier corresponding to the Kubernetes cluster where the namespace will be created.

Troubleshooting

  • Common issues:

    • Invalid or missing authentication credentials can cause authorization errors.
    • Malformed JSON in the "Body" property can lead to request failures.
    • Attempting to create a namespace that already exists will result in an error.
    • Incorrect environment identifier may cause the request to fail or target the wrong cluster.
  • Error messages and resolutions:

    • 401 Unauthorized: Check that the API authentication token or credentials are correctly set up.
    • 400 Bad Request: Verify that the JSON in the "Body" property is valid and conforms to Kubernetes namespace schema.
    • 409 Conflict: Namespace already exists; choose a different name or handle the conflict accordingly.
    • 404 Not Found: The specified environment identifier does not correspond to a reachable Kubernetes cluster.

Links and References

Discussion