Skip to content

Commit dce67a8

Browse files
committed
feat(kubernetes): enable containerd debugging in calico debug env
1 parent 2644072 commit dce67a8

File tree

5 files changed

+49
-17
lines changed

5 files changed

+49
-17
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
| tag | version | alias | note |
3030
|-----|---------|-------|------|
31-
| [kubernetes-v1.35.1_containerd-v2.2.1_calico_debug](./kubernetes/v1.35.1/containerd/v2.2.1/calico/debug) | v0.1.0 | - | debug kubelet |
31+
| [kubernetes-v1.35.1_containerd-v2.2.1_calico_debug](./kubernetes/v1.35.1/containerd/v2.2.1/calico/debug) | v0.2.0 | - | debug kubelet,containerd |
3232
| [kubernetes-v1.35.1_containerd-v2.2.1_calico](./kubernetes/v1.35.1/containerd/v2.2.1/calico/default) | v0.1.0 | - | calico installed |
3333
| [kubernetes-v1.35.1_containerd-v2.2.1_init](./kubernetes/v1.35.1/containerd/v2.2.1/init) | v0.1.0 | - | kubeadm init, without CNI |
3434
| [kubernetes-v1.35.1_containerd-v2.2.1_base](./kubernetes/v1.35.1/containerd/v2.2.1/base) | v0.1.0 | - | k8s components installed |
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
VERSION=v0.1.0
1+
VERSION=v0.2.0
22
IMAGE=kubernetes-v1.35.1_containerd-v2.2.1_calico_debug
33
COMPOSE_PROJECT_NAME=kubernetes-1-35-1_containerd-v2-2-1-calico-debug

kubernetes/v1.35.1/containerd/v2.2.1/calico/debug/Dockerfile

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,20 @@ ARG VERSION_IMAGE=0.1.0
1212
# ================================
1313
ARG BASE_IMAGE=ghcr.io/ctrsploit/kubernetes-v${VERSION_KUBERNETES}_containerd-v${VERSION_CONTAINERD}_calico:ctr_v${VERSION_IMAGE}
1414
ARG URL_ARTIFACT_KUBELET_DEBUG=https://github.com/ssst0n3/container-debug-artifacts/releases/download/kubernetes/kubelet-v${VERSION_KUBERNETES}-debug
15-
# ARG URL_ARTIFACT_CONTAINERD_DEBUG=https://github.com/ssst0n3/container-debug-artifacts/releases/download/containerd/containerd-v${VERSION_CONTAINERD}-debug
15+
ARG URL_ARTIFACT_CONTAINERD_DEBUG=https://github.com/ssst0n3/container-debug-artifacts/releases/download/containerd/containerd-v${VERSION_CONTAINERD}-debug
1616
ARG URL_ARTIFACT_DLV=https://github.com/ssst0n3/container-debug-artifacts/releases/download/dlv/dlv-v${VERSION_DLV}
1717

1818
# ================================
1919
# Build Stages
2020
# ================================
2121
FROM ${BASE_IMAGE}
2222
ARG URL_ARTIFACT_KUBELET_DEBUG
23-
# ARG URL_ARTIFACT_CONTAINERD_DEBUG
23+
ARG URL_ARTIFACT_CONTAINERD_DEBUG
2424
ARG URL_ARTIFACT_DLV
2525
ADD --chmod=755 ${URL_ARTIFACT_KUBELET_DEBUG} /usr/local/bin/kubelet.debug
26-
# ADD --chmod=755 ${URL_ARTIFACT_CONTAINERD_DEBUG} /usr/local/bin/containerd.debug
26+
ADD --chmod=755 ${URL_ARTIFACT_CONTAINERD_DEBUG} /usr/local/bin/containerd.debug
2727
ADD --chmod=755 ${URL_ARTIFACT_DLV} /usr/local/bin/dlv
2828
COPY --chmod=755 debug.sh /usr/local/bin/debug.sh
29-
# back up real kubelet binary
29+
# back up real binary
3030
RUN cp /usr/bin/kubelet /usr/local/bin/kubelet.real && \
31-
# back up real containerd binary
3231
cp /usr/local/bin/containerd /usr/local/bin/containerd.real

kubernetes/v1.35.1/containerd/v2.2.1/calico/debug/README.md

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
| Type | Image | Notes |
44
| ---- | ----- | ----- |
55
| dqd | ghcr.io/ctrsploit/kubernetes-v1.35.1_containerd-v2.2.1_calico_debug:latest | -> `v0.2.0` |
6+
| dqd | ghcr.io/ctrsploit/kubernetes-v1.35.1_containerd-v2.2.1_calico_debug:v0.2.0 | debug kubelet,containerd |
67
| dqd | ghcr.io/ctrsploit/kubernetes-v1.35.1_containerd-v2.2.1_calico_debug:v0.1.0 | debug kubelet |
8+
| ctr | ghcr.io/ctrsploit/kubernetes-v1.35.1_containerd-v2.2.1_calico_debug:ctr_v0.2.0 | - |
79
| ctr | ghcr.io/ctrsploit/kubernetes-v1.35.1_containerd-v2.2.1_calico_debug:ctr_v0.1.0 | - |
810

911
## Usage
@@ -19,14 +21,27 @@ $ docker compose -f docker-compose.yml -f docker-compose.kvm.yml up -d
1921

2022
```shell
2123
$ ./ssh
22-
root@kubernetes-1-32-2-containerd-2-0-3:~# systemctl stop kubelet
23-
root@kubernetes-1-32-2-containerd-2-0-3:~# ln -sf /usr/local/bin/debug.sh /usr/bin/kubelet
24-
root@kubernetes-1-32-2-containerd-2-0-3:~# systemctl start kubelet
25-
root@kubernetes-1-32-2-containerd-2-0-3:~# journalctl -u kubelet -f
24+
root@kubernetes-1-35-1-containerd-2-2-1:~# systemctl stop kubelet
25+
root@kubernetes-1-35-1-containerd-2-2-1:~# ln -sf /usr/local/bin/debug.sh /usr/bin/kubelet
26+
root@kubernetes-1-35-1-containerd-2-2-1:~# systemctl start kubelet
27+
root@kubernetes-1-35-1-containerd-2-2-1:~# journalctl -u kubelet -f
2628
API server listening at: [::]:2345
2729
...
2830
```
2931

32+
### Debug Containerd with Delve
33+
34+
```shell
35+
$ ./ssh
36+
root@kubernetes-1-35-1-containerd-2-2-1:~# systemctl stop containerd
37+
root@kubernetes-1-35-1-containerd-2-2-1:~# ln -sf /usr/local/bin/debug.sh /usr/local/bin/containerd
38+
root@kubernetes-1-35-1-containerd-2-2-1:~# /usr/local/bin/containerd --config /etc/containerd/config.toml
39+
API server listening at: [::]:2346
40+
...
41+
```
42+
43+
> Using `systemctl start containerd` is also ok, but will raise a systemctl's timeout error. It's as an expected behavior, because `containerd.service` uses `Type=notify`, and launching containerd via Delve can cause systemd startup timeout.
44+
3045
### GoLand remote attach
3146

3247
kubelet
@@ -37,13 +52,30 @@ Host: 127.0.0.1
3752
Port: 13516
3853
```
3954

55+
containerd
56+
57+
```text
58+
Run/Debug Configurations -> Go Remote
59+
Host: 127.0.0.1
60+
Port: 13517
61+
```
62+
4063
### Restore Kubelet
4164

4265
```shell
43-
root@kubernetes-1-32-2-containerd-2-0-3:~# systemctl stop kubelet
44-
root@kubernetes-1-32-2-containerd-2-0-3:~# cp /usr/local/bin/kubelet.real /usr/bin/kubelet
45-
root@kubernetes-1-32-2-containerd-2-0-3:~# chmod +x /usr/bin/kubelet
46-
root@kubernetes-1-32-2-containerd-2-0-3:~# systemctl start kubelet
66+
root@kubernetes-1-35-1-containerd-2-2-1:~# systemctl stop kubelet
67+
root@kubernetes-1-35-1-containerd-2-2-1:~# cp /usr/local/bin/kubelet.real /usr/bin/kubelet
68+
root@kubernetes-1-35-1-containerd-2-2-1:~# chmod +x /usr/bin/kubelet
69+
root@kubernetes-1-35-1-containerd-2-2-1:~# systemctl start kubelet
70+
```
71+
72+
### Restore Containerd
73+
74+
```shell
75+
root@kubernetes-1-35-1-containerd-2-2-1:~# systemctl stop containerd
76+
root@kubernetes-1-35-1-containerd-2-2-1:~# cp /usr/local/bin/containerd.real /usr/local/bin/containerd
77+
root@kubernetes-1-35-1-containerd-2-2-1:~# chmod +x /usr/local/bin/containerd
78+
root@kubernetes-1-35-1-containerd-2-2-1:~# systemctl start containerd
4779
```
4880

4981
### Built-in Pods
@@ -128,7 +160,7 @@ make all ENV=kubernetes/v1.35.1/containerd/v2.2.1/calico/debug
128160

129161
```dockerfile
130162
# syntax=docker/dockerfile:1-labs
131-
FROM ghcr.io/ctrsploit/kubernetes-v1.35.1_containerd-v2.2.1_calico_debug:ctr_v0.1.0
163+
FROM ghcr.io/ctrsploit/kubernetes-v1.35.1_containerd-v2.2.1_calico_debug:ctr_v0.2.0
132164
...
133165
RUN --security=insecure ["/sbin/init", "--log-target=kmsg"]
134166
```

kubernetes/v1.35.1/containerd/v2.2.1/calico/debug/docker-compose.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@ services:
66
environment:
77
- "QEMU_NET=10.0.2.0/24"
88
- "QEMU_DHCPSTART=10.0.2.16"
9-
- "QEMU_HOSTFWD=hostfwd=tcp::6443-:6443,hostfwd=tcp::2345-:2345"
9+
- "QEMU_HOSTFWD=hostfwd=tcp::6443-:6443,hostfwd=tcp::2345-:2345,hostfwd=tcp::2346-:2346"
1010
ports:
1111
- "13514:22"
1212
- "13515:6443"
1313
- "13516:2345"
14+
- "13517:2346"
1415
tty: true
1516
stdin_open: true

0 commit comments

Comments
 (0)