From eed0cb87ae67079d84c13d43e25dc3f5fe3b8df9 Mon Sep 17 00:00:00 2001 From: Fabian <62034751+BaldFabi@users.noreply.github.com> Date: Sat, 30 Aug 2025 01:27:36 +0200 Subject: [PATCH] feat(plugins): add pvc debug container plugin (#3528) --- plugins/README.md | 3 ++- plugins/pvc-debug-container.yaml | 38 ++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 plugins/pvc-debug-container.yaml diff --git a/plugins/README.md b/plugins/README.md index fd3ad893..1c9536e6 100644 --- a/plugins/README.md +++ b/plugins/README.md @@ -5,7 +5,7 @@ K9s plugins extend the tool to provide additional functionality via actions to f Following is an example of some plugin files in this directory. Other files are not listed in this table. | Plugin-Name | Description | Available on Views | Shortcut | Kubectl plugin, external dependencies | -|--------------------------------|-------------------------------------------------------------------------------------------|-------------------------------------|-----------|---------------------------------------------------------------------------------------| +| ------------------------------ | ----------------------------------------------------------------------------------------- | ----------------------------------- | --------- | ------------------------------------------------------------------------------------- | | ai-incident-investigation.yaml | Run AI investigation on application issues to find the root cause in seconds | all | Shift-h/o | [HolmesGPT](https://github.com/robusta-dev/holmesgpt) | | argocd.yaml | Perform argocd operation quickly | applications | Shift-r | [ArgoCD](https://argo-cd.readthedocs.io/en/stable/getting_started/) | | debug-container.yaml | Add [ephemeral debug container](1)
([nicolaka/netshoot](2)) | containers | Shift-d | | @@ -21,6 +21,7 @@ Following is an example of some plugin files in this directory. Other files are | log-jq.yaml | View resource logs using jq | pods | Ctrl-j | kubectl-plugins/kubectl-jq | | log-bunyan.yaml | View pods, service, deployment logs using bunyan | pods, service, deployment | Ctrl-l | [Bunyan](https://www.npmjs.com/package/bunyan) | | log-full.yaml | get full logs from pod/container | pods/containers | Ctrl-l | | +| pvc-debug-container.yaml | Add ephemeral debug container with pvc mounted | pods | s | kubectl | | resource-recommendations.yaml | View recommendations for CPU/Memory requests based on historical data | deployments/daemonsets/statefulsets | Shift-k | [Robusta KRR](https://github.com/robusta-dev/krr) | | szero.yaml | Temporarily scale down/up all deployments, statefulsets, and daemonsets | namespaces | Shift-d/u | [szero](https://github.com/jadolg/szero) | | trace-dns.yaml | Trace DNS resolution using Inspektor Gadget (4) | containers/pods/nodes | Shift-d | | diff --git a/plugins/pvc-debug-container.yaml b/plugins/pvc-debug-container.yaml new file mode 100644 index 00000000..b647c85d --- /dev/null +++ b/plugins/pvc-debug-container.yaml @@ -0,0 +1,38 @@ +plugins: + pvc-shell: + shortCut: s + description: "Spawn an Ubuntu shell pod with this PVC mounted" + scopes: + - pvc + command: sh + background: false + args: + - -c + - | + echo "Starting a shell pod with PVC $NAME mounted at /mnt/data" + cat < /dev/null 2>&1 - + apiVersion: v1 + kind: Pod + metadata: + name: pvc-shell + namespace: $NAMESPACE + spec: + restartPolicy: Never + containers: + - name: shell + image: ubuntu:latest + command: ["bash"] + stdin: true + tty: true + volumeMounts: + - name: vol + mountPath: /mnt/data + volumes: + - name: vol + persistentVolumeClaim: + claimName: $NAME + EOF + echo "Waiting for pod to be ready..." + kubectl --kubeconfig $KUBECONFIG -n $NAMESPACE wait --for=condition=Ready pod/pvc-shell > /dev/null 2>&1 + kubectl --kubeconfig $KUBECONFIG -n $NAMESPACE exec -it pvc-shell -- bash + kubectl --kubeconfig $KUBECONFIG -n $NAMESPACE delete pod pvc-shell --grace-period=0 --force=true > /dev/null 2>&1