Git Product home page Git Product logo

kubectl-netshoot's Introduction

kubectl netshoot ๐ŸŒ 

A kubectl plugin to easily spin up and access a netshoot container. netshoot is a network troubleshooting Swiss-army knife which allows you to perform Kubernetes troubleshooting without installing any new packages in your containers or cluster nodes.

Installation

krew

Using krew kubectl plugin manager:

# add kubectl-netshoot plugin index
kubectl krew index add netshoot https://github.com/nilic/kubectl-netshoot.git

# install netshoot plugin
kubectl krew install netshoot/netshoot

Without krew

Just download the binary for your OS and architecture from the Releases page and place it in your PATH.

Usage

Usage:
  kubectl netshoot [command]

Available Commands:
  completion  Generate the autocompletion script for the specified shell
  debug       Debug using an ephemeral container in an existing pod or on a node
  help        Help about any command
  run         Run a throwaway pod for troubleshooting
  version     Print kubectl-netshoot version

Flags:
  -h, --help                           help for kubectl-netshoot
      --host-network                   ("run" command only) spin up netshoot on the node's network namespace
      --image-name string              netshoot container image to use (default "nicolaka/netshoot")
      --image-tag string               netshoot container image tag to use (default "latest")

In addition to these flags, the following kubectl flags are available for all kubectl netshoot commands:

Flags:
      --as string                      Username to impersonate for the operation. User could be a regular user or a service account in a namespace.
      --as-group stringArray           Group to impersonate for the operation, this flag can be repeated to specify multiple groups.
      --as-uid string                  UID to impersonate for the operation.
      --cache-dir string               Default cache directory (default "$HOME/.kube/cache")
      --certificate-authority string   Path to a cert file for the certificate authority
      --client-certificate string      Path to a client certificate file for TLS
      --client-key string              Path to a client key file for TLS
      --cluster string                 The name of the kubeconfig cluster to use
      --context string                 The name of the kubeconfig context to use
      --disable-compression            If true, opt-out of response compression for all requests to the server
      --insecure-skip-tls-verify       If true, the server's certificate will not be checked for validity. This will make your HTTPS connections insecure
      --kubeconfig string              Path to the kubeconfig file to use for CLI requests.
      --match-server-version           Require server version to match client version
  -n, --namespace string               If present, the namespace scope for this CLI request
      --request-timeout string         The length of time to wait before giving up on a single server request. Non-zero values should contain a corresponding time unit (e.g. 1s, 2m, 3h). A value of zero means don't timeout requests. (default "0")
  -s, --server string                  The address and port of the Kubernetes API server
      --tls-server-name string         Server name to use for server certificate validation. If it is not provided, the hostname used to contact the server is used
      --token string                   Bearer token for authentication to the API server
      --user string                    The name of the kubeconfig user to use

Examples

Interactive session

Common use-case is to spin up a netshoot container with an interactive session and attach to it so you can perform troubleshooting using tools available in netshoot.

run command is equivalent to kubectl run --rm meaning that the pod will be deleted after you exit the session.

# spin up a throwaway pod for troubleshooting
kubectl netshoot run tmp-shell

# spin up a throwaway pod with a specific netshoot image
kubectl netshoot run tmp-shell --image-tag v0.5

# spin up a throwaway pod on the node's network namespace
kubectl netshoot run tmp-shell --host-network

debug command spins up netshoot as an ephemeral container in an existing pod or on a node. Ephemeral container terminates after the interactive session is exited.

# debug using an ephemeral container in an existing pod
kubectl netshoot debug my-existing-pod

# debug with a specific netshoot image
kubectl netshoot debug my-existing-pod --image-tag v0.5

# create a debug session on a node
kubectl netshoot debug node/my-node

When running a debug session on a node, netshoot will run in the node's network namespace and have node's filesystem mounted at /host.

Running one-time commands

Instead of attaching to the shell, you can also run a one-time command directly on the netshoot container. The command you want to run is specified after --:

kubectl netshoot run tmp-shell -- ping 8.8.8.8
kubectl netshoot debug mypod -- curl localhost:8443

Troubleshooting with a custom container

By default, plugin spins up nicolaka/netshoot:latest container image, but flags --image-name and --image-tag allow for running an arbitrary container, eg.

kubectl netshoot run tmp-shell --image-name busybox --image-tag 1.36.0

kubectl-netshoot's People

Contributors

nilic avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

kubectl-netshoot's Issues

Please add netshoot kubect plugin to krew

Hi,

netshoot is such a timesaver and also your plugin, it would be really nice if you could add the plugin to krew which basically only needs writing a manifest file to add it to the krew plugin index.

https://krew.sigs.k8s.io/docs/developer-guide/distributing-with-krew/

i can also give it a shot because with all the plugins it's much nicer to have a system to automatically update all the plugins, and with hundrets of them already in krew it would be a huge benefit, because imho netshoot is the best debug image out there :)!

Add support for mounting volumes into ephemeral container

Thanks for sharing this great plugin with the community !

As a kubectl-netshoot user,
In order to inspect mounted volumes in a pod, such as secrets, configmaps or volumes that can be mounted more than once,
I need an kubectl-netshoot option to craft the ephemeral container with volumeMounts from the pod

See kubernetes/kubectl#1071 (comment)

I started crafting some bash + jq script to do so, see WIP at https://github.com/orange-cloudfoundry/paas-templates/issues/1949#issuecomment-1549714130 but this feels snowflake. This seems much better located into kubectl-netshoot

Add support to specify nodeSelector

Hi. I have a mixed cluster with Linux & Windows-based nodes. netshoot fails when is being scheduled onto Windows node. With plain kubectl I overcome it with the following command:

kubectl run tmp-shell --rm -i --tty --image nicolaka/netshoot --overrides='{ "spec": { "nodeSelector": { "kubernetes.io/os": "linux" } } }'

It would be nice to have this functionality supported in the plugin.

Add support for setting security context into ephemeral container specs

As a kubectl-netshoot user,
In order to use strace to debug a program (e.g. infering data sent over an encrypted connection)
I need an kubectl-netshoot option to craft the ephemeral container with a security context such as "securityContext": {"capabilities": {"add": ["SYS_PTRACE"]}},or

More background into
https://betterprogramming.pub/debugging-kubernetes-pods-deep-dive-d6b2814cd8ce

Unfortunately, I didnโ€™t find a way to pass extra permissions to the ephemeral container from kubectl command. So we will construct and send an HTTP request to kube API server without the use of kubectl command.

curl -v -XPATCH -H "Content-Type: application/json-patch+json" \
'http://127.0.0.1:8001/api/v1/namespaces/default/pods/nginx-8f458dc5b-wkvq4/ephemeralcontainers' \
--data-binary @- << EOF
[{
"op": "add", "path": "/spec/ephemeralContainers/-",
"value": {
"command":[ "/bin/sh" ],
"stdin": true, "tty": true,
"image": "nicolaka/netshoot",
"name": "debug-strace",
"securityContext": {"capabilities": {"add": ["SYS_PTRACE"]}},
"targetContainerName": "nginx" }}]
EOF

Now, You can strace without getting permission denied.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.