Skip to content

Commit f0d5947

Browse files
authored
Add Pod Toolbox features to the container (#50)
* container: Add tools/scripts/docs for troubleshooting. * Add iproute2
1 parent 6aa58c2 commit f0d5947

File tree

8 files changed

+221
-5
lines changed

8 files changed

+221
-5
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
/kube-router
2+
/gobgp

Dockerfile

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,24 @@
1-
FROM alpine
2-
RUN apk add --no-cache iptables ipset
3-
COPY kube-router /
1+
FROM alpine:3.6
42

5-
ENTRYPOINT ["/kube-router"]
3+
COPY kube-router gobgp /usr/local/bin/
4+
COPY build/image-assets/bashrc /root/.bashrc
5+
COPY build/image-assets/profile /root/.profile
6+
COPY build/image-assets/vimrc /root/.vimrc
7+
COPY build/image-assets/motd-kube-router.sh /etc/motd-kube-router.sh
8+
9+
RUN apk add --no-cache \
10+
iptables \
11+
ipset \
12+
iproute2 \
13+
ipvsadm \
14+
curl \
15+
bash && \
16+
mkdir -p /var/lib/gobgp && \
17+
mkdir -p /usr/local/share/bash-completion && \
18+
curl -L -o /usr/local/share/bash-completion/bash-completion \
19+
https://raw.githubusercontent.com/scop/bash-completion/master/bash_completion && \
20+
cd && \
21+
/usr/local/bin/gobgp --gen-cmpl --bash-cmpl-file /var/lib/gobgp/gobgp-completion.bash
22+
23+
WORKDIR "/root"
24+
ENTRYPOINT ["/usr/local/bin/kube-router"]

Documentation/pod-toolbox.md

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# Pod Toolbox
2+
3+
When kube-router is ran as a Pod within your Kubernetes cluster, it also ships
4+
with a number of tools automatically configured for your cluster. These can be
5+
used to troubleshoot issues and learn more about how cluster networking is
6+
performed.
7+
8+
## Logging In
9+
10+
Here's a quick way to get going on a random node in your cluster:
11+
```
12+
KR_POD="basename $(kubectl -n kube-system get pods -l k8s-app=kube-router --output name|head -n1)"
13+
kubectl -n kube-system exec -it ${KR_POD} bash
14+
```
15+
16+
Use `kubectl -n kube-system get pods -l k8s-app=kube-router -o wide` to see what
17+
nodes are running which pods. This will help if you want to investigate a
18+
particular node.
19+
20+
## Tools And Usage
21+
22+
Once logged in you will see some help on using the tools in the container.
23+
24+
For example:
25+
```console
26+
Welcome to kube-router on "node1.zbrbdl"!
27+
28+
For debugging, the following tools are available:
29+
- ipvsadm | Gather info about Virtual Services and Real Servers via IPVS.
30+
| Examples:
31+
| ## Show all options
32+
| ipvsadm --help
33+
| ## List Services and Endpoints handled by IPVS
34+
| ipvsadm -ln
35+
| ## Show traffic rate information
36+
| ipvsadm -ln --rate
37+
| ## Show cumulative traffic
38+
| ipvsadm -ln --stats
39+
40+
- gobgp | Get BGP related information from your nodes.
41+
|
42+
| Tab-completion is ready to use, just type "gobgp <TAB>"
43+
| to see the subcommands available.
44+
|
45+
| By default gobgp will query the Node this Pod is running
46+
| on, i.e. "node1.zbrbdl". To query a different node use
47+
| "gobgp --host node02.mydomain" as an example.
48+
|
49+
| For more examples see: https://github.com/osrg/gobgp/blob/master/docs/sources/cli-command-syntax.md
50+
51+
Here's a quick look at what's happening on this Node
52+
--- BGP Server Configuration ---
53+
AS: 64512
54+
Router-ID: 10.10.3.2
55+
Listening Port: 179, Addresses: 0.0.0.0, ::
56+
57+
--- BGP Neighbors ---
58+
Peer AS Up/Down State |#Received Accepted
59+
64512 2d 01:05:07 Establ | 1 1
60+
61+
--- BGP Route Info ---
62+
Network Next Hop AS_PATH Age Attrs
63+
*> 10.2.0.0/24 10.10.3.3 4000 400000 300000 40001 2d 01:05:20 [{Origin: i} {LocalPref: 100}]
64+
*> 10.2.1.0/24 10.10.3.2 4000 400000 300000 40001 00:00:36 [{Origin: i}]
65+
66+
--- IPVS Services ---
67+
IP Virtual Server version 1.2.1 (size=4096)
68+
Prot LocalAddress:Port Scheduler Flags
69+
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
70+
TCP 10.3.0.1:443 rr persistent 10800 mask 0.0.0.0
71+
-> 10.10.3.2:443 Masq 1 0 0
72+
TCP 10.3.0.10:53 rr
73+
-> 10.2.0.2:53 Masq 1 0 0
74+
TCP 10.3.0.15:2379 rr
75+
-> 10.10.3.3:2379 Masq 1 45 0
76+
TCP 10.3.0.155:2379 rr
77+
-> 10.10.3.3:2379 Masq 1 0 0
78+
UDP 10.3.0.10:53 rr
79+
-> 10.2.0.2:53 Masq 1 0 0
80+
```

Makefile

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ test: gofmt ## Runs code quality pipelines (gofmt, tests, coverage, lint, etc)
2626
run: kube-router ## Runs "kube-router --help".
2727
./kube-router --help
2828

29-
container: kube-router ## Builds a Docker container image.
29+
container: kube-router gobgp ## Builds a Docker container image.
3030
@echo Starting kube-router container image build.
3131
$(DOCKER) build -t "$(REGISTRY_DEV):$(IMG_TAG)" .
3232
@if [ "$(GIT_BRANCH)" = "master" ]; then \
@@ -119,6 +119,13 @@ else
119119
@echo
120120
endif
121121

122+
gobgp:
123+
$(DOCKER) run -v $(PWD):/pwd golang:alpine \
124+
sh -c ' \
125+
apk add -U git && \
126+
CGO_ENABLED=0 go get github.com/osrg/gobgp/gobgp && \
127+
cp /go/bin/gobgp /pwd'
128+
122129
# http://marmelab.com/blog/2016/02/29/auto-documented-makefile.html
123130
help:
124131
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | \

build/image-assets/bashrc

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# print motd
2+
/etc/motd-kube-router.sh
3+
4+
# append to the history file, don't overwrite it
5+
shopt -s histappend
6+
7+
# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
8+
HISTSIZE=1000
9+
HISTFILESIZE=2000
10+
11+
# check the window size after each command and, if necessary,
12+
# update the values of LINES and COLUMNS.
13+
shopt -s checkwinsize
14+
15+
# colour Definitions for .bashrc
16+
COL_YEL="\[\e[1;33m\]"
17+
COL_GRA="\[\e[0;37m\]"
18+
COL_WHI="\[\e[1;37m\]"
19+
COL_GRE="\[\e[1;32m\]"
20+
COL_RED="\[\e[1;31m\]"
21+
COL_BLU="\[\e[1;34m\]"
22+
23+
# Bash Prompt
24+
if test "$UID" -eq 0 ; then
25+
_COL_USER=$COL_RED
26+
_p=" #"
27+
else
28+
_COL_USER=$COL_GRE
29+
_p=">"
30+
fi
31+
32+
# Bash Prompt
33+
if test "$UID" -eq 0 ; then
34+
_COL_USER=$COL_RED
35+
_p=" #"
36+
else
37+
_COL_USER=$COL_GRE
38+
_p=">"
39+
fi
40+
41+
COLORIZED_PROMPT="${_COL_USER}\u${COL_WHI}@${COL_YEL}\h${COL_WHI}:${COL_BLU}\w${_p}\[\e[m\]"
42+
43+
case $TERM in
44+
*term | rxvt | screen | linux )
45+
PS1="${COLORIZED_PROMPT}" ;;
46+
* )
47+
PS1="\u@\h:\w${_p} " ;;
48+
esac
49+
50+
source /usr/local/share/bash-completion/bash-completion
51+
source /var/lib/gobgp/gobgp-completion.bash
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/usr/bin/env sh
2+
3+
echo "Welcome to kube-router on \"${NODE_NAME}\"!"
4+
echo
5+
echo "For debugging, the following tools are available:"
6+
echo "- ipvsadm | Gather info about Virtual Services and Real Servers via IPVS."
7+
echo " | Examples:"
8+
echo " | ## Show all options"
9+
echo " | ipvsadm --help"
10+
echo " | ## List Services and Endpoints handled by IPVS"
11+
echo " | ipvsadm -ln"
12+
echo " | ## Show traffic rate information"
13+
echo " | ipvsadm -ln --rate"
14+
echo " | ## Show cumulative traffic statistics"
15+
echo " | ipvsadm -ln --stats"
16+
echo
17+
echo "- gobgp | Get BGP related information from your nodes."
18+
echo " | "
19+
echo " | Tab-completion is ready to use, just type \"gobgp <TAB>\""
20+
echo " | to see the subcommands available."
21+
echo " | "
22+
echo " | By default gobgp will query the Node this Pod is running"
23+
echo " | on, i.e. \"${NODE_NAME}\". To query a different node use"
24+
echo " | \"gobgp --host node02.mydomain\" for example."
25+
echo " | "
26+
echo " | Examples: See https://github.com/osrg/gobgp/blob/master/docs/sources/cli-command-syntax.md"
27+
echo
28+
echo "Here's a quick look at what's happening on this Node"
29+
echo "--- BGP Server Configuration ---"
30+
gobgp global
31+
echo
32+
echo "--- BGP Neighbors ---"
33+
gobgp neighbor
34+
echo
35+
echo "--- BGP Route Info ---"
36+
gobgp global rib
37+
echo
38+
echo "--- IPVS Services ---"
39+
ipvsadm -ln
40+
echo

build/image-assets/profile

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
export CHARSET=UTF-8
2+
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
3+
export PAGER=less
4+
export PS1='\h:\w\$ '
5+
umask 022
6+
7+
for script in /etc/profile.d/*.sh ; do
8+
if [ -r $script ] ; then
9+
. $script
10+
fi
11+
done
12+
13+
if [ -f /etc/bash.bashrc ]; then
14+
. /etc/bash.bashrc
15+
fi

build/image-assets/vimrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
syntax on
2+
set expandtab
3+
set tabstop=2

0 commit comments

Comments
 (0)