<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>Linux on sysarcher/@ich_code</title><link>https://sysarcher.github.io/categories/linux/</link><description>Recent content in Linux on sysarcher/@ich_code</description><generator>Hugo</generator><language>en-us</language><lastBuildDate>Wed, 24 Feb 2021 21:22:37 +0200</lastBuildDate><atom:link href="https://sysarcher.github.io/categories/linux/index.xml" rel="self" type="application/rss+xml"/><item><title>Some nice Hacks</title><link>https://sysarcher.github.io/posts/nice-hacks/</link><pubDate>Wed, 24 Feb 2021 21:22:37 +0200</pubDate><guid>https://sysarcher.github.io/posts/nice-hacks/</guid><description>&lt;p&gt;&lt;em&gt;Linux only&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;DISCLAIMER: THE FOLLOWING CAN LEAD TO CREATING SECURITY HOLES IN THE VPN-PROTECTED NETWORK&amp;hellip; BE VERY CAREFUL. MAKE SURE YOU KNOW WHAT YOU&amp;rsquo;RE DOING. IF YOU DON&amp;rsquo;T UNDERSTAND WHAT YOU&amp;rsquo;RE DOING, &lt;strong&gt;DO NOT PROCEED&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;VPNs are a pain in the neck. I managed to find a way to have VPN traffic limited to some sites instead of routing everything through your corporate network.&lt;/p&gt;
&lt;p&gt;Routing everything through corporate network is also a cause of load on the company&amp;rsquo;s servers. Imagine a ton of people watching Youtube over VPN. Now, I&amp;rsquo;m talking about traditional VPN here, not p2p stuff.&lt;/p&gt;</description><content:encoded><![CDATA[<p><em>Linux only</em></p>
<p><em>DISCLAIMER: THE FOLLOWING CAN LEAD TO CREATING SECURITY HOLES IN THE VPN-PROTECTED NETWORK&hellip; BE VERY CAREFUL. MAKE SURE YOU KNOW WHAT YOU&rsquo;RE DOING. IF YOU DON&rsquo;T UNDERSTAND WHAT YOU&rsquo;RE DOING, <strong>DO NOT PROCEED</strong></em></p>
<p>VPNs are a pain in the neck. I managed to find a way to have VPN traffic limited to some sites instead of routing everything through your corporate network.</p>
<p>Routing everything through corporate network is also a cause of load on the company&rsquo;s servers. Imagine a ton of people watching Youtube over VPN. Now, I&rsquo;m talking about traditional VPN here, not p2p stuff.</p>
<h2 id="use-vpn-slice">Use <code>vpn-slice</code></h2>
<p><a href="https://github.com/dlenski/vpn-slice"><code>vpn-slice</code></a> is an awesome tool that allows you to use the VPN for only a certain few websites. I used <code>vpn-slice</code> along with <code>openconnect</code>.</p>
<p>Installation is pretty straightforward if you follow the documentation. Just make sure the <code>root</code> user sees the binary. I installed <code>pyenv</code> seperately for the <code>root</code> user and configured the global python env to be 3.9.2 (<code>pyenv global 3.9.2</code>).</p>
<p>That&rsquo;s it. Now install <code>vpn-slice</code>:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"><code class="language-console" data-lang="console"><span style="display:flex;"><span>$ pyenv global 3.9.2  <span style="color:#75715e"># or whatever version you want</span>
</span></span><span style="display:flex;"><span>$ pip install --upgrade pip
</span></span><span style="display:flex;"><span>$ pip install dnspython  <span style="color:#75715e"># recommended in project README</span>
</span></span><span style="display:flex;"><span>$ pip install vpn-slice
</span></span></code></pre></div><h2 id="usage-with-openconnect">Usage with <code>openconnect</code></h2>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span><span style="color:#75715e"># Source: https://docs.microsoft.com/en-us/microsoft-365/enterprise/urls-and-ip-address-ranges?view=o365-worldwide#skype-for-business-online-and-microsoft-teams</span>
</span></span><span style="display:flex;"><span>MSFT<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;teams.microsoft.com login.microsoftonline.com microsoftstreams.com 13.107.64.0/18, 52.112.0.0/14, 52.120.0.0/14&#34;</span>
</span></span><span style="display:flex;"><span>MYCOMPANY<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;&#34;</span>  <span style="color:#75715e"># Your company&#39;s domains, IP addr etc.</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>openconnect <span style="color:#ae81ff">\
</span></span></span><span style="display:flex;"><span>  -c /home/$USER/.cert/CERT.crt <span style="color:#ae81ff">\
</span></span></span><span style="display:flex;"><span>  -k /home/$USER/.cert/private.key --key-password-from-fsid <span style="color:#ae81ff">\
</span></span></span><span style="display:flex;"><span>  -s <span style="color:#e6db74">&#34;vpn-slice </span>$MSFT<span style="color:#e6db74"> </span>$MYCOMPANY<span style="color:#e6db74">&#34;</span> <span style="color:#ae81ff">\
</span></span></span><span style="display:flex;"><span>  vpn.company.com
</span></span></code></pre></div>]]></content:encoded></item><item><title>Benchmarking DPDK</title><link>https://sysarcher.github.io/posts/dpdk-benchmarking/</link><pubDate>Mon, 08 Jul 2019 21:22:37 +0200</pubDate><guid>https://sysarcher.github.io/posts/dpdk-benchmarking/</guid><description>&lt;p&gt;&lt;em&gt;My reference: &lt;a href="https://software.intel.com/en-us/articles/set-up-open-vswitch-with-dpdk-on-ubuntu-server"&gt;https://software.intel.com/en-us/articles/set-up-open-vswitch-with-dpdk-on-ubuntu-server&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;So I got to play with the Data Plane Development Kit (DPDK) from Intel recently. I planned on replicating the PVP benchmark for my use-case. I set up the following environment:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Ubuntu 18.04 (bionic) host with:
&lt;ul&gt;
&lt;li&gt;KVM&lt;/li&gt;
&lt;li&gt;QEMU&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Debian 10 guest images downloaded from: &lt;a href="https://cdimage.debian.org/cdimage/openstack/current/"&gt;https://cdimage.debian.org/cdimage/openstack/current/&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;A useful tool is &lt;code&gt;numactl&lt;/code&gt; (use &lt;code&gt;apt&lt;/code&gt; to install it). On my non-server system, I don&amp;rsquo;t have multiple socks and multiple cores per sock etc.&lt;/p&gt;</description><content:encoded><![CDATA[<p><em>My reference: <a href="https://software.intel.com/en-us/articles/set-up-open-vswitch-with-dpdk-on-ubuntu-server">https://software.intel.com/en-us/articles/set-up-open-vswitch-with-dpdk-on-ubuntu-server</a></em></p>
<p>So I got to play with the Data Plane Development Kit (DPDK) from Intel recently. I planned on replicating the PVP benchmark for my use-case. I set up the following environment:</p>
<ul>
<li>Ubuntu 18.04 (bionic) host with:
<ul>
<li>KVM</li>
<li>QEMU</li>
</ul>
</li>
<li>Debian 10 guest images downloaded from: <a href="https://cdimage.debian.org/cdimage/openstack/current/">https://cdimage.debian.org/cdimage/openstack/current/</a></li>
</ul>
<p>A useful tool is <code>numactl</code> (use <code>apt</code> to install it). On my non-server system, I don&rsquo;t have multiple socks and multiple cores per sock etc.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"><code class="language-console" data-lang="console"><span style="display:flex;"><span>root@machine:~# numactl  -s
</span></span><span style="display:flex;"><span>policy: default
</span></span><span style="display:flex;"><span>preferred node: current
</span></span><span style="display:flex;"><span>physcpubind: 2 3 4 5 6 7 
</span></span><span style="display:flex;"><span>cpubind: 0 
</span></span><span style="display:flex;"><span>nodebind: 0 
</span></span><span style="display:flex;"><span>membind: 0 
</span></span></code></pre></div><h2 id="setting-up-ovsdpdk">Setting up (OVS+DPDK)</h2>
<p>First of all set install OVS-dpdk using <code>apt</code></p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>sudo apt-get install openvswitch-switch-dpdk 
</span></span><span style="display:flex;"><span>sudo update-alternatives --set ovs-vswitchd /usr/lib/openvswitch-switch-dpdk/ovs-vswitchd-dpdk
</span></span></code></pre></div><p>Restart the systemd service: <code>sudo systemctl restart openvswitch-switch.service</code></p>
<p>Hugepages will need to be set up. But we need to tell DPDK about that.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"><code class="language-console" data-lang="console"><span style="display:flex;"><span>root@machine:~# cat /etc/dpdk/dpdk.conf
</span></span><span style="display:flex;"><span>   ...
</span></span><span style="display:flex;"><span>NR_1G_PAGES=4
</span></span><span style="display:flex;"><span>   ...
</span></span></code></pre></div><h3 id="isolate-some-cpus">Isolate some CPUs</h3>
<p>Edit the value of <code>GRUB_CMDLINE_LINUX_DEFAULT</code> to:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"><code class="language-ini" data-lang="ini"><span style="display:flex;"><span><span style="color:#a6e22e">GRUB_CMDLINE_LINUX_DEFAULT</span><span style="color:#f92672">=</span><span style="color:#e6db74">&#34;default_hugepagesz=1G hugepagesz=1G hugepages=4 hugepagesz=2M hugepages=2048 iommu=pt intel_iommu=on isolcpus=0,1&#34;</span>
</span></span></code></pre></div><p>And run <code>sudo update-grub</code>.</p>
<p><em>this setting will not need to change afterwards. A reboot of the machine is required. See if the parameters got passed correctly by doing <code>cat /proc/cmdline</code></em></p>
<h3 id="set-up-hugepages">Set up Hugepages</h3>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>sudo mkdir -p /mnt/huge
</span></span><span style="display:flex;"><span>sudo mkdir -p /mnt/huge_2mb
</span></span><span style="display:flex;"><span>sudo mount -t hugetlbfs none /mnt/huge
</span></span><span style="display:flex;"><span>sudo mount -t hugetlbfs none /mnt/huge_2mb -o pagesize<span style="color:#f92672">=</span>2MB
</span></span><span style="display:flex;"><span>sudo mount -t hugetlbfs none /dev/hugepages
</span></span></code></pre></div><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"><code class="language-console" data-lang="console"><span style="display:flex;"><span>root@machine:~# grep HugePages_ /proc/meminfo 
</span></span><span style="display:flex;"><span>HugePages_Total:       4
</span></span><span style="display:flex;"><span>HugePages_Free:        1
</span></span><span style="display:flex;"><span>HugePages_Rsvd:        0
</span></span><span style="display:flex;"><span>HugePages_Surp:        0
</span></span></code></pre></div><h2 id="configure-ovs-dpdk">Configure OVS-DPDK</h2>
<p>The database needs to be set up only once (<code>sudo ovs-vsctl --no-wait init</code>)</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>sudo ovs-vsctl --no-wait set Open_vSwitch . other_config:dpdk-lcore-mask<span style="color:#f92672">=</span>0x03  <span style="color:#75715e"># hopefully: cores, 0,1 </span>
</span></span><span style="display:flex;"><span>sudo ovs-vsctl --no-wait set Open_vSwitch . other_config:dpdk-socket-mem<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;1024&#34;</span>
</span></span><span style="display:flex;"><span>sudo ovs-vsctl set Open_vSwitch . other_config:pmd-cpu-mask<span style="color:#f92672">=</span>0x0C <span style="color:#75715e"># we have just one NUMA node</span>
</span></span></code></pre></div><h3 id="create-ovs-dpdk-bridge-and-ports">Create OVS-DPDK Bridge and Ports</h3>
<p><code>dpdkvhostuser</code> is a predefined type. <code>vhost-user</code> is understood by Qemu 2.2 and above.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>sudo ovs-vsctl add-br br0 -- set bridge br0 datapath_type<span style="color:#f92672">=</span>netdev
</span></span><span style="display:flex;"><span>sudo ovs-vsctl add-port br0 vhost-user1 -- set Interface vhost-user1 type<span style="color:#f92672">=</span>dpdkvhostuser
</span></span><span style="display:flex;"><span>sudo ovs-vsctl add-port br0 vhost-user2 -- set Interface vhost-user2 type<span style="color:#f92672">=</span>dpdkvhostuser
</span></span></code></pre></div><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"><code class="language-console" data-lang="console"><span style="display:flex;"><span>root@machine:~# ovs-vsctl show
</span></span><span style="display:flex;"><span>c3459670-39b8-43f7-bc57-569672ed79c6
</span></span><span style="display:flex;"><span>    Bridge &#34;br0&#34;
</span></span><span style="display:flex;"><span>        Port &#34;br0&#34;
</span></span><span style="display:flex;"><span>            Interface &#34;br0&#34;
</span></span><span style="display:flex;"><span>                type: internal
</span></span><span style="display:flex;"><span>        Port &#34;vhost-user2&#34;
</span></span><span style="display:flex;"><span>            Interface &#34;vhost-user2&#34;
</span></span><span style="display:flex;"><span>                type: dpdkvhostuser
</span></span><span style="display:flex;"><span>        Port &#34;vhost-user1&#34;
</span></span><span style="display:flex;"><span>            Interface &#34;vhost-user1&#34;
</span></span><span style="display:flex;"><span>                type: dpdkvhostuser
</span></span><span style="display:flex;"><span>    ovs_version: &#34;2.9.2&#34;
</span></span></code></pre></div><h3 id="binding-devices-to-dpdk">Binding Devices to DPDK</h3>
<p><em>We should check <a href="https://core.dpdk.org/supported/">whether the NIC is compatible</a> with DPDK first. The <a href="https://core.dpdk.org/supported/">list</a> on DPDK doesn&rsquo;t seem to have been updated e.g. the <a href="https://doc.dpdk.org/guides-18.11/nics/igb.html?highlight=i210#supported-chipsets-and-nics">documentation itself for newer versions</a> states that the I210 is supported.</em></p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>sudo modprobe vfio-pci
</span></span><span style="display:flex;"><span>sudo dpdk-devbind --bind<span style="color:#f92672">=</span>vfio-pci eno1 <span style="color:#75715e"># eno1 is the interface I want to bind to DPDK</span>
</span></span></code></pre></div><p><code>dpdk-devbind --status</code> can be used to check whether the NIC is now using the DPDK compatible driver.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"><code class="language-console" data-lang="console"><span style="display:flex;"><span>root@machine:~# dpdk-devbind --status
</span></span><span style="display:flex;"><span><span style="color:#960050;background-color:#1e0010">
</span></span></span><span style="display:flex;"><span>Network devices using DPDK-compatible driver
</span></span><span style="display:flex;"><span>============================================
</span></span><span style="display:flex;"><span>0000:00:19.0 &#39;Ethernet Connection I217-V 153b&#39; drv=vfio-pci unused=e1000e
</span></span><span style="display:flex;"><span><span style="color:#960050;background-color:#1e0010">
</span></span></span><span style="display:flex;"><span>Network devices using kernel driver
</span></span><span style="display:flex;"><span>===================================
</span></span><span style="display:flex;"><span>0000:02:00.0 &#39;Killer E220x Gigabit Ethernet Controller e091&#39; if=enp2s0 drv=alx unused=vfio-pci *Active*
</span></span><span style="display:flex;"><span><span style="color:#960050;background-color:#1e0010">
</span></span></span><span style="display:flex;"><span>    ...
</span></span></code></pre></div><h2 id="vms-quick-start">VMs Quick Start</h2>
<p><a href="https://cdimage.debian.org/cdimage/openstack/current/debian-10.0.1-20190708-openstack-amd64.qcow2">Download Debian 10 (buster)</a> and change the password for <code>root</code> using <code>guestfish</code>. (Debian was an arbitrary choice here.)</p>
<p>Add anything to the images at this point. I downloaded <code>qperf</code> with all it&rsquo;s dependencies and added it:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>PACKAGES<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;qperf iperf&#34;</span>
</span></span><span style="display:flex;"><span>apt-get download <span style="color:#66d9ef">$(</span>apt-cache depends --recurse --no-recommends --no-suggests <span style="color:#ae81ff">\
</span></span></span><span style="display:flex;"><span>  --no-conflicts --no-breaks --no-replaces --no-enhances <span style="color:#ae81ff">\
</span></span></span><span style="display:flex;"><span>  --no-pre-depends <span style="color:#e6db74">${</span>PACKAGES<span style="color:#e6db74">}</span> | grep <span style="color:#e6db74">&#34;^\w&#34;</span><span style="color:#66d9ef">)</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>virt-copy-in -a ./debian-10.0.0-openstack-amd64-2.qcow2  *.deb  /home/
</span></span></code></pre></div><p><code>openssl passwd -1 &lt;password&gt;</code> can be used to generate a password entry, and this can be added to the guest image using:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>guestfish --rw --add ../debian-10.0.0-openstack-amd64.qcow2 --mount /dev/sda1:/ vi /etc/shadow
</span></span></code></pre></div><p>And make 2 copies of the <code>debian-10.0.1-20190708-openstack-amd64.qcow2</code> file. We&rsquo;ll use it as our hard drives for guests.</p>
<h4 id="some-resources-to-read">Some resources to read</h4>
<ul>
<li>File-sharing: <code>https://www.linux-kvm.org/page/9p_virtio</code></li>
<li>OVS+KVM: <code>https://docs.paloaltonetworks.com/vm-series/8-1/vm-series-deployment/set-up-the-vm-series-firewall-on-kvm/performance-tuning-of-the-vm-series-for-kvm/enable-open-vswitch-on-kvm.html#</code></li>
<li>Using <code>testpmd</code> to test DPDK Performance: <code>https://software.intel.com/en-us/articles/testing-dpdk-performance-and-features-with-testpmd</code></li>
<li>Vhost/Virtio in DPDK: <code>https://software.intel.com/en-us/articles/configuration-and-performance-of-vhost-virtio-in-data-plane-development-kit-dpdk</code></li>
</ul>
<h3 id="launching-the-guests">Launching the Guests</h3>
<p>I launched the guests in two separate terminal windows (i.e., copy-paste instead of executing).</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"><code class="language-console" data-lang="console"><span style="display:flex;"><span>root@machine:~# cat ./launch-os.sh 
</span></span><span style="display:flex;"><span># Launch OS1
</span></span><span style="display:flex;"><span>qemu-system-x86_64 -m 1024 -smp 4 -cpu host -hda ./debian-10.0.0-openstack-amd64.qcow2 -boot c -enable-kvm -no-reboot -net none -nographic -chardev socket,id=char1,path=/run/openvswitch/vhost-user1 -netdev type=vhost-user,id=mynet1,chardev=char1,vhostforce -device virtio-net-pci,mac=00:00:00:00:00:01,netdev=mynet1 -object memory-backend-file,id=mem,size=1G,mem-path=/dev/hugepages,share=on -numa node,memdev=mem -mem-prealloc
</span></span><span style="display:flex;"><span><span style="color:#960050;background-color:#1e0010">
</span></span></span><span style="display:flex;"><span># Launch OS2
</span></span><span style="display:flex;"><span>qemu-system-x86_64 -m 1024 -smp 4 -cpu host -hda ./debian-10.0.0-openstack-amd64-2.qcow2 -boot c -enable-kvm -no-reboot -net none -nographic -chardev socket,id=char2,path=/run/openvswitch/vhost-user2 -netdev type=vhost-user,id=mynet2,chardev=char2,vhostforce -device virtio-net-pci,mac=00:00:00:00:00:02,netdev=mynet2 -object memory-backend-file,id=mem,size=1G,mem-path=/dev/hugepages,share=on -numa node,memdev=mem -mem-prealloc -fsdev local,security_model=passthrough,id=fsdev0,path=/tmp/share -device virtio-9p-pci,id=fs0,fsdev=fsdev0,mount_tag=hostshare
</span></span></code></pre></div><p>Godspeed!</p>
]]></content:encoded></item><item><title>Kata annotations</title><link>https://sysarcher.github.io/posts/kata-annotations/</link><pubDate>Tue, 11 Jun 2019 21:22:37 +0200</pubDate><guid>https://sysarcher.github.io/posts/kata-annotations/</guid><description>&lt;p&gt;&lt;em&gt;Annotations are a great feature in Kubernetes and a means for communicating to kata some options. &lt;a href="https://github.com/kata-containers/documentation/issues/486"&gt;They are being documented as of the time of this writing&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Using annotations, you can:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Customize the Kernel that is used (see &lt;code&gt;KernelPath&lt;/code&gt; example below)&lt;/li&gt;
&lt;li&gt;Change the guest image (&lt;code&gt;ImagePath&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;Hypervisor (&lt;code&gt;HypervisorPath&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;Firmware (&lt;code&gt;FirmwarePath&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;etc. etc. (All of the annotations are listed in &lt;a href="https://github.com/kata-containers/runtime/blob/master/virtcontainers/pkg/annotations/annotations.go"&gt;&lt;code&gt;annotations.go&lt;/code&gt;&lt;/a&gt;)&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="using-a-custom-kernel"&gt;Using a Custom Kernel&lt;/h3&gt;
&lt;p&gt;Here is the &lt;code&gt;yaml&lt;/code&gt; file I used to apply a custom kernel:&lt;/p&gt;</description><content:encoded><![CDATA[<p><em>Annotations are a great feature in Kubernetes and a means for communicating to kata some options. <a href="https://github.com/kata-containers/documentation/issues/486">They are being documented as of the time of this writing</a></em></p>
<p>Using annotations, you can:</p>
<ul>
<li>Customize the Kernel that is used (see <code>KernelPath</code> example below)</li>
<li>Change the guest image (<code>ImagePath</code>)</li>
<li>Hypervisor (<code>HypervisorPath</code>)</li>
<li>Firmware (<code>FirmwarePath</code>)</li>
<li>etc. etc. (All of the annotations are listed in <a href="https://github.com/kata-containers/runtime/blob/master/virtcontainers/pkg/annotations/annotations.go"><code>annotations.go</code></a>)</li>
</ul>
<h3 id="using-a-custom-kernel">Using a Custom Kernel</h3>
<p>Here is the <code>yaml</code> file I used to apply a custom kernel:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"><code class="language-yaml" data-lang="yaml"><span style="display:flex;"><span><span style="color:#f92672">apiVersion</span>: <span style="color:#ae81ff">v1</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">kind</span>: <span style="color:#ae81ff">Pod</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">metadata</span>:
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">annotations</span>:
</span></span><span style="display:flex;"><span>        <span style="color:#f92672">com.github.containers.virtcontainers.KernelPath</span>: <span style="color:#e6db74">&#34;/usr/share/kata-containers/vmlinuz-4.19.31-40&#34;</span>
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">name</span>: <span style="color:#ae81ff">kata-example</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">spec</span>:
</span></span><span style="display:flex;"><span>  <span style="color:#f92672">runtimeClassName</span>: <span style="color:#ae81ff">kata-qemu</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>  <span style="color:#f92672">containers</span>:
</span></span><span style="display:flex;"><span>  - <span style="color:#f92672">name</span>: <span style="color:#ae81ff">nginx-container</span>
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">image</span>: <span style="color:#ae81ff">nginx</span>
</span></span></code></pre></div><p>The <code>metadata</code> key contains the <code>annotations</code> map. All of the annotations are listed in <a href="https://github.com/kata-containers/runtime/blob/master/virtcontainers/pkg/annotations/annotations.go"><code>annotations.go</code></a> on the main repo.</p>
]]></content:encoded></item><item><title>Kata and Kubernetes</title><link>https://sysarcher.github.io/posts/kata-k8s/</link><pubDate>Sun, 19 May 2019 21:22:37 +0200</pubDate><guid>https://sysarcher.github.io/posts/kata-k8s/</guid><description>&lt;h3 id="setting-up-kata-using-docker"&gt;Setting up Kata using Docker&lt;/h3&gt;
&lt;p&gt;This is documented here: &lt;a href="https://github.com/kata-containers/packaging/blob/master/kata-deploy/README.md#docker-quick-start"&gt;https://github.com/kata-containers/packaging/blob/master/kata-deploy/README.md#docker-quick-start&lt;/a&gt;&lt;/p&gt;
&lt;h3 id="using-minikube-and-kata"&gt;Using Minikube and Kata&lt;/h3&gt;
&lt;p&gt;&lt;a href="https://github.com/kata-containers/documentation/pull/445#"&gt;This PR&lt;/a&gt; is adding the documentation to get started with &lt;code&gt;minikube&lt;/code&gt;: &lt;a href="https://github.com/kata-containers/documentation/pull/445#"&gt;https://github.com/kata-containers/documentation/pull/445#&lt;/a&gt;&lt;/p&gt;
&lt;h3 id="using-kubeadm"&gt;Using &lt;code&gt;kubeadm&lt;/code&gt;&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;First, set up a Kubernetes cluster using &lt;code&gt;kubeadm&lt;/code&gt;: &lt;a href="https://kubernetes.io/docs/setup/production-environment/tools/kubeadm/create-cluster-kubeadm/"&gt;https://kubernetes.io/docs/setup/production-environment/tools/kubeadm/create-cluster-kubeadm/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;then, &lt;a href="https://github.com/kata-containers/packaging/blob/master/kata-deploy/README.md#kubernetes-quick-start"&gt;https://github.com/kata-containers/packaging/blob/master/kata-deploy/README.md#kubernetes-quick-start&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="conclusion"&gt;Conclusion&lt;/h3&gt;
&lt;p&gt;Using the new &lt;code&gt;kata-deploy&lt;/code&gt; method, it is very easy to set up a Kubernetes cluster that uses Kata Containers.&lt;/p&gt;</description><content:encoded><![CDATA[<h3 id="setting-up-kata-using-docker">Setting up Kata using Docker</h3>
<p>This is documented here: <a href="https://github.com/kata-containers/packaging/blob/master/kata-deploy/README.md#docker-quick-start">https://github.com/kata-containers/packaging/blob/master/kata-deploy/README.md#docker-quick-start</a></p>
<h3 id="using-minikube-and-kata">Using Minikube and Kata</h3>
<p><a href="https://github.com/kata-containers/documentation/pull/445#">This PR</a> is adding the documentation to get started with <code>minikube</code>: <a href="https://github.com/kata-containers/documentation/pull/445#">https://github.com/kata-containers/documentation/pull/445#</a></p>
<h3 id="using-kubeadm">Using <code>kubeadm</code></h3>
<ul>
<li>First, set up a Kubernetes cluster using <code>kubeadm</code>: <a href="https://kubernetes.io/docs/setup/production-environment/tools/kubeadm/create-cluster-kubeadm/">https://kubernetes.io/docs/setup/production-environment/tools/kubeadm/create-cluster-kubeadm/</a></li>
<li>then, <a href="https://github.com/kata-containers/packaging/blob/master/kata-deploy/README.md#kubernetes-quick-start">https://github.com/kata-containers/packaging/blob/master/kata-deploy/README.md#kubernetes-quick-start</a></li>
</ul>
<h3 id="conclusion">Conclusion</h3>
<p>Using the new <code>kata-deploy</code> method, it is very easy to set up a Kubernetes cluster that uses Kata Containers.</p>
]]></content:encoded></item><item><title>Taking Kata Steps</title><link>https://sysarcher.github.io/posts/kata-steps/</link><pubDate>Sun, 28 Apr 2019 21:22:37 +0200</pubDate><guid>https://sysarcher.github.io/posts/kata-steps/</guid><description>&lt;p&gt;So I thought that it might be a great idea to run an RT kernel inside Kata containers. This is a usecase because I soon hope to see Kata containers running on real-time capable hypervisors and also being used in scenarios where real-time is a thing. Soon!&lt;/p&gt;
&lt;p&gt;For now, let&amp;rsquo;s look at how I went about doing what I did..&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;You need to &lt;code&gt;go get github.com/kata-containers/packaging&lt;/code&gt; repository. (or, git clone if you so prefer.) Be sure to have your &lt;code&gt;$GOPATH&lt;/code&gt; properly set!!&lt;/li&gt;
&lt;li&gt;cd into &lt;code&gt;packaging/kernel&lt;/code&gt; directory.&lt;/li&gt;
&lt;li&gt;I chose the &lt;code&gt;4.19.31&lt;/code&gt; version of the kernel. Primarily because it was a newer kernel (not too different from the kernel version that comes with the current kata release.) and because it had the &lt;a href="https://cdn.kernel.org/pub/linux/kernel/projects/rt/4.19/patch-4.19.31-rt18.patch.xz"&gt;RT patches available&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;I changed &lt;a href="https://github.com/kata-containers/packaging/blob/dce0558ec6d8329e81fa59c809351170f6741a7a/kernel/build-kernel.sh#L25"&gt;the &lt;code&gt;kernel_version=&amp;quot;&amp;quot;&lt;/code&gt; line&lt;/a&gt; to &lt;code&gt;kernel_version=&amp;quot;4.19.31&amp;quot;&lt;/code&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;That&amp;rsquo;s it. We are ready to (1) apply the necessary patches from Kata maintainers to our Kernel of choosing and (2) apply the RT patches:&lt;/p&gt;</description><content:encoded><![CDATA[<p>So I thought that it might be a great idea to run an RT kernel inside Kata containers. This is a usecase because I soon hope to see Kata containers running on real-time capable hypervisors and also being used in scenarios where real-time is a thing. Soon!</p>
<p>For now, let&rsquo;s look at how I went about doing what I did..</p>
<ol>
<li>You need to <code>go get github.com/kata-containers/packaging</code> repository. (or, git clone if you so prefer.) Be sure to have your <code>$GOPATH</code> properly set!!</li>
<li>cd into <code>packaging/kernel</code> directory.</li>
<li>I chose the <code>4.19.31</code> version of the kernel. Primarily because it was a newer kernel (not too different from the kernel version that comes with the current kata release.) and because it had the <a href="https://cdn.kernel.org/pub/linux/kernel/projects/rt/4.19/patch-4.19.31-rt18.patch.xz">RT patches available</a></li>
<li>I changed <a href="https://github.com/kata-containers/packaging/blob/dce0558ec6d8329e81fa59c809351170f6741a7a/kernel/build-kernel.sh#L25">the <code>kernel_version=&quot;&quot;</code> line</a> to <code>kernel_version=&quot;4.19.31&quot;</code></li>
</ol>
<p>That&rsquo;s it. We are ready to (1) apply the necessary patches from Kata maintainers to our Kernel of choosing and (2) apply the RT patches:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span><span style="color:#75715e"># download and apply the kata patches to the kernel</span>
</span></span><span style="display:flex;"><span>./build-kernel.sh setup
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>cd kata-linux-4.19.31-36
</span></span><span style="display:flex;"><span>patch -p1&lt;../path-to-extracted-patch/patch-4.19.31-rt18.patch
</span></span></code></pre></div><p>Wait&hellip; we need to first, <code>make menuconfig</code> and enable <code>RT</code> capabilities</p>
<pre tabindex="0"><code>General Setup 
  --&gt; Preemption Model
    --&gt; Fully Preemptible Kernel (RT)
</code></pre><p>Now, we&rsquo;re ready to build the Kernel and install it*:</p>
<pre tabindex="0"><code>./build-kernel.sh setup
sudo ./build-kernel.sh install
</code></pre><h3 id="drum-roll-please">Drum Roll please</h3>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"><code class="language-console" data-lang="console"><span style="display:flex;"><span>$ docker run -it --runtime kata-runtime ubuntu bash
</span></span><span style="display:flex;"><span>root@77cf04fd8290:/# uname -r
</span></span><span style="display:flex;"><span>4.19.31-rt18
</span></span><span style="display:flex;"><span>root@77cf04fd8290:/# uname -a
</span></span><span style="display:flex;"><span>Linux 77cf04fd8290 4.19.31-rt18 #2 SMP PREEMPT RT Mon Apr 29 09:06:08 CEST 2019 x86_64 x86_64 x86_64 GNU/Linux
</span></span><span style="display:flex;"><span>root@77cf04fd8290:/# 
</span></span></code></pre></div><p>So proud!!!</p>
<p>Happy Building!!</p>
<h3 id="note-on-kernel-files">Note on Kernel Files</h3>
<p><code>vmlinux</code>: uncompressed kernel. |
<code>vmlinuz</code>: compressed kernel. |
<code>bzImage</code>: located under <code>arch/x86_64/boot/bzImage</code>. Big Zimage. Compressed kernel image.</p>
<p>More info: <a href="https://stackoverflow.com/a/22338835/3760442">https://stackoverflow.com/a/22338835/3760442</a></p>
<h3 id="acknowledgements">Acknowledgements</h3>
<p>Special thanks to @egernst, @rico and the great team on Slack!! Though this was my first foray into Kata Containers, I must say the folks were very welcoming. Thank you all!!</p>
<p><em>* I built the kernel (as of the time of writing) using <code>make build -j4</code> instead of using the <code>build-kernel.sh</code> script but it shouldn&rsquo;t matter. Just FYI.</em></p>
]]></content:encoded></item></channel></rss>