<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Darek Barecki</title>
    <description>The latest articles on DEV Community by Darek Barecki (@bareckidarek).</description>
    <link>https://dev.to/bareckidarek</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F899011%2F61035fe3-08b4-4ba5-8dc5-705b4ca6a066.png</url>
      <title>DEV Community: Darek Barecki</title>
      <link>https://dev.to/bareckidarek</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/bareckidarek"/>
    <language>en</language>
    <item>
      <title>TCP packets traffic visualization for kubernetes by k8spacket and Grafana</title>
      <dc:creator>Darek Barecki</dc:creator>
      <pubDate>Tue, 09 Aug 2022 11:18:00 +0000</pubDate>
      <link>https://dev.to/bareckidarek/tcp-packets-traffic-visualization-for-kubernetes-by-k8spacket-and-grafana-422c</link>
      <guid>https://dev.to/bareckidarek/tcp-packets-traffic-visualization-for-kubernetes-by-k8spacket-and-grafana-422c</guid>
      <description>&lt;p&gt;Do you know what your k8s cluster does when you are not watching? Who establishes the TCP communication with him? Who is called by him, e.g., from third-party libraries?&lt;/p&gt;

&lt;p&gt;With &lt;code&gt;k8spacket&lt;/code&gt; and &lt;code&gt;Grafana&lt;/code&gt;, you can visualize TCP traffic in the cluster. See how your workloads communicate together. Inspect how many connections are established, how many bytes are exchanged, and how long these connections are active.&lt;br&gt;
 &lt;/p&gt;
&lt;h3&gt;
  
  
  Description
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;k8spacket&lt;/code&gt; is the tool written in Golang and uses the &lt;code&gt;gopacket&lt;/code&gt; third-party library to sniff TCP packets on your workloads (incoming and outgoing). It creates TCP listeners on running container network interfaces. When Kubernetes creates a new container, the CNI plugin is responsible for giving the possibility to communicate either with other containers or from cluster to the world. The most common approach uses &lt;code&gt;linux namespace&lt;/code&gt; to isolate networks and &lt;code&gt;veth pair&lt;/code&gt; to connect the isolated namespace with the bridge. If you want to know more, please refer to a great article written by Safak (&lt;a href="https://dev.to/polarbit/how-docker-container-networking-works-mimic-it-using-linux-network-namespaces-9mj"&gt;How Docker Container Networking Works - Mimic It Using Linux Network Namespaces&lt;/a&gt;). Besides type &lt;code&gt;bridge&lt;/code&gt;, the CNI plugin can use other types (&lt;code&gt;vlan&lt;/code&gt;, &lt;code&gt;ipvlan&lt;/code&gt;, &lt;code&gt;macvlan&lt;/code&gt;), but all create a network interface for container linux namespace, which is the main handle for &lt;code&gt;k8spacket&lt;/code&gt; sniffers. &lt;/p&gt;

&lt;p&gt;&lt;code&gt;k8spacket&lt;/code&gt; is running with the option&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;hostNetwork: true
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;to eliminate the isolation mentioned earlier. It collects TCP streams, processes data, and exposes results through API to be used by &lt;code&gt;Grafana&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Additionally, &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;k8spacket&lt;/code&gt; is a Kubernetes API client and can resolve sniffed workload as a cluster resource name (&lt;code&gt;Pods&lt;/code&gt; and &lt;code&gt;Services&lt;/code&gt;) visible on visualization. &lt;/li&gt;
&lt;li&gt;It is launched as a &lt;code&gt;DaemonSet&lt;/code&gt; to listen to network interfaces on all nodes. &lt;/li&gt;
&lt;li&gt;Implemented watcher checks every &lt;code&gt;10s&lt;/code&gt; (default) if there is a new (or old) network interface to observe (or forget). &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwjw1gxoq4z1j8czr1iao.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwjw1gxoq4z1j8czr1iao.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In addition to showing a graph of your cluster resources, it also exposes &lt;code&gt;Prometheus&lt;/code&gt; metrics.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8zj4keb5nlxyg2w31yg9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8zj4keb5nlxyg2w31yg9.png" alt="Image description"&gt;&lt;/a&gt;&lt;br&gt;
 &lt;/p&gt;

&lt;h3&gt;
  
  
  Installation
&lt;/h3&gt;

&lt;p&gt;To install &lt;code&gt;k8spacket&lt;/code&gt;, you need to have Helm and Grafana installed. Additionally, the tool requires Hamad's Node Grafana API plugin (&lt;a href="https://grafana.com/grafana/plugins/hamedkarbasi93-nodegraphapi-datasource/" rel="noopener noreferrer"&gt;Node Graph API&lt;/a&gt;). &lt;br&gt;
See all installation steps &lt;a href="https://k8spacket.github.io/k8spacket/#installation" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;br&gt;
 &lt;/p&gt;

&lt;h3&gt;
  
  
  Usage
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Types of stats
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;connection&lt;/code&gt; - helps understand how many connections are established between your workloads and from/to outside clients. It tells you which sockets stay open and could cause problems. It is helpful when you are behind some SNAT gateway with port exhaustion (e.g., &lt;code&gt;Azure AKS&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;bytes&lt;/code&gt; - shows how many bytes are sent or received by workloads.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;duration&lt;/code&gt; - calculates the lifetime of connections.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fraw.githubusercontent.com%2Fk8spacket%2Fk8spacket%2Fmaster%2Fdocs%2Fgraphmode.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fraw.githubusercontent.com%2Fk8spacket%2Fk8spacket%2Fmaster%2Fdocs%2Fgraphmode.gif" alt="Graph modes"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Filters
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;by namespace&lt;/code&gt; - select one or more k8s namespaces&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fraw.githubusercontent.com%2Fk8spacket%2Fk8spacket%2Fmaster%2Fdocs%2Fnamespace.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fraw.githubusercontent.com%2Fk8spacket%2Fk8spacket%2Fmaster%2Fdocs%2Fnamespace.gif" alt="Namespace"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;by names included&lt;/code&gt; - select workload names for visualization&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;by names excluded&lt;/code&gt; - exclude workload names from visualization&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fraw.githubusercontent.com%2Fk8spacket%2Fk8spacket%2Fmaster%2Fdocs%2Fincludeexclude.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fraw.githubusercontent.com%2Fk8spacket%2Fk8spacket%2Fmaster%2Fdocs%2Fincludeexclude.gif" alt="Include &amp;amp; exlude"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Summary
&lt;/h3&gt;

&lt;p&gt;If you want to know what is going on with TCP traffic in your cluster, try &lt;code&gt;k8spacket&lt;/code&gt;. Investigation about cutting the traffic (&lt;code&gt;network policy&lt;/code&gt;) could be painless when you see a leak of packages outside. Make a review of third-party libraries to check connections with the world.&lt;/p&gt;

&lt;p&gt;The source code can be found at &lt;a href="https://github.com/k8spacket/k8spacket" rel="noopener noreferrer"&gt;github.com/k8spacket&lt;/a&gt;&lt;/p&gt;

</description>
      <category>devops</category>
      <category>kubernetes</category>
      <category>observability</category>
      <category>tcp</category>
    </item>
  </channel>
</rss>
