Useful tools for network debugging in kubernetes

ยท 1 min read

Create a light weight Deployment for miscellaneous testing:

apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: example-app
  name: example-app
  namespace: debug
spec:
  revisionHistoryLimit: 1
  selector:
    matchLabels:
      app: example-app
  template:
    metadata:
      labels:
        app: example-app
    spec:
      containers:
        - args:
            - |
              mkdir -p /www && \
              echo "<div>${MESSAGE}</div" > /www/index.html && \
              httpd -f -p 0.0.0.0:${PORT} -h /www
          command:
            - /bin/sh
            - -c
          env:
            - name: MESSAGE
              value: "hello world!"
            - name: PORT
              value: "80"
          image: busybox:1.36.1
          name: busybox-httpd
          ports:
            - containerPort: 80

Launch a "one-off" container with useful network debugging tools.

kubectl run --rm utils-debug -n debug -it --image arunvelsriram/utils bash

Alternatively, attach a debug container with useful network debugging tools to a running Pod

kubectl debug my-running-pod -it \
  --image=nicolaka/netshoot -n example

Curl

curl domain.example.com

Ping

Useful for checking ICMP works

ping domain.example.com

Use dig for multiple DNS record checks

dig +short my.example.com

# Output is the resolved IP
34.00.00.100

dig +short examples.xyz NS

# Output shows the nameservers in this case cloudflare
gabe.ns.cloudflare.com.
kehlani.ns.cloudflare.com.

Useful curl command to quickly check if a load balancer is routing traffic as expected between different subdomains. Examples this will allow you to debug if Istio's ingress-gateway and VirtualService's are working as expected; or if kubernetes/ingress-nginx and Ingress per namespace are working. This will work even if the A record is still not pointing to the IP of the load balancer.

curl 34.00.000.000 -l -H "Host:subdomain.example.com"

# Output should return service response as expected

Check a domain resolves to expected IP with nslookup

nslookup example.foobar.com

#output
Server:		8.8.8.8
Address:	8.8.8.8#53

Non-authoritative answer:
Name:	example.foobar.com
Address: 34.01.091.101