Skip to content

Commit

Permalink
Add Pod Toolbox features to the container (#50)
Browse files Browse the repository at this point in the history
* container: Add tools/scripts/docs for troubleshooting.
* Add iproute2
  • Loading branch information
bzub committed Jul 11, 2017
1 parent 6aa58c2 commit f0d5947
Show file tree
Hide file tree
Showing 8 changed files with 221 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/kube-router
/gobgp
27 changes: 23 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
FROM alpine
RUN apk add --no-cache iptables ipset
COPY kube-router /
FROM alpine:3.6

ENTRYPOINT ["/kube-router"]
COPY kube-router gobgp /usr/local/bin/
COPY build/image-assets/bashrc /root/.bashrc
COPY build/image-assets/profile /root/.profile
COPY build/image-assets/vimrc /root/.vimrc
COPY build/image-assets/motd-kube-router.sh /etc/motd-kube-router.sh

RUN apk add --no-cache \
iptables \
ipset \
iproute2 \
ipvsadm \
curl \
bash && \
mkdir -p /var/lib/gobgp && \
mkdir -p /usr/local/share/bash-completion && \
curl -L -o /usr/local/share/bash-completion/bash-completion \
https://raw.githubusercontent.com/scop/bash-completion/master/bash_completion && \
cd && \
/usr/local/bin/gobgp --gen-cmpl --bash-cmpl-file /var/lib/gobgp/gobgp-completion.bash

WORKDIR "/root"
ENTRYPOINT ["/usr/local/bin/kube-router"]
80 changes: 80 additions & 0 deletions Documentation/pod-toolbox.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# Pod Toolbox

When kube-router is ran as a Pod within your Kubernetes cluster, it also ships
with a number of tools automatically configured for your cluster. These can be
used to troubleshoot issues and learn more about how cluster networking is
performed.

## Logging In

Here's a quick way to get going on a random node in your cluster:
```
KR_POD="basename $(kubectl -n kube-system get pods -l k8s-app=kube-router --output name|head -n1)"
kubectl -n kube-system exec -it ${KR_POD} bash
```

Use `kubectl -n kube-system get pods -l k8s-app=kube-router -o wide` to see what
nodes are running which pods. This will help if you want to investigate a
particular node.

## Tools And Usage

Once logged in you will see some help on using the tools in the container.

For example:
```console
Welcome to kube-router on "node1.zbrbdl"!

For debugging, the following tools are available:
- ipvsadm | Gather info about Virtual Services and Real Servers via IPVS.
| Examples:
| ## Show all options
| ipvsadm --help
| ## List Services and Endpoints handled by IPVS
| ipvsadm -ln
| ## Show traffic rate information
| ipvsadm -ln --rate
| ## Show cumulative traffic
| ipvsadm -ln --stats

- gobgp | Get BGP related information from your nodes.
|
| Tab-completion is ready to use, just type "gobgp <TAB>"
| to see the subcommands available.
|
| By default gobgp will query the Node this Pod is running
| on, i.e. "node1.zbrbdl". To query a different node use
| "gobgp --host node02.mydomain" as an example.
|
| For more examples see: https://github.com/osrg/gobgp/blob/master/docs/sources/cli-command-syntax.md

Here's a quick look at what's happening on this Node
--- BGP Server Configuration ---
AS: 64512
Router-ID: 10.10.3.2
Listening Port: 179, Addresses: 0.0.0.0, ::

--- BGP Neighbors ---
Peer AS Up/Down State |#Received Accepted
64512 2d 01:05:07 Establ | 1 1

--- BGP Route Info ---
Network Next Hop AS_PATH Age Attrs
*> 10.2.0.0/24 10.10.3.3 4000 400000 300000 40001 2d 01:05:20 [{Origin: i} {LocalPref: 100}]
*> 10.2.1.0/24 10.10.3.2 4000 400000 300000 40001 00:00:36 [{Origin: i}]

--- IPVS Services ---
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 10.3.0.1:443 rr persistent 10800 mask 0.0.0.0
-> 10.10.3.2:443 Masq 1 0 0
TCP 10.3.0.10:53 rr
-> 10.2.0.2:53 Masq 1 0 0
TCP 10.3.0.15:2379 rr
-> 10.10.3.3:2379 Masq 1 45 0
TCP 10.3.0.155:2379 rr
-> 10.10.3.3:2379 Masq 1 0 0
UDP 10.3.0.10:53 rr
-> 10.2.0.2:53 Masq 1 0 0
```
9 changes: 8 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ test: gofmt ## Runs code quality pipelines (gofmt, tests, coverage, lint, etc)
run: kube-router ## Runs "kube-router --help".
./kube-router --help

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

gobgp:
$(DOCKER) run -v $(PWD):/pwd golang:alpine \
sh -c ' \
apk add -U git && \
CGO_ENABLED=0 go get github.com/osrg/gobgp/gobgp && \
cp /go/bin/gobgp /pwd'

# http://marmelab.com/blog/2016/02/29/auto-documented-makefile.html
help:
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | \
Expand Down
51 changes: 51 additions & 0 deletions build/image-assets/bashrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# print motd
/etc/motd-kube-router.sh

# append to the history file, don't overwrite it
shopt -s histappend

# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
HISTSIZE=1000
HISTFILESIZE=2000

# check the window size after each command and, if necessary,
# update the values of LINES and COLUMNS.
shopt -s checkwinsize

# colour Definitions for .bashrc
COL_YEL="\[\e[1;33m\]"
COL_GRA="\[\e[0;37m\]"
COL_WHI="\[\e[1;37m\]"
COL_GRE="\[\e[1;32m\]"
COL_RED="\[\e[1;31m\]"
COL_BLU="\[\e[1;34m\]"

# Bash Prompt
if test "$UID" -eq 0 ; then
_COL_USER=$COL_RED
_p=" #"
else
_COL_USER=$COL_GRE
_p=">"
fi

# Bash Prompt
if test "$UID" -eq 0 ; then
_COL_USER=$COL_RED
_p=" #"
else
_COL_USER=$COL_GRE
_p=">"
fi

COLORIZED_PROMPT="${_COL_USER}\u${COL_WHI}@${COL_YEL}\h${COL_WHI}:${COL_BLU}\w${_p}\[\e[m\]"

case $TERM in
*term | rxvt | screen | linux )
PS1="${COLORIZED_PROMPT}" ;;
* )
PS1="\u@\h:\w${_p} " ;;
esac

source /usr/local/share/bash-completion/bash-completion
source /var/lib/gobgp/gobgp-completion.bash
40 changes: 40 additions & 0 deletions build/image-assets/motd-kube-router.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/usr/bin/env sh

echo "Welcome to kube-router on \"${NODE_NAME}\"!"
echo
echo "For debugging, the following tools are available:"
echo "- ipvsadm | Gather info about Virtual Services and Real Servers via IPVS."
echo " | Examples:"
echo " | ## Show all options"
echo " | ipvsadm --help"
echo " | ## List Services and Endpoints handled by IPVS"
echo " | ipvsadm -ln"
echo " | ## Show traffic rate information"
echo " | ipvsadm -ln --rate"
echo " | ## Show cumulative traffic statistics"
echo " | ipvsadm -ln --stats"
echo
echo "- gobgp | Get BGP related information from your nodes."
echo " | "
echo " | Tab-completion is ready to use, just type \"gobgp <TAB>\""
echo " | to see the subcommands available."
echo " | "
echo " | By default gobgp will query the Node this Pod is running"
echo " | on, i.e. \"${NODE_NAME}\". To query a different node use"
echo " | \"gobgp --host node02.mydomain\" for example."
echo " | "
echo " | Examples: See https://github.com/osrg/gobgp/blob/master/docs/sources/cli-command-syntax.md"
echo
echo "Here's a quick look at what's happening on this Node"
echo "--- BGP Server Configuration ---"
gobgp global
echo
echo "--- BGP Neighbors ---"
gobgp neighbor
echo
echo "--- BGP Route Info ---"
gobgp global rib
echo
echo "--- IPVS Services ---"
ipvsadm -ln
echo
15 changes: 15 additions & 0 deletions build/image-assets/profile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export CHARSET=UTF-8
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
export PAGER=less
export PS1='\h:\w\$ '
umask 022

for script in /etc/profile.d/*.sh ; do
if [ -r $script ] ; then
. $script
fi
done

if [ -f /etc/bash.bashrc ]; then
. /etc/bash.bashrc
fi
3 changes: 3 additions & 0 deletions build/image-assets/vimrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
syntax on
set expandtab
set tabstop=2

0 comments on commit f0d5947

Please sign in to comment.