61
Alban Crequy Exploration of Linux Container Network Monitoring and Visualization ContainerCon Europe - October 2016 https://goo.gl/iDL8te

Visualization Network Monitoring and Exploration of Linux ... · Exploration of Linux Container Network Monitoring and Visualization ContainerCon Europe - October 2016 ... ∘Microservices

  • Upload
    others

  • View
    12

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Visualization Network Monitoring and Exploration of Linux ... · Exploration of Linux Container Network Monitoring and Visualization ContainerCon Europe - October 2016 ... ∘Microservices

Alban Crequy

Exploration of Linux Container Network Monitoring and

Visualization

ContainerCon Europe - October 2016https://goo.gl/iDL8te

Page 2: Visualization Network Monitoring and Exploration of Linux ... · Exploration of Linux Container Network Monitoring and Visualization ContainerCon Europe - October 2016 ... ∘Microservices

Alban Crequy

∘ Worked on the rkt container run-time∘ Contributed to systemd

https://github.com/alban

Page 3: Visualization Network Monitoring and Exploration of Linux ... · Exploration of Linux Container Network Monitoring and Visualization ContainerCon Europe - October 2016 ... ∘Microservices

Berlin-based software company building foundational Linux technologies

Some examples of what we work on...

OSTreegit for operating system binaries

Page 4: Visualization Network Monitoring and Exploration of Linux ... · Exploration of Linux Container Network Monitoring and Visualization ContainerCon Europe - October 2016 ... ∘Microservices

Find out more about us…

Blog: https://kinvolk.io/blog

Github: https://github.com/kinvolk

Twitter: https://twitter.com/kinvolkio

Email: [email protected]

Page 5: Visualization Network Monitoring and Exploration of Linux ... · Exploration of Linux Container Network Monitoring and Visualization ContainerCon Europe - October 2016 ... ∘Microservices

∘ First use-case: visualizing tcp connections∘ Microservices application with containers: Weave Socks∘ CoreOS Linux, Kubernetes, Weave Scope

∘ Using /proc & conntrack∘ Limitations∘ proc connector, eBPF & kprobes

∘ Next use cases:∘ L7, HTTP: eBPF & kprobes∘ Simulating degraded networks with traffic control

Plan

Page 6: Visualization Network Monitoring and Exploration of Linux ... · Exploration of Linux Container Network Monitoring and Visualization ContainerCon Europe - October 2016 ... ∘Microservices

The demo application

Page 7: Visualization Network Monitoring and Exploration of Linux ... · Exploration of Linux Container Network Monitoring and Visualization ContainerCon Europe - October 2016 ... ∘Microservices

microservices-demo

https://github.com/microservices-demo/microservices-demo

Page 8: Visualization Network Monitoring and Exploration of Linux ... · Exploration of Linux Container Network Monitoring and Visualization ContainerCon Europe - October 2016 ... ∘Microservices

Some micro-services

front-end Firefox

catalogue

ordersorders-db

payment

Page 9: Visualization Network Monitoring and Exploration of Linux ... · Exploration of Linux Container Network Monitoring and Visualization ContainerCon Europe - October 2016 ... ∘Microservices
Page 10: Visualization Network Monitoring and Exploration of Linux ... · Exploration of Linux Container Network Monitoring and Visualization ContainerCon Europe - October 2016 ... ∘Microservices

Orchestrating containersWith Kubernetes

Page 11: Visualization Network Monitoring and Exploration of Linux ... · Exploration of Linux Container Network Monitoring and Visualization ContainerCon Europe - October 2016 ... ∘Microservices

Kubernetes Replica Sets

Kubernetesnode 1

front-end

Kubernetesnode 2

front-end

Kubernetesnode 3

ordersorders

catalogue catalogue

Page 12: Visualization Network Monitoring and Exploration of Linux ... · Exploration of Linux Container Network Monitoring and Visualization ContainerCon Europe - October 2016 ... ∘Microservices

Kubernetesnode 1

front-end

Kubernetesnode 2

front-end

Kubernetesnode 3

ordersorders

Kubernetes Services

orders service

Page 13: Visualization Network Monitoring and Exploration of Linux ... · Exploration of Linux Container Network Monitoring and Visualization ContainerCon Europe - October 2016 ... ∘Microservices

Kubernetes ServicesProxying the traffic from the virtual service IP to a Kubernetes pod

Several implementations possible:

- Userspace proxy in kube-proxy- Iptables rules (Destination NAT) installed by kube-proxy- Cilium implements a load balancer based on eBPF (tc level)

Page 14: Visualization Network Monitoring and Exploration of Linux ... · Exploration of Linux Container Network Monitoring and Visualization ContainerCon Europe - October 2016 ... ∘Microservices

Weave Scope

Page 15: Visualization Network Monitoring and Exploration of Linux ... · Exploration of Linux Container Network Monitoring and Visualization ContainerCon Europe - October 2016 ... ∘Microservices

Weave Scope

Page 16: Visualization Network Monitoring and Exploration of Linux ... · Exploration of Linux Container Network Monitoring and Visualization ContainerCon Europe - October 2016 ... ∘Microservices

Weave Scope

demo

Page 17: Visualization Network Monitoring and Exploration of Linux ... · Exploration of Linux Container Network Monitoring and Visualization ContainerCon Europe - October 2016 ... ∘Microservices

procfs

Page 18: Visualization Network Monitoring and Exploration of Linux ... · Exploration of Linux Container Network Monitoring and Visualization ContainerCon Europe - October 2016 ... ∘Microservices

procfs files- /proc/$PID- /proc/$PID/ns/net network namespace- /proc/$PID/fd/ file descriptors- /proc/$PID/net/tcp tcp connections

Page 19: Visualization Network Monitoring and Exploration of Linux ... · Exploration of Linux Container Network Monitoring and Visualization ContainerCon Europe - October 2016 ... ∘Microservices

procfs files

Page 20: Visualization Network Monitoring and Exploration of Linux ... · Exploration of Linux Container Network Monitoring and Visualization ContainerCon Europe - October 2016 ... ∘Microservices

procfs limitations- No notifications- Need to read procfs for

- new processes- new network namespaces- new sockets- every second?

- CPU intensive for systems with high number of processes- Missing short-lived connections- Issues with packet modifications (e.g. DNAT)

Page 21: Visualization Network Monitoring and Exploration of Linux ... · Exploration of Linux Container Network Monitoring and Visualization ContainerCon Europe - October 2016 ... ∘Microservices

Packet modifications

Local process

Socket lookup

Traffic control, ingress

packet

Protocol layer

Network layer

Link layer

Local process

NAT

Traffic control, egress

Kubernetes node 1 Kubernetes node 2

Page 22: Visualization Network Monitoring and Exploration of Linux ... · Exploration of Linux Container Network Monitoring and Visualization ContainerCon Europe - October 2016 ... ∘Microservices

Netlink

Page 23: Visualization Network Monitoring and Exploration of Linux ... · Exploration of Linux Container Network Monitoring and Visualization ContainerCon Europe - October 2016 ... ∘Microservices

Netlink socketssocket(AF_NETLINK, SOCK_RAW, NETLINK_...);

Several Netlink sockets:

- NETLINK_ROUTE- NETLINK_INET_DIAG- NETLINK_SELINUX- NETLINK_CONNECTOR- NETLINK_NETFILTER- ...

Page 24: Visualization Network Monitoring and Exploration of Linux ... · Exploration of Linux Container Network Monitoring and Visualization ContainerCon Europe - October 2016 ... ∘Microservices

conntrack

Page 25: Visualization Network Monitoring and Exploration of Linux ... · Exploration of Linux Container Network Monitoring and Visualization ContainerCon Europe - October 2016 ... ∘Microservices

conntrack -E- Use NETLINK_NETFILTER sockets to subscribe to Conntrack events

from the kernel - Is aware of NAT rewritings

Page 26: Visualization Network Monitoring and Exploration of Linux ... · Exploration of Linux Container Network Monitoring and Visualization ContainerCon Europe - October 2016 ... ∘Microservices

conntrack limitations- Conntrack events don’t include:

- Process ID- Network namespace ID

- Conntrack zones included but not necessary used by container run-times

- So harvesting procfs regularly still necessary

Page 27: Visualization Network Monitoring and Exploration of Linux ... · Exploration of Linux Container Network Monitoring and Visualization ContainerCon Europe - October 2016 ... ∘Microservices

Other kind of Netlink sockets?

Page 28: Visualization Network Monitoring and Exploration of Linux ... · Exploration of Linux Container Network Monitoring and Visualization ContainerCon Europe - October 2016 ... ∘Microservices

NETLINK_INET_DIAGsocket(AF_NETLINK, SOCK_RAW, NETLINK_INET_DIAG);

- Fetch information about sockets- Used by ss (“another utility to investigate sockets”)- Basic bytecode to filter the sockets (e.g. “INET_DIAG_BC_JMP”)

- But no notification mechanism- Patch “sock_diag: notify packet socket creation/deletion” (2013)

rejected

Page 29: Visualization Network Monitoring and Exploration of Linux ... · Exploration of Linux Container Network Monitoring and Visualization ContainerCon Europe - October 2016 ... ∘Microservices

Kernel Connectorsocket(AF_NETLINK, SOCK_RAW, NETLINK_CONNECTOR);

Several Kernel Connector agents:

- Device mapper- HyperV- Proc connector

Page 30: Visualization Network Monitoring and Exploration of Linux ... · Exploration of Linux Container Network Monitoring and Visualization ContainerCon Europe - October 2016 ... ∘Microservices

Proc connectorbind(sockfd, ...CN_IDX_PROC...);

sendmsg(sockfd, ...PROC_CN_MCAST_LISTEN...)

- Since Linux v2.6.15 (January 2006)

Notifications for:

- fork- exec- exit

Page 31: Visualization Network Monitoring and Exploration of Linux ... · Exploration of Linux Container Network Monitoring and Visualization ContainerCon Europe - October 2016 ... ∘Microservices

Proc connectorMissing:

- network namespace- RFC patch “proc connector: add namespace events” last month

https://lkml.org/lkml/2016/9/8/588- Sockets

So harvesting procfs regularly still necessary

Page 32: Visualization Network Monitoring and Exploration of Linux ... · Exploration of Linux Container Network Monitoring and Visualization ContainerCon Europe - October 2016 ... ∘Microservices

Proc connector

demo

Page 33: Visualization Network Monitoring and Exploration of Linux ... · Exploration of Linux Container Network Monitoring and Visualization ContainerCon Europe - October 2016 ... ∘Microservices

BPF

Page 34: Visualization Network Monitoring and Exploration of Linux ... · Exploration of Linux Container Network Monitoring and Visualization ContainerCon Europe - October 2016 ... ∘Microservices

Classic BPF (cBPF)

socket

kernel

userspace

BPF_JMP...BPF_LD...BPF_RET...

setsockopt(sockfd,SOL_SOCKET,SO_ATTACH_FILTER,&bpf, sizeof(bpf));recvfrom()

Page 35: Visualization Network Monitoring and Exploration of Linux ... · Exploration of Linux Container Network Monitoring and Visualization ContainerCon Europe - October 2016 ... ∘Microservices

Extended BPF (or eBPF)Program type:

- BPF_PROG_TYPE_SOCKET_FILTER- BPF_PROG_TYPE_KPROBE- BPF_PROG_TYPE_SCHED_CLS- BPF_PROG_TYPE_SCHED_ACT- BPF_PROG_TYPE_TRACEPOINT (Linux >= 4.7)- BPF_PROG_TYPE_XDP

Page 36: Visualization Network Monitoring and Exploration of Linux ... · Exploration of Linux Container Network Monitoring and Visualization ContainerCon Europe - October 2016 ... ∘Microservices

eBPF classifier for qdiscs

eth0

classifier

kernel

userspace

BPF_JMP...BPF_LD...BPF_RET...

if (skb->protocol…) return TC_H_MAKE(TC_H_ROOT, mark); compilation

clang... -march=bpf

uploadin the kernel:

- bpf()- Netlink

x86_64 codeJIT compilation

Page 37: Visualization Network Monitoring and Exploration of Linux ... · Exploration of Linux Container Network Monitoring and Visualization ContainerCon Europe - October 2016 ... ∘Microservices

eBPF maps

kernel

userspace

x86_64 code

eBPF maps

Userspace program

∘ Keep context between calls∘ Report statistics to userspace

Page 38: Visualization Network Monitoring and Exploration of Linux ... · Exploration of Linux Container Network Monitoring and Visualization ContainerCon Europe - October 2016 ... ∘Microservices

Tracepoints with eBPF- BPF_PROG_TYPE_TRACEPOINT since Linux 4.7- Find the list of tracepoints in /sys/kernel/debug/tracing/events- Stable API- But limited tracepoints

Page 39: Visualization Network Monitoring and Exploration of Linux ... · Exploration of Linux Container Network Monitoring and Visualization ContainerCon Europe - October 2016 ... ∘Microservices

kprobes with eBPF- BPF_PROG_TYPE_KPROBE since Linux 4.1- No ABI guarantees- Probe any kernel function

Page 40: Visualization Network Monitoring and Exploration of Linux ... · Exploration of Linux Container Network Monitoring and Visualization ContainerCon Europe - October 2016 ... ∘Microservices

Socket events with kprobe / eBPF- BPF Compiler Collection (BCC)

- bcc/examples/tracing/tcpv4connect.py- Iago’s tcp4tracer (WIP)

- Get connection tuple, pid, netns- tcp_v4_connect- tcp_close- inet_csk_accept

Page 41: Visualization Network Monitoring and Exploration of Linux ... · Exploration of Linux Container Network Monitoring and Visualization ContainerCon Europe - October 2016 ... ∘Microservices

Packet modifications

Local process

Socket lookup

Traffic control, ingress

packet

Protocol layer

Network layer

Link layer

Local process

NAT

Traffic control, egress

Kubernetes node 1 Kubernetes node 2

Page 42: Visualization Network Monitoring and Exploration of Linux ... · Exploration of Linux Container Network Monitoring and Visualization ContainerCon Europe - October 2016 ... ∘Microservices

tcp4tracer & NAT- The connection tuple from the process’ point of view is not enough

- NAT- Kubernetes Services

- Iago’s tcp4tracer (WIP)- nf_nat_ipv4_manip_pkt- nf_nat_tcp_manip_pkt

Page 43: Visualization Network Monitoring and Exploration of Linux ... · Exploration of Linux Container Network Monitoring and Visualization ContainerCon Europe - October 2016 ... ∘Microservices

More metrics

Page 44: Visualization Network Monitoring and Exploration of Linux ... · Exploration of Linux Container Network Monitoring and Visualization ContainerCon Europe - October 2016 ... ∘Microservices

Weave Scope architecture

Kubernetesnode 1

Kubernetesnode 2

Scope App

Scope Probe

Firefox

Scope Probe

Page 45: Visualization Network Monitoring and Exploration of Linux ... · Exploration of Linux Container Network Monitoring and Visualization ContainerCon Europe - October 2016 ... ∘Microservices

Weave Scope plugins

Kubernetesnode 1

Kubernetesnode 2

Scope App

Scope Probe

Firefox

Scope Probe

plugin plugin plugin plugin

Page 46: Visualization Network Monitoring and Exploration of Linux ... · Exploration of Linux Container Network Monitoring and Visualization ContainerCon Europe - October 2016 ... ∘Microservices
Page 47: Visualization Network Monitoring and Exploration of Linux ... · Exploration of Linux Container Network Monitoring and Visualization ContainerCon Europe - October 2016 ... ∘Microservices

HTTP requests plugin- Number of HTTP requests per second- Without instrumenting the application- eBPF kprobe on skb_copy_datagram_iter

kernel

userspace

HTTP serverHTTP client

recvfrom()sendmsg()

GET / HTTP/1.1 skb_copy_datagram_iter()copies the skb into the iovec

Page 48: Visualization Network Monitoring and Exploration of Linux ... · Exploration of Linux Container Network Monitoring and Visualization ContainerCon Europe - October 2016 ... ∘Microservices

HTTP responses plugin- Number of HTTP responses by category (404, etc.)- Without instrumenting the application- eBPF kprobe on skb_copy_datagram_from_iter- Using an eBPF map to track the context between kprobe & kretprobe

kernel

userspace

HTTP serverHTTP client

sendmsg()recvfrom()

HTTP/1.0 200 OK skb_copy_datagram_from_iter()copies the iovec into the skb

Page 49: Visualization Network Monitoring and Exploration of Linux ... · Exploration of Linux Container Network Monitoring and Visualization ContainerCon Europe - October 2016 ... ∘Microservices

Testing degraded networks

Page 50: Visualization Network Monitoring and Exploration of Linux ... · Exploration of Linux Container Network Monitoring and Visualization ContainerCon Europe - October 2016 ... ∘Microservices

Traffic control, why?

web server client

client

client

THEINTERNET

∘ fair distribution of bandwidth

∘ reserve bandwidth to specific applications

∘ avoid bufferbloat

Page 51: Visualization Network Monitoring and Exploration of Linux ... · Exploration of Linux Container Network Monitoring and Visualization ContainerCon Europe - October 2016 ... ∘Microservices

∘ Network scheduling algorithm∘ which packet to emit next?∘ when?

∘ Configurable at run-time:∘ /sbin/tc∘ Netlink

∘ Default on new network interfaces: sysctl net.core.default_qdisc

Queuing disciplines(qdisc)

eth0 THE INTERNETqdisc

Page 52: Visualization Network Monitoring and Exploration of Linux ... · Exploration of Linux Container Network Monitoring and Visualization ContainerCon Europe - October 2016 ... ∘Microservices

Stochastic FairnessQueueing (sfq)

eth0

THE INTERNET

FIFO n

FIFO 1

FIFO 0

...

round robin

Page 53: Visualization Network Monitoring and Exploration of Linux ... · Exploration of Linux Container Network Monitoring and Visualization ContainerCon Europe - October 2016 ... ∘Microservices

Demo

Reproduce this demo yourself: https://github.com/kinvolk/demo

Page 54: Visualization Network Monitoring and Exploration of Linux ... · Exploration of Linux Container Network Monitoring and Visualization ContainerCon Europe - October 2016 ... ∘Microservices

Network emulator(netem)

eth0 THE INTERNETnetem

bandwidth

latency packet loss

corrupt...

Page 55: Visualization Network Monitoring and Exploration of Linux ... · Exploration of Linux Container Network Monitoring and Visualization ContainerCon Europe - October 2016 ... ∘Microservices

Testing with containers

container 1 container 2

eth0eth0

Testing framework

configure “netem” qdiscs:bandwidth, latency, packet drop...

Page 56: Visualization Network Monitoring and Exploration of Linux ... · Exploration of Linux Container Network Monitoring and Visualization ContainerCon Europe - October 2016 ... ∘Microservices

Add latency on a specific connection

front-end Firefox

catalogue

ordersorders-db

payment

latency=100ms

Page 57: Visualization Network Monitoring and Exploration of Linux ... · Exploration of Linux Container Network Monitoring and Visualization ContainerCon Europe - October 2016 ... ∘Microservices

How to define classes of traffic

eth0

netem

interface

latency=100ms

dest_ip=10.0.4.* dest_ip=10.0.5.* other

Page 58: Visualization Network Monitoring and Exploration of Linux ... · Exploration of Linux Container Network Monitoring and Visualization ContainerCon Europe - October 2016 ... ∘Microservices

u32: filter on contenteth0

HTB

HTB

HTBHTB HTB

netemnetem netem

interface

root qdisc (type = HTB)

root class (type = HTB)

leaf qdiscs (type = netem)

leaf classes (type = HTB)

filters (type=u32)

otherip=10.0.5.*ip=10.0.4.*

latency=10ms

Page 59: Visualization Network Monitoring and Exploration of Linux ... · Exploration of Linux Container Network Monitoring and Visualization ContainerCon Europe - October 2016 ... ∘Microservices

Filtering with cBPF/eBPF

eth0

BPF

netemnetem

kernel

userspace

BPF_JMP...BPF_LD...BPF_RET...

if (skb->protocol…) return TC_H_MAKE(TC_H_ROOT, mark); compilation

clang... -march=bpf

uploadin the kernel:

- bpf()- Netlink

x86_64 codeJIT compilation

Page 60: Visualization Network Monitoring and Exploration of Linux ... · Exploration of Linux Container Network Monitoring and Visualization ContainerCon Europe - October 2016 ... ∘Microservices

eBPF maps

eth0

BPF

netemnetem

kernel

userspace

x86_64 code

eBPF map

tc

Page 61: Visualization Network Monitoring and Exploration of Linux ... · Exploration of Linux Container Network Monitoring and Visualization ContainerCon Europe - October 2016 ... ∘Microservices

Questions?The slides: https://goo.gl/iDL8te