<?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>Forem: Brian Boucheron</title>
    <description>The latest articles on Forem by Brian Boucheron (@beardicus).</description>
    <link>https://forem.com/beardicus</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%2F32939%2F6ba9fb53-f643-4785-a646-c760071899f8.jpg</url>
      <title>Forem: Brian Boucheron</title>
      <link>https://forem.com/beardicus</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/beardicus"/>
    <language>en</language>
    <item>
      <title>How to Inspect and Debug Kubernetes Networking Primitives</title>
      <dc:creator>Brian Boucheron</dc:creator>
      <pubDate>Thu, 06 Sep 2018 18:27:59 +0000</pubDate>
      <link>https://forem.com/digitalocean/how-to-inspect-and-debug-kubernetes-networking-primitives-d7n</link>
      <guid>https://forem.com/digitalocean/how-to-inspect-and-debug-kubernetes-networking-primitives-d7n</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Kubernetes is a container orchestration system that can manage containerized applications across a cluster of server nodes. Maintaining network connectivity between all the containers in a cluster requires some advanced networking techniques. In this article, we will briefly cover some tools and techniques for inspecting this networking setup.&lt;/p&gt;

&lt;p&gt;These tools may be useful if you are debugging connectivity issues, investigating network throughput problems, or exploring Kubernetes to learn how it operates.&lt;/p&gt;

&lt;p&gt;If you want to know more about Kubernetes in general, you can learn the basics by reading DigitalOcean's &lt;a href="https://www.digitalocean.com/community/tutorials/an-introduction-to-kubernetes"&gt;&lt;em&gt;An Introduction to Kubernetes&lt;/em&gt;&lt;/a&gt;. For a networking-specific overview of Kubernetes, please read &lt;a href="https://www.digitalocean.com/community/tutorials/kubernetes-networking-under-the-hood"&gt;&lt;em&gt;Kubernetes Networking Under the Hood&lt;/em&gt;&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Getting Started
&lt;/h2&gt;

&lt;p&gt;This tutorial assumes that you already have a Kubernetes cluster, with &lt;code&gt;kubectl&lt;/code&gt; installed on your local computer and configured to connect to the cluster. Any &lt;code&gt;kubectl&lt;/code&gt; commands presented are intended to be run on your local machine.&lt;/p&gt;

&lt;p&gt;All other commands are to be run on a Kubernetes node as the &lt;strong&gt;root&lt;/strong&gt; user. If you use a sudo-enabled non-root user on your Kubernetes nodes, please use &lt;code&gt;sudo&lt;/code&gt; to run the commands when necessary.&lt;/p&gt;

&lt;h2&gt;
  
  
  Finding a Pod's Cluster IP
&lt;/h2&gt;

&lt;p&gt;To find the cluster IP address of a Kubernetes pod, use the &lt;code&gt;kubectl get pod&lt;/code&gt; command on your local machine, with the option &lt;code&gt;-o wide&lt;/code&gt;. This option will list more information, including the node the pod resides on, and the pod's cluster IP.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;kubectl get pod &lt;span class="nt"&gt;-o&lt;/span&gt; wide
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;NAME                           READY     STATUS    RESTARTS   AGE       IP            NODE
hello-world-5b446dd74b-7c7pk   1/1       Running   0          22m       10.244.18.4   node-one
hello-world-5b446dd74b-pxtzt   1/1       Running   0          22m       10.244.3.4    node-two
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;strong&gt;IP&lt;/strong&gt; column will contain the internal cluster IP address for each pod.&lt;/p&gt;

&lt;p&gt;If you don't see the pod you're looking for, make sure you're in the right namespace. You can list all pods in all namespaces by adding the flag &lt;code&gt;--all-namespaces&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Finding a Service's IP
&lt;/h2&gt;

&lt;p&gt;We can find a Service IP using &lt;code&gt;kubectl&lt;/code&gt; as well. In this case we will list all services in all namespaces:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;kubectl get service &lt;span class="nt"&gt;--all-namespaces&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;NAMESPACE     NAME                       TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)         AGE
default       kubernetes                 ClusterIP   10.32.0.1       &amp;lt;none&amp;gt;        443/TCP         6d
kube-system   csi-attacher-doplugin      ClusterIP   10.32.159.128   &amp;lt;none&amp;gt;        12345/TCP       6d
kube-system   csi-provisioner-doplugin   ClusterIP   10.32.61.61     &amp;lt;none&amp;gt;        12345/TCP       6d
kube-system   kube-dns                   ClusterIP   10.32.0.10      &amp;lt;none&amp;gt;        53/UDP,53/TCP   6d
kube-system   kubernetes-dashboard       ClusterIP   10.32.226.209   &amp;lt;none&amp;gt;        443/TCP         6d
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The service IP can be found in the &lt;strong&gt;CLUSTER-IP&lt;/strong&gt; column.&lt;/p&gt;

&lt;h2&gt;
  
  
  Finding and Entering Pod Network Namespaces
&lt;/h2&gt;

&lt;p&gt;Each Kubernetes pod gets assigned its own network namespace. Network namespaces (or netns) are a Linux networking primitive that provide isolation between network devices.&lt;/p&gt;

&lt;p&gt;It can be useful to run commands from within a pod's netns, to check DNS resolution or general network connectivity. To do so, we first need to look up the process ID of one of the containers in a pod. For Docker, we can do that with a series of two commands. First, list the containers running on a node:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker ps
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;CONTAINER ID        IMAGE                                   COMMAND                  CREATED             STATUS              PORTS               NAMES
173ee46a3926        gcr.io/google-samples/node-hello        "/bin/sh -c 'node se…"   9 days ago          Up 9 days                               k8s_hello-world_hello-world-5b446dd74b-pxtzt_default_386a9073-7e35-11e8-8a3d-bae97d2c1afd_0
11ad51cb72df        k8s.gcr.io/pause-amd64:3.1              "/pause"                 9 days ago          Up 9 days                               k8s_POD_hello-world-5b446dd74b-pxtzt_default_386a9073-7e35-11e8-8a3d-bae97d2c1afd_0
. . .
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Find the &lt;strong&gt;container ID&lt;/strong&gt; or &lt;strong&gt;name&lt;/strong&gt; of any container in the pod you're interested in. In the above output we're showing two containers:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  The first container is the &lt;code&gt;hello-world&lt;/code&gt; app running in the &lt;code&gt;hello-world&lt;/code&gt; pod&lt;/li&gt;
&lt;li&gt;  The second is a &lt;em&gt;pause&lt;/em&gt; container running in the &lt;code&gt;hello-world&lt;/code&gt; pod. This container exists solely to hold onto the pod's network namespace&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To get the process ID of either container, take note of the container ID or name, and use it in the following &lt;code&gt;docker&lt;/code&gt; command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker inspect &lt;span class="nt"&gt;--format&lt;/span&gt; &lt;span class="s1"&gt;'{{ .State.Pid }}'&lt;/span&gt; your_container_id_or_name
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;14552
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A process ID (or PID) will be output. Now we can use the &lt;code&gt;nsenter&lt;/code&gt; program to run a command in that process's network namespace:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;nsenter &lt;span class="nt"&gt;-t&lt;/span&gt; your_container_pid &lt;span class="nt"&gt;-n&lt;/span&gt; ip addr
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Be sure to use your own PID, and replace &lt;code&gt;ip addr&lt;/code&gt; with the command you'd like to run inside the pod's network namespace.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; One advantage of using &lt;code&gt;nsenter&lt;/code&gt; to run commands in a pod's namespace – versus using something like &lt;code&gt;docker exec&lt;/code&gt; – is that you have access to all of the commands available on the node, instead of the typically limited set of commands installed in containers.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Finding a Pod's Virtual Ethernet Interface
&lt;/h2&gt;

&lt;p&gt;Each pod's network namespace communicates with the node's root netns through a virtual ethernet pipe. On the node side, this pipe appears as a device that typically begins with &lt;code&gt;veth&lt;/code&gt; and ends in a unique identifier, such as &lt;code&gt;veth77f2275&lt;/code&gt; or &lt;code&gt;veth01&lt;/code&gt;. Inside the pod this pipe appears as &lt;code&gt;eth0&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;It can be useful to correlate which &lt;code&gt;veth&lt;/code&gt; device is paired with a particular pod. To do so, we will list all network devices on the node, then list the devices in the pod's network namespace. We can then correlate device numbers between the two listings to make the connection.&lt;/p&gt;

&lt;p&gt;First, run &lt;code&gt;ip addr&lt;/code&gt; in the pod's network namespace using &lt;code&gt;nsenter&lt;/code&gt;. Refer to the previous section &lt;em&gt;Finding and Entering Pod Network Namespaces&lt;/em&gt; for details on how to do this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;nsenter &lt;span class="nt"&gt;-t&lt;/span&gt; your_container_pid &lt;span class="nt"&gt;-n&lt;/span&gt; ip addr
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1: lo: &amp;lt;LOOPBACK,UP,LOWER_UP&amp;gt; mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
10: eth0@if11: &amp;lt;BROADCAST,MULTICAST,UP,LOWER_UP&amp;gt; mtu 1450 qdisc noqueue state UP group default
    link/ether 02:42:0a:f4:03:04 brd ff:ff:ff:ff:ff:ff link-netnsid 0
    inet 10.244.3.4/24 brd 10.244.3.255 scope global eth0
       valid_lft forever preferred_lft forever
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The command will output a list of the pod's interfaces. Note the &lt;code&gt;if11&lt;/code&gt; number after &lt;code&gt;eth0@&lt;/code&gt; in the example output. This means this pod's &lt;code&gt;eth0&lt;/code&gt; is linked to the node's 11th interface. Now run &lt;code&gt;ip addr&lt;/code&gt; in the node's default namespace to list out its interfaces:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ip addr
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1: lo: &amp;lt;LOOPBACK,UP,LOWER_UP&amp;gt; mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever

. . .

7: veth77f2275@if6: &amp;lt;BROADCAST,MULTICAST,UP,LOWER_UP&amp;gt; mtu 1450 qdisc noqueue master docker0 state UP group default
    link/ether 26:05:99:58:0d:b9 brd ff:ff:ff:ff:ff:ff link-netnsid 0
    inet6 fe80::2405:99ff:fe58:db9/64 scope link
       valid_lft forever preferred_lft forever
9: vethd36cef3@if8: &amp;lt;BROADCAST,MULTICAST,UP,LOWER_UP&amp;gt; mtu 1450 qdisc noqueue master docker0 state UP group default
    link/ether ae:05:21:a2:9a:2b brd ff:ff:ff:ff:ff:ff link-netnsid 1
    inet6 fe80::ac05:21ff:fea2:9a2b/64 scope link
       valid_lft forever preferred_lft forever
11: veth4f7342d@if10: &amp;lt;BROADCAST,MULTICAST,UP,LOWER_UP&amp;gt; mtu 1450 qdisc noqueue master docker0 state UP group default
    link/ether e6:4d:7b:6f:56:4c brd ff:ff:ff:ff:ff:ff link-netnsid 2
    inet6 fe80::e44d:7bff:fe6f:564c/64 scope link
       valid_lft forever preferred_lft forever
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The 11th interface is &lt;code&gt;veth4f7342d&lt;/code&gt; in this example output. This is the virtual ethernet pipe to the pod we're investigating.&lt;/p&gt;

&lt;h2&gt;
  
  
  Inspecting Conntrack Connection Tracking
&lt;/h2&gt;

&lt;p&gt;Prior to version 1.11, Kubernetes used iptables NAT and the conntrack kernel module to track connections. To list all the connections currently being tracked, use the &lt;code&gt;conntrack&lt;/code&gt; command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;conntrack &lt;span class="nt"&gt;-L&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To watch continuously for new connections, use the &lt;code&gt;-E&lt;/code&gt; flag:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;conntrack &lt;span class="nt"&gt;-E&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To list conntrack-tracked connections to a particular destination address, use the &lt;code&gt;-d&lt;/code&gt; flag:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;conntrack &lt;span class="nt"&gt;-L&lt;/span&gt; &lt;span class="nt"&gt;-d&lt;/span&gt; your_destination_address
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If your nodes are having issues making reliable connections to services, it's possible your connection tracking table is full and new connections are being dropped. If that's the case you may see messages like the following in your system logs:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Jul 12 15:32:11 worker-528 kernel: nf_conntrack: table full, dropping packet.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There is a sysctl setting for the maximum number of connections to track. You can list out your current value with the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;sysctl net.netfilter.nf_conntrack_max
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;net.netfilter.nf_conntrack_max = 131072
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To set a new value, use the &lt;code&gt;-w&lt;/code&gt; flag:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;sysctl &lt;span class="nt"&gt;-w&lt;/span&gt; net.netfilter.nf_conntrack_max&lt;span class="o"&gt;=&lt;/span&gt;198000
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To make this setting permanent, add it to the &lt;code&gt;sysctl.conf&lt;/code&gt; file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;net.ipv4.netfilter.ip_conntrack_max = 198000
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Inspecting Iptables Rules
&lt;/h2&gt;

&lt;p&gt;Prior to version 1.11, Kubernetes used iptables NAT to implement virtual IP translation and load balancing for Service IPs.&lt;/p&gt;

&lt;p&gt;To dump all iptables rules on a node, use the &lt;code&gt;iptables-save&lt;/code&gt; command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;iptables-save
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Because the output can be lengthy, you may want to pipe to a file (&lt;code&gt;iptables-save &amp;gt; output.txt&lt;/code&gt;) or a pager (&lt;code&gt;iptables-save | less&lt;/code&gt;) to more easily review the rules.&lt;/p&gt;

&lt;p&gt;To list just the Kubernetes Service NAT rules, use the &lt;code&gt;iptables&lt;/code&gt; command and the &lt;code&gt;-L&lt;/code&gt; flag to specify the correct chain:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;iptables &lt;span class="nt"&gt;-t&lt;/span&gt; nat &lt;span class="nt"&gt;-L&lt;/span&gt; KUBE-SERVICES
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Chain KUBE-SERVICES (2 references)
target     prot opt source               destination
KUBE-SVC-TCOU7JCQXEZGVUNU  udp  --  anywhere             10.32.0.10           /* kube-system/kube-dns:dns cluster IP */ udp dpt:domain
KUBE-SVC-ERIFXISQEP7F7OF4  tcp  --  anywhere             10.32.0.10           /* kube-system/kube-dns:dns-tcp cluster IP */ tcp dpt:domain
KUBE-SVC-XGLOHA7QRQ3V22RZ  tcp  --  anywhere             10.32.226.209        /* kube-system/kubernetes-dashboard: cluster IP */ tcp dpt:https
. . .
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Querying Cluster DNS
&lt;/h2&gt;

&lt;p&gt;One way to debug your cluster DNS resolution is to deploy a debug container with all the tools you need, then use &lt;code&gt;kubectl&lt;/code&gt; to exec &lt;code&gt;nslookup&lt;/code&gt; on it. This is described in &lt;a href="https://kubernetes.io/docs/tasks/administer-cluster/dns-debugging-resolution/"&gt;the official Kubernetes documentation&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Another way to query the cluster DNS is using &lt;code&gt;dig&lt;/code&gt; and &lt;code&gt;nsenter&lt;/code&gt; from a node. If &lt;code&gt;dig&lt;/code&gt; is not installed, it can be installed with &lt;code&gt;apt&lt;/code&gt; on Debian-based Linux distributions:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;apt &lt;span class="nb"&gt;install &lt;/span&gt;dnsutils
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;First, find the cluster IP of the &lt;strong&gt;kube-dns&lt;/strong&gt; service:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;kubectl get service &lt;span class="nt"&gt;-n&lt;/span&gt; kube-system kube-dns
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;NAME       TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)         AGE
kube-dns   ClusterIP   10.32.0.10   &amp;lt;none&amp;gt;        53/UDP,53/TCP   15d
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The cluster IP is highlighted above. Next we'll use &lt;code&gt;nsenter&lt;/code&gt; to run &lt;code&gt;dig&lt;/code&gt; in the a container namespace. Look at the section &lt;em&gt;Finding and Entering Pod Network Namespaces&lt;/em&gt; for more information on this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;nsenter &lt;span class="nt"&gt;-t&lt;/span&gt; 14346 &lt;span class="nt"&gt;-n&lt;/span&gt; dig kubernetes.default.svc.cluster.local @10.32.0.10
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This &lt;code&gt;dig&lt;/code&gt; command looks up the Service's full domain name of &lt;strong&gt;service-name.namespace.svc.cluster.local&lt;/strong&gt; and specifics the IP of the cluster DNS service IP (&lt;code&gt;@10.32.0.10&lt;/code&gt;).&lt;/p&gt;

&lt;h2&gt;
  
  
  Looking at IPVS Details
&lt;/h2&gt;

&lt;p&gt;As of Kubernetes 1.11, &lt;code&gt;kube-proxy&lt;/code&gt; can configure IPVS to handle the translation of virtual Service IPs to pod IPs. You can list the translation table of IPs with &lt;code&gt;ipvsadm&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ipvsadm &lt;span class="nt"&gt;-Ln&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
  -&amp;gt; RemoteAddress:Port           Forward Weight ActiveConn InActConn
TCP  100.64.0.1:443 rr
  -&amp;gt; 178.128.226.86:443           Masq    1      0          0
TCP  100.64.0.10:53 rr
  -&amp;gt; 100.96.1.3:53                Masq    1      0          0
  -&amp;gt; 100.96.1.4:53                Masq    1      0          0
UDP  100.64.0.10:53 rr
  -&amp;gt; 100.96.1.3:53                Masq    1      0          0
  -&amp;gt; 100.96.1.4:53                Masq    1      0          0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To show a single Service IP, use the &lt;code&gt;-t&lt;/code&gt; option and specify the desired IP:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ipvsadm &lt;span class="nt"&gt;-Ln&lt;/span&gt; &lt;span class="nt"&gt;-t&lt;/span&gt; 100.64.0.10:53
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Prot LocalAddress:Port Scheduler Flags
  -&amp;gt; RemoteAddress:Port           Forward Weight ActiveConn InActConn
TCP  100.64.0.10:53 rr
  -&amp;gt; 100.96.1.3:53                Masq    1      0          0
  -&amp;gt; 100.96.1.4:53                Masq    1      0          0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;In this article we’ve reviewed some commands and techniques for exploring and inspecting the details of your Kubernetes cluster's networking. For more information about Kubernetes, take a look at &lt;a href="https://www.digitalocean.com/community/tags/kubernetes?type=tutorials"&gt;DigitalOcean's Kubernetes tutorials&lt;/a&gt; and &lt;a href="https://kubernetes.io/docs/home/"&gt;the official Kubernetes documentation&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>kubernetes</category>
      <category>networking</category>
      <category>devops</category>
    </item>
  </channel>
</rss>
