Skip to content

Commit d6a3200

Browse files
committed
updating README, contribution notes, k8s deployment
1 parent 35c2ef9 commit d6a3200

File tree

3 files changed

+118
-9
lines changed

3 files changed

+118
-9
lines changed

Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ RUN apt-get update && apt-get install -y \
77

88
RUN /tmp/fetch_binaries.sh
99

10-
FROM alpine:3.14
10+
FROM alpine:3.15.4
1111

1212
RUN set -ex \
1313
&& echo "http://nl.alpinelinux.org/alpine/edge/main" >> /etc/apk/repositories \

README.md

+92-8
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ Kubernetes also uses network namespaces. Kubelets creates a network namespace pe
1717

1818
Cool thing about namespaces is that you can switch between them. You can enter a different container's network namespace, perform some troubleshooting on its network's stack with tools that aren't even installed on that container. Additionally, `netshoot` can be used to troubleshoot the host itself by using the host's network namespace. This allows you to perform any troubleshooting without installing any new packages directly on the host or your application's package.
1919

20+
## Netshoot with Docker
21+
2022
* **Container's Network Namespace:** If you're having networking issues with your application's container, you can launch `netshoot` with that container's network namespace like this:
2123

2224
`$ docker run -it --net container:<container_name> nicolaka/netshoot`
@@ -27,15 +29,88 @@ Cool thing about namespaces is that you can switch between them. You can enter a
2729

2830
* **Network's Network Namespace:** If you want to troubleshoot a Docker network, you can enter the network's namespace using `nsenter`. This is explained in the `nsenter` section below.
2931

30-
**Kubernetes**
31-
32-
If you want to spin up a throw away container for debugging.
32+
## Netshoot with Docker Compose
3333

34-
`$ kubectl run tmp-shell --rm -i --tty --image nicolaka/netshoot -- /bin/bash`
34+
You can easily deploy `netshoot` using Docker Compose using something like this:
3535

36-
And if you want to spin up a container on the host's network namespace.
36+
```
37+
version: "3.6"
38+
services:
39+
tcpdump:
40+
image: nicolaka/netshoot
41+
depends_on:
42+
- nginx
43+
command: tcpdump -i eth0 -w /data/nginx.pcap
44+
network_mode: service:nginx
45+
volumes:
46+
- $PWD/data:/data
47+
48+
nginx:
49+
image: nginx:alpine
50+
ports:
51+
- 80:80
52+
```
3753

38-
`$ kubectl run tmp-shell --rm -i --tty --overrides='{"spec": {"hostNetwork": true}}' --image nicolaka/netshoot -- /bin/bash`
54+
## Netshoot with Kubernetes
55+
56+
* If you want to spin up a throw away container for debugging.
57+
58+
`$ kubectl run tmp-shell --rm -i --tty --image nicolaka/netshoot`
59+
60+
* if you want to spin up a container on the host's network namespace.
61+
62+
`$ kubectl run tmp-shell --rm -i --tty --overrides='{"spec": {"hostNetwork": true}}' --image nicolaka/netshoot`
63+
64+
* if you want to use netshoot as a sidecar container to troubleshoot your application container
65+
66+
```
67+
$ cat netshoot-sidecar.yaml
68+
apiVersion: apps/v1
69+
kind: Deployment
70+
metadata:
71+
name: nginx-netshoot
72+
labels:
73+
app: nginx-netshoot
74+
spec:
75+
replicas: 1
76+
selector:
77+
matchLabels:
78+
app: nginx-netshoot
79+
template:
80+
metadata:
81+
labels:
82+
app: nginx-netshoot
83+
spec:
84+
containers:
85+
- name: nginx
86+
image: nginx:1.14.2
87+
ports:
88+
- containerPort: 80
89+
- name: netshoot
90+
image: nicolaka/netshoot
91+
command: ["/bin/bash"]
92+
args: ["-c", "while true; do ping localhost; sleep 60;done"]
93+
94+
$ kubectl apply -f netshoot-sidecar.yaml
95+
deployment.apps/nginx-netshoot created
96+
97+
$ kubectl get pod
98+
NAME READY STATUS RESTARTS AGE
99+
nginx-netshoot-7f9c6957f8-kr8q6 2/2 Running 0 4m27s
100+
101+
$ kubectl exec -it nginx-netshoot-7f9c6957f8-kr8q6 -c netshoot -- /bin/zsh
102+
dP dP dP
103+
88 88 88
104+
88d888b. .d8888b. d8888P .d8888b. 88d888b. .d8888b. .d8888b. d8888P
105+
88' `88 88ooood8 88 Y8ooooo. 88' `88 88' `88 88' `88 88
106+
88 88 88. ... 88 88 88 88 88. .88 88. .88 88
107+
dP dP `88888P' dP `88888P' dP dP `88888P' `88888P' dP
108+
109+
Welcome to Netshoot! (github.com/nicolaka/netshoot)
110+
111+
112+
nginx-netshoot-7f9c6957f8-kr8q6 $
113+
```
39114

40115
**Network Problems**
41116

@@ -602,6 +677,15 @@ swaks --to [email protected] \
602677

603678
More info, examples and lots of documentation on `Swaks` [here](http://www.jetmore.org/john/code/swaks/)
604679

605-
## Feedback & Contribution
680+
## Contribution
681+
682+
Feel free to provide to contribute networking troubleshooting tools and use-cases by opening PRs. If you would like to add any package, please follow these steps:
683+
684+
* In the PR, please include some rationale as to why this tool is useful to be included in netshoot.
685+
> Note: If the functionality of the tool is already addressed by an existing tool, I might not accept the PR
686+
* Change the Dockerfile to include the new package/tool
687+
* If you're building the tool from source, make sure you leverage the multi-stage build process and update the `build/fetch_binaries.sh` script
688+
* Update the README's list of included packages AND include a section on how to use the tool
689+
* If the tool you're adding supports multi-platform, please make sure you highlight that.
690+
606691

607-
Feel free to provide feedback and contribute networking troubleshooting tools and use-cases by opening PRs. If you would like to add any package, open a PR with the rationale and ensure that you update both the Dockerfile and the README with some examples on how to use it!

configs/netshoot-sidecar.yaml

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: nginx-netshoot
5+
labels:
6+
app: nginx-netshoot
7+
spec:
8+
replicas: 1
9+
selector:
10+
matchLabels:
11+
app: nginx-netshoot
12+
template:
13+
metadata:
14+
labels:
15+
app: nginx-netshoot
16+
spec:
17+
containers:
18+
- name: nginx
19+
image: nginx:1.14.2
20+
ports:
21+
- containerPort: 80
22+
- name: netshoot
23+
image: nicolaka/netshoot
24+
command: ["/bin/bash"]
25+
args: ["-c", "while true; do ping localhost; sleep 60;done"]

0 commit comments

Comments
 (0)