-
Notifications
You must be signed in to change notification settings - Fork 132
Add exec_in_pod tool for command execution in Kubernetes pods #128
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add exec_in_pod tool for command execution in Kubernetes pods #128
Conversation
…r command execution
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds a new tool, exec_in_pod, which enables command execution in Kubernetes pods while supporting both string and array command formats along with optional shell and container parameters. The key changes include:
- Implementation of the exec_in_pod tool with input validation and output handling.
- New tests to verify both array and string command executions and error handling.
- Updates to response schemas and the main request handler to register the new tool.
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
File | Description |
---|---|
tests/exec_in_pod.test.ts | New integration tests for the exec_in_pod tool functionality. |
src/tools/exec_in_pod.ts | Implementation of the exec_in_pod tool using the Kubernetes Exec API. |
src/models/response-schemas.ts | Added ExecInPodResponseSchema to support the new tool. |
src/index.ts | Updated request handler to include exec_in_pod in the tool list. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just the comment about making timeout configurable. I think the copilot review around using ExecInPodSchema is correct too, so probably want to update that.
Everything else LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code LGTM - not entirely sure whats causing the tests to fail though, once tests are fixed up can merge & make new build.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you want to land this before the big refactor or after?
This one needs a rebase after the refactor |
@rr-paras-patel ping on this PR - should be an easy rebase for index right? Seems like it would be a useful feature for next release. |
Summary: Test Plan:
See Flux159#129 Summary: Test Plan:
…to improve usability.
…t, detailing new features such as scaling deployments, port forwarding, and Helm operations.
…d enhance clarity in instructions. Updated descriptions and structured steps for better user guidance in Kubernetes resource investigations.
…-level issues, improving guidance for Kubernetes resource investigations. Updated instructions for clarity and actionable insights.
…tency. Updated keyword search description and expanded resource type identification to include Ingress.
… and kubectl_explain tool for resource type identification. Enhanced clarity in troubleshooting steps for Kubernetes resources.
… to "all" to broaden the search scope for troubleshooting resources across all namespaces.
Co-authored-by: Copilot <[email protected]>
…g fixed delay and updating response schema handling for prompts list.
…delete, create, logs, generic, patch, and rollout functionalities in index.ts.
…nce type safety and clarity.
…x.ts to streamline the toolset.
…ubernetes resources, following the removal of kubectl_list functionality.
…uring consistency across documentation and functionality following the removal of kubectl_list.
…t, ensuring alignment with recent changes in functionality across all test files.
…metadata references for improved clarity and consistency.
…es, and namespaces, ensuring robustness and clarity in resource validation.
…error handling, and improve service creation and deletion logic. Added tests for NodePort and LoadBalancer services, and ensured consistent use of asResponseSchema for type safety.
…tempt, improving error handling for non-existent services, and ensuring test failure for unexpected responses.
…e, updating descriptions for clarity and consistency in diagnostic operations.
…or connecting to AWS EKS, Google GKE, and Azure AKS clusters, and specify the latest image tag for Docker commands.
### Connect to Google GKE Clusters | ||
|
||
```json | ||
{ | ||
"mcpServers": { | ||
"kubernetes": { | ||
"command": "docker", | ||
"args": [ | ||
"run", | ||
"-i", | ||
"--rm", | ||
"-v", | ||
"~/.kube:/home/appuser/.kube:ro", | ||
"-v", | ||
"~/.config/gcloud:/home/appuser/.config/gcloud:ro", | ||
"-e", | ||
"CLOUDSDK_CORE_PROJECT=my-gcp-project", | ||
"-e", | ||
"CLOUDSDK_COMPUTE_REGION=us-central1", | ||
"flux159/mcp-server-kubernetes:latest" | ||
] | ||
} | ||
} | ||
} | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have a note around GKE in #103 (comment) - specifically the auth plugin for kubeconfig needs to be named "gke-gcloud-auth-plugin" for the docker container to correctly authenticate. Think that this is still the case so should be in the readme
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Flux159 can you please update GKE related instructions i only have capability to verify with EKS
Introduce a new tool to execute commands within Kubernetes pods, enhancing the functionality with a schema for input validation and response handling. The implementation supports both string and array command formats, along with an optional shell specification.
This pull request introduces a new feature for executing commands in Kubernetes pods, removes redundant functionality, and updates documentation to align with the changes. The most significant updates include the addition of the
exec_in_pod
tool, removal of thekubectl_list
tool, and updates to prompts and documentation to reflect these changes.New Feature:
exec_in_pod
Toolexec_in_pod
, for executing commands in Kubernetes pods using the Kubernetes client-node Exec API. It supports both string and array command formats, optional container targeting, and customizable timeouts. (src/tools/exec_in_pod.ts
, src/tools/exec_in_pod.tsR1-R203)exec_in_pod
tool insrc/index.ts
, including its schema and request handler. (src/index.ts
, [1] [2] [3]Removed Functionality:
kubectl_list
Toolkubectl_list
tool and its associated schema, as its functionality overlaps withkubectl_get
. (src/index.ts
, [1] [2] [3]README.md
to remove references tokubectl_list
. (README.md
, [1] [2]Updates to Prompts
k8s-troubleshoot
prompt tok8s-diagnose
for better clarity and alignment with its purpose. Updated descriptions, error messages, and flow details accordingly. (src/prompts/index.ts
, [1] [2]README.md
to reflect the prompt name change and its description. (README.md
, README.mdL92-R100)Documentation Enhancements
CLAUDE.md
file providing detailed development guidelines, architecture overview, and testing strategies for the MCP server. (CLAUDE.md
, CLAUDE.mdR1-R90)Schema Updates
exec_in_pod
tool to handle its output. (src/models/response-schemas.ts
, src/models/response-schemas.tsR163-R166)