Kubernetes Command Generator using Natural Language and GPT-4o - n8n Workflow

Use this powerful n8n workflow to translate natural language into secure, read-only kubectl commands for managing Kubernetes clusters, powered by GPT-4o.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?

This n8n workflow is ideal for:
DevOps Engineers and SREs looking to interact with K8s clusters via chat.
Users who want to simplify complex kubectl syntax using natural language.
Teams utilizing the n8n Chat interface for operational automation.
Anyone interested in advanced AI agents within an n8n automation structure.

Overview

Managing multi-cluster Kubernetes environments often requires precise and lengthy kubectl commands. This innovative n8n workflow solves this complexity by leveraging the intelligence of GPT-4o alongside specialized n8n node tools (MCP client).

When a user submits a natural language request (e.g., 'Show me failing pods in the staging cluster'), the workflow first intelligently identifies the target cluster, switches the Kubernetes context, and then utilizes a dedicated AI Agent to generate the correct, read-only kubectl command. This ensures operations are safe and standardized. This powerful n8n workflow acts as a natural language interface for infrastructure monitoring, showcasing the versatility of custom n8n templates for DevOps.

How it Works

This automation starts with a user's request and follows a clear, multi-step process:


  1. Trigger Reception: The process is initiated by the When chat message received n8n trigger, which captures the user's natural language input.

  2. Cluster Identification: The K8s Cluster Analyzer (a Langchain Agent using GPT-4o and the List K8s Clusters tool) analyzes the input to determine which Kubernetes cluster the user intends to query. If the cluster is ambiguous or missing, it prompts the user with available options. This step ensures the correct context is established.

  3. Context Switching: If a cluster is identified, the Switch K8s Context n8n node utilizes a custom MCP tool to securely change the active K8s context to the specified cluster.

  4. Command Generation: The K8s Query Analyzer (another Langchain Agent powered by GPT-4o) takes the original user query and converts it into a valid, read-only kubectl command (e.g., kubectl get pods --field-selector=status.phase=Failed). The prompt enforces strict JSON output and read-only constraints, making this a highly secure n8n workflow step.

  5. Command Execution: Finally, the Kubectl MCP Tool n8n node executes the generated kubectl command using the runkubectlcommand_ro operation, fetching the results back to the user.

Installation Guide

To deploy this expert n8n workflow, follow these steps:


  1. Import the n8n template: Copy the provided JSON and import it into your n8n instance via the 'Workflows' section and the 'New' -> 'Import from JSON' option.

  2. OpenAI Credentials: You must configure an OpenAI credential set with access to gpt-4o. Connect the OpenAI K8s Model and OpenAI Chat Model nodes to this credential.

  3. MCP Tool Credentials: This workflow relies on specialized external tooling (MCP Client) designed for interacting with Kubernetes configurations (likely involving kubectl access and secure context management). You must set up the mcpClientApi credentials for the Kubectl MCP Tool, Switch K8s Context, and List K8s Clusters n8n node steps. This credential setup will link your n8n installation to your K8s environment.

  4. Activation: Once credentials are set up, activate the When chat message received n8n trigger to start listening for user input.

Node Details

When chat message received (Langchain Chat Trigger): This is the starting n8n trigger. It listens for incoming messages, typically from a defined chat interface, providing the chatInput for the rest of the n8n workflow.
OpenAI Chat Model / OpenAI K8s Model (Langchain ChatOpenAI): These n8n node instances utilize gpt-4o as the core LLM engine. They are critical for the natural language processing and structured command generation capabilities of the workflow.
List K8s Clusters (MCP Client Tool): A custom n8n node that executes the listclusters operation. Its function is to dynamically provide the list of available Kubernetes contexts to the AI Analyzer.
K8s Cluster Analyzer (Langchain Agent): This n8n node uses the LLM and the List K8s Clusters tool to intelligently match the user's request to a specific, available cluster name. It ensures the query is executed in the correct K8s environment.
Switch K8s Context (MCP Client): This n8n node executes the switchcontext command, preparing the environment for the subsequent kubectl operation.
K8s Query Analyzer (Langchain Agent): This highly constrained n8n node is responsible for taking the user's query and generating the output only as a raw JSON object containing a secure, read-only kubectl command.


  • Kubectl MCP Tool (MCP Client): The final execution n8n node. It runs the generated read-only kubectl command using the runkubectlcommand_ro operation via the custom tool.

Related n8n Workflows

Free

Nodes: 6 Nodes
Updated: December 26 2025
View all
Created by

An enthusiast DevOps Engineer with 3+ years of experience in devops tools and automation.

Featured*