
Budapesti Mûszaki és Gazdaságtudományi Egyetem Villamosmérnöki és Informatikai Kar Távközlési és Médiainformatikai Tanszék Application of Extended Berkeley Packet Filters in Cloud Environment Diplomaterv Készítette Konzulens Ipari konzulens Bartha Csongor Dr. Simon Csaba Szabó Gergely December 21, 2019 Contents Kivonat 6 Abstract 7 1 Introduction8 2 Berkeley Packet Filter mechanisms and system components9 2.1 Concepts......................................9 2.1.1 Cloud computing.............................9 2.1.2 Kubernetes................................9 2.1.3 User- and kernelspace.......................... 10 2.1.4 System calls................................ 10 2.1.5 Userspace packet-filtering........................ 10 2.2 The classic Berkeley Packet Filters....................... 12 2.2.1 Compiling cBPF............................. 12 2.2.2 PCAP................................... 13 2.2.3 Tcpdump................................. 14 2.3 Extended Berkeley Packet Filters........................ 14 2.3.1 How eBPF works............................. 15 2.3.2 Code verification............................. 16 2.3.3 Compiling eBPF............................. 17 2.3.4 XDP - eXpress Data Path........................ 18 2.3.5 An eBPF vulnerability.......................... 19 2.3.6 The overhead of eBPF.......................... 20 1 2.3.7 Further possibilities........................... 20 2.4 Monitoring toolset................................ 21 2.4.1 Prometheus................................ 21 2.4.2 Grafana.................................. 21 2.4.3 AlertManager............................... 21 2.5 Projects leveraging eBPF technology...................... 21 2.5.1 Tools and libraries using eBPF..................... 23 3 The main approaches of programming eBPF 26 3.1 Raw BPF..................................... 26 3.2 BCC - BPF Compiler Collection........................ 26 3.2.1 Probe-types................................ 27 3.3 High level tracing languages........................... 28 3.3.1 BPFtrace................................. 28 3.3.2 DTrace.................................. 30 3.3.3 Ply..................................... 31 4 eBPF in practice 32 4.1 Using eBPF in Kubernetes............................ 32 4.1.1 Cilium................................... 34 4.1.2 Weave Scope............................... 35 4.2 Tracing and monitoring with BCC and BPFtrace............... 36 4.2.1 BCC.................................... 36 4.2.2 BPFtrace................................. 37 4.3 BCC in practice.................................. 37 4.3.1 The BPF section............................. 38 4.3.2 The Python section............................ 40 4.3.3 Getting data from the kernel...................... 41 4.4 The ebpf-exporter................................ 43 4.4.1 Configuration and structure....................... 43 2 5 The implementation in Kubernetes 45 5.1 The infrastructure of the Kubernetes cluster.................. 46 5.2 Setting up Prometheus.............................. 47 5.2.1 General configuration.......................... 47 5.3 Creating the ebpf exporter............................ 49 5.3.1 The Dockerfile.............................. 49 5.3.2 Privileged mode............................. 50 5.3.3 Accessing the image from Google Cloud Platform........... 51 5.4 Deploying the monitoring stack in Kubernetes................. 52 5.4.1 Deploying the exporter.......................... 52 5.4.2 Deploying Prometheus.......................... 56 5.4.3 Deploying Grafana............................ 62 5.5 The BPF programs in the exporter....................... 63 5.5.1 Cachestat................................. 63 5.5.2 Tcp-counter................................ 64 5.5.3 The resulting time-series......................... 66 6 Measuring system performance 67 6.1 The test system.................................. 67 6.1.1 Using Prometheus............................ 67 6.1.2 The exporters............................... 68 6.1.3 Visualizing the data with Grafana................... 72 6.2 Programs and scripts for testing......................... 73 6.2.1 Testing tcp-counter............................ 73 6.2.2 Testing cachestat............................. 75 6.2.3 The spikes on the graphs........................ 76 6.3 Discussion..................................... 78 7 Summary 79 Bibliography 84 3 Appendices 85 A.1 Filelife....................................... 85 A.2 Ebpf-exporter Dockerfile............................. 87 A.3 The yaml file configuring the ebpf-exporter daemonset............ 88 A.4 The yaml file of the configMap for Prometheus................ 90 4 HALLGATÓI NYILATKOZAT Alulírott Bartha Csongor, szigorló hallgató kijelentem, hogy ezt a diplomatervet meg nem engedett segítség nélkül, saját magam készítettem, csak a megadott forrásokat (szakiro- dalom, eszközök stb.) használtam fel. Minden olyan részt, melyet szó szerint, vagy azonos értelemben, de átfogalmazva más forrásból átvettem, egyértelmûen, a forrás megadásával megjelöltem. Hozzájárulok, hogy a jelen munkám alapadatait (szerzõ(k), cím, angol és magyar nyelvû tartalmi kivonat, készítés éve, konzulens(ek) neve) a BME VIK nyilvánosan hozzáférhetõ elektronikus formában, a munka teljes szövegét pedig az egyetem belsõ hálózatán keresztül (vagy autentikált felhasználók számára) közzétegye. Kijelentem, hogy a benyújtott munka és annak elektronikus verziója megegyezik. Dékáni engedéllyel titkosított diplomatervek esetén a dolgozat szövege csak 3 év eltelte után válik hozzáférhetõvé. Budapest, December 21, 2019 Bartha Csongor hallgató Kivonat A modern felhő alapú megoldások egyik fontos komponense a Kubernetes konténer menedzs- ment rendszer. A Kubernetes klaszterekbe telepített nagy komplexitású szolgáltatások üzemeltetésének elengedhetetlen része a rendszert alkotó konténerek és egyéb erőforrások teljesítményének felügyelete, mivel az jelentős mértékben meghatározza a szolgáltatások minőségét. A szakdolgozatomban bemutatom a hatékony felügyeleti lehetőségeket, valamint az álta- lam egy Kubernetes rendszer teljesítményének monitorozására kiválasztott Berkeley cso- magszűrő új változatát (extended Berkeley Packet Filter - eBPF). Az eBPF egy általános célú Linux kernel mechanizmus, mely a felhasználói térben leírt csomagkezelési szabályokon túl egyszerű programok futtatását is lehetővé teszi a kernelben különféle csatlakozási pon- tok használatával ("probe"), ami által tetszőleges adatok nyerhetők ki az adott rendszerről. Részletesen bemutatom az eBPF programozás menetét és áttekintem a jelenleg elérhető fontosabb eBPF alapú felhasználási eseteket. Bemutatom egy eBPF alapú Kubernetes monitorozási rendszer tervét, annak alkotóelemeit és a megvalósítás lépéseit. Mérések alapján megvizsgálom, hogy miként lehet alkalmazni két erőforrástípus (TCP hálózati forgalom és cache memória) monitorozására. Dolgozatomat az eredmények értékelésével és a jövőbeli bővítési lehetőségekkel zárom. 6 Abstract The wide-scale adoption of container-based virtualization technologies is supported by the Kubernetes container management system, which provides the required tools to implement reliable and scalable services. It is inevitable to create a monitoring system for the con- tainers and all kinds of computing resources that make up a Kubernetes cluster, when operating services of great complexity, as it influences the quality of those services to a great extent. In my thesis, I present, how the Berkeley Packet Filter, and especially its enhanced version (the extended Berkeley Packet Filter - eBPF) can be used for detailed monitoring of cloud systems. The eBPF is a Linux kernel mechanism, that lets executing packet filtering and other small programs of data collecting purpose inside the kernel, that was written in the user space, by using different kinds of probes. I present eBPF in detail, including its programming possibilities and its applications, with special focus on the networking and monitoring areas. I also illustrate the more important use cases related to eBPF, that are currently available. I present the design of an eBPF-based Kubernetes monitoring system along with its com- ponents and also the detailed steps of its implementation. I examine, how this system can be used for collecting metrics and monitoring two kinds of resources (TCP network traffic and cache memory). I finish my thesis evaluating the results of the measurements with the help of some of the most popular monitoring tools, and also cover the topic of how this system could be extended in the future. 7 1. Introduction Nowadays, more and more companies and projects shift their focus on container-based virtualization. Containers have taken the place of virtual machines in many different areas, especially in cloud services, due to the containers’ much higher performance and lower costs in the first place. The cloud model provides convenient, on-demand access for customiz- able, shared resources like servers, networks, services, etc. with ideal operational managing costs compared to traditional models. Cloud services are also scalable and provide high availability. One of the fundamental concepts processed in this thesis is the Berkeley Packet Filter (BPF), which is an in-kernel virtual machine with the initial purpose of network packet filtering and processing [39]. The later iterations of BPF called Extended Berkeley Packet Filters (eBPF), however, offer many more possibilities - the ability to define programs in the user-space and executing them in the kernel in a protocol-independent way, while saving a great amount of
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages91 Page
-
File Size-