Skip to content

Commit 1a39123

Browse files
authored
docs: Update retina shell documentation (#1854)
# Description Updating the retina shell documentation to be more comprehensive. Removing the readme from `/shell` in favour of the documentation page to avoid having to maintain two documents. ## Related Issue #1835 ## Checklist - [x] I have read the [contributing documentation](https://retina.sh/docs/Contributing/overview). - [x] I signed and signed-off the commits (`git commit -S -s ...`). See [this documentation](https://docs.github.com/en/authentication/managing-commit-signature-verification/about-commit-signature-verification) on signing commits. - [x] I have correctly attributed the author(s) of the code. - [x] I have tested the changes locally. - [x] I have followed the project's style guidelines. - [x] I have updated the documentation, if necessary. - [x] I have added tests, if applicable. --- Please refer to the [CONTRIBUTING.md](../CONTRIBUTING.md) file for more information on how to contribute to this project. --------- Signed-off-by: Kamil <[email protected]>
1 parent fd113dd commit 1a39123

File tree

2 files changed

+114
-92
lines changed

2 files changed

+114
-92
lines changed

docs/06-Troubleshooting/shell.md

Lines changed: 114 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,37 @@
11
# Shell
22

3-
**EXPERIMENTAL: `retina shell` is an experimental feature, so the flags and behavior may change in future versions.**
3+
>NOTE: `retina shell` is an experimental feature. The flags and behavior may change in future versions.
44
5-
The `retina shell` command allows you to start an interactive shell on a Kubernetes node or pod. This runs a container image with many common networking tools installed (`ping`, `curl`, etc.).
5+
The `retina shell` command allows you to start an interactive shell on a Kubernetes node or pod for adhoc debugging.
66

7-
## Testing connectivity
7+
This runs a container image built from the Dockerfile in the `/shell` directory, with many common networking tools installed (`ping`, `curl`, etc.), as well as specialized tools such as [bpftool](#bpftool), [pwru](#pwru) or [Inspektor Gadget](#inspektor-gadget-ig).
88

9-
Start a shell on a node or inside a pod
9+
Currently the Retina Shell only works in Linux environments. Windows support will be added in the future.
1010

11-
```bash
11+
## Getting Started
12+
13+
Start a shell on a node or inside a pod:
14+
15+
```shell
1216
# To start a shell in a node (root network namespace):
13-
kubectl retina shell aks-nodepool1-15232018-vmss000001
17+
kubectl retina shell <node-name>
1418

1519
# To start a shell inside a pod (pod network namespace):
16-
kubectl retina shell -n kube-system pods/coredns-d459997b4-7cpzx
20+
kubectl retina shell -n kube-system pods/<pod-name>
21+
22+
# To start a shell inside of a node and mount the host file system
23+
kubectl retina shell <node-name> --mount-host-filesystem
24+
25+
# To start a shell inside of a node with extra capabilities
26+
kubectl retina shell <node-name> --capabilities=<CAPABILITIES,COMMA,SEPARATED>
1727
```
1828

29+
For testing, you can override the image used by `retina shell` either with CLI arguments (`--retina-shell-image-repo` and `--retina-shell-image-version`) or environment variables (`RETINA_SHELL_IMAGE_REPO` and `RETINA_SHELL_IMAGE_VERSION`).
30+
31+
Run `kubectl retina shell -h` for full documentation and examples.
32+
33+
## Testing connectivity
34+
1935
Check connectivity using `ping`:
2036

2137
```text
@@ -32,15 +48,6 @@ PING 10.224.0.4 (10.224.0.4) 56(84) bytes of data.
3248
rtt min/avg/max/mdev = 0.908/1.015/1.128/0.077 ms
3349
```
3450

35-
Check DNS resolution using `dig`:
36-
37-
```text
38-
root [ / ]# dig example.com +short
39-
93.184.215.14
40-
```
41-
42-
The tools `nslookup` and `drill` are also available if you prefer those.
43-
4451
Check connectivity to apiserver using `nc` and `curl`:
4552

4653
```text
@@ -61,35 +68,47 @@ root [ / ]# curl -k https://10.0.0.1
6168
}
6269
```
6370

64-
### nftables and iptables
71+
## DNS Resolution
72+
73+
Check DNS resolution using `dig`:
74+
75+
```text
76+
root [ / ]# dig example.com +short
77+
93.184.215.14
78+
```
79+
80+
The tools `nslookup` and `drill` are also available if you prefer those.
81+
82+
## nftables and iptables
6583

6684
Accessing nftables and iptables rules requires `NET_RAW` and `NET_ADMIN` capabilities.
6785

68-
```bash
69-
kubectl retina shell aks-nodepool1-15232018-vmss000002 --capabilities NET_ADMIN,NET_RAW
86+
```text
87+
kubectl retina shell <node-name> --capabilities NET_ADMIN,NET_RAW
7088
```
7189

7290
Then you can run `iptables` and `nft`:
7391

7492
```text
7593
root [ / ]# iptables -nvL | head -n 2
7694
Chain INPUT (policy ACCEPT 1191K packets, 346M bytes)
77-
pkts bytes target prot opt in out source destination
95+
pkts bytes target prot opt in out source destination
96+
7897
root [ / ]# nft list ruleset | head -n 2
7998
# Warning: table ip filter is managed by iptables-nft, do not touch!
8099
table ip filter {
81100
```
82101

83-
**If you see the error "Operation not permitted (you must be root)", check that your `kubectl retina shell` command sets `--capabilities NET_RAW,NET_ADMIN`.**
102+
>NOTE: If you see the error "Operation not permitted (you must be root)", check that your `kubectl retina shell` command sets `--capabilities NET_RAW,NET_ADMIN`.
84103
85104
`iptables` in the shell image uses `iptables-nft`, which may or may not match the configuration on the node. For example, Azure Linux 2 maps `iptables` to `iptables-legacy`. To use the exact same `iptables` binary as installed on the node, you will need to `chroot` into the host filesystem (see below).
86105

87106
## Accessing the host filesystem
88107

89108
On nodes, you can mount the host filesystem to `/host`:
90109

91-
```bash
92-
kubectl retina shell aks-nodepool1-15232018-vmss000002 --mount-host-filesystem
110+
```text
111+
kubectl retina shell <node-name> --mount-host-filesystem
93112
```
94113

95114
This mounts the host filesystem (`/`) to `/host` in the debug pod:
@@ -108,7 +127,7 @@ Symlinks between files on the host filesystem may not resolve correctly. If you
108127
`chroot` requires the `SYS_CHROOT` capability:
109128

110129
```bash
111-
kubectl retina shell aks-nodepool1-15232018-vmss000002 --mount-host-filesystem --capabilities SYS_CHROOT
130+
kubectl retina shell <node-name> --mount-host-filesystem --capabilities SYS_CHROOT
112131
```
113132

114133
Then you can use `chroot` to switch to start a shell inside the host filesystem:
@@ -133,7 +152,7 @@ search shncgv2kgepuhm1ls1dwgholsd.cx.internal.cloudapp.net
133152
`systemctl` commands require both `chroot` to the host filesystem and host PID:
134153

135154
```bash
136-
kubectl retina shell aks-nodepool1-15232018-vmss000002 --mount-host-filesystem --capabilities SYS_CHROOT --host-pid
155+
kubectl retina shell <node-name> --mount-host-filesystem --capabilities SYS_CHROOT --host-pid
137156
```
138157

139158
Then `chroot` to the host filesystem and run `systemctl status`:
@@ -144,7 +163,69 @@ root [ / ]# chroot /host systemctl status | head -n 2
144163
State: running
145164
```
146165

147-
**If `systemctl` shows an error "Failed to connect to bus: No data available", check that the `retina shell` command has `--host-pid` set and that you have chroot'd to /host.**
166+
>NOTE: If `systemctl` shows an error "Failed to connect to bus: No data available", check that the `retina shell` command has `--host-pid` set and that you have chroot'd to /host.
167+
168+
## [pwru](https://github.com/cilium/pwru)
169+
170+
eBPF-based tool for tracing network packets in the Linux kernel with advanced filtering capabilities. It allows fine-grained introspection of kernel state to facilitate debugging network connectivity issues.
171+
172+
Requires the `NET_ADMIN` and `SYS_ADMIN` capabilities.
173+
174+
Capability requirements are based on common eBPF tool practices and not directly from the pwru documentation.
175+
176+
```shell
177+
kubectl retina shell -n kube-system pod/<pod-name> --capabilities=NET_ADMIN,SYS_ADMIN
178+
```
179+
180+
You can then run, for example:
181+
182+
```shell
183+
pwru -h
184+
pwru "tcp and (src port 8080 or dst port 8080)"
185+
```
186+
187+
## [bpftool](https://github.com/libbpf/bpftool)
188+
189+
Allows you to list, dump, load BPF programs, etc. Reference utility to quickly inspect and manage BPF objects on your system, to manipulate BPF object files, or to perform various other BPF-related tasks.
190+
191+
Requires the `NET_ADMIN` and `SYS_ADMIN` capabilities.
192+
193+
```shell
194+
kubectl retina shell -n kube-system pod/<pod-name> --capabilities=NET_ADMIN,SYS_ADMIN
195+
```
196+
197+
You can then run for example:
198+
199+
```shell
200+
bpftool -h
201+
bpftool prog show
202+
bpftool map dump id <map_id>
203+
```
204+
205+
## [Inspektor Gadget (ig)](https://inspektor-gadget.io/)
206+
207+
Tools and framework for data collection and system inspection on Kubernetes clusters and Linux hosts using eBPF.
208+
209+
To use `ig`, you need to add the `--mount-host-filesystem`, `--apparmor-unconfined` and `--seccomp-unconfined` flags, along with the following capabilities:
210+
211+
* `NET_ADMIN`
212+
* `SYS_ADMIN`
213+
* `SYS_RESOURCE`
214+
* `SYSLOG`
215+
* `IPC_LOCK`
216+
* `SYS_PTRACE`
217+
* `NET_RAW`
218+
219+
```shell
220+
kubectl retina shell <node-name> --capabilities=NET_ADMIN,SYS_ADMIN,SYS_RESOURCE,SYSLOG,IPC_LOCK,SYS_PTRACE,NET_RAW --mount-host-filesystem --apparmor-unconfined --seccomp-unconfined
221+
```
222+
223+
You can then run for example:
224+
225+
```shell
226+
ig -h
227+
ig run trace_dns:latest
228+
```
148229

149230
## Troubleshooting
150231

@@ -158,7 +239,8 @@ If `kubectl retina shell` fails with a timeout error, then:
158239
Example:
159240

160241
```bash
161-
kubectl retina shell --timeout 10m node001 # increase timeout to 10 minutes
242+
# increase timeout to 10 minutes
243+
kubectl retina shell --timeout 10m <node-name>
162244
```
163245

164246
### Firewalls and ImagePullBackoff
@@ -172,14 +254,16 @@ Example:
172254

173255
```bash
174256
export RETINA_SHELL_IMAGE_REPO="example.azurecr.io/retina/retina-shell"
175-
export RETINA_SHELL_IMAGE_VERSION=v0.0.1 # optional, if not set defaults to the Retina CLI version.
176-
kubectl retina shell node0001 # this will use the image "example.azurecr.io/retina/retina-shell:v0.0.1"
257+
# optional, if not set defaults to the Retina CLI version.
258+
export RETINA_SHELL_IMAGE_VERSION=v0.0.1
259+
# this will use the image "example.azurecr.io/retina/retina-shell:v0.0.1"
260+
kubectl retina shell <node-name>
177261
```
178262

179263
## Limitations
180264

181265
* Windows nodes and pods are not yet supported.
182-
* `bpftool` and `bpftrace` are not supported.
266+
* `bpftrace` not yet supported.
183267
* The shell image links `iptables` commands to `iptables-nft`, even if the node itself links to `iptables-legacy`.
184268
* `nsenter` is not supported.
185269
* `ip netns` will not work without `chroot` to the host filesystem.

shell/README.md

Lines changed: 0 additions & 62 deletions
This file was deleted.

0 commit comments

Comments
 (0)