<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Mikuláš on Medium]]></title>
        <description><![CDATA[Stories by Mikuláš on Medium]]></description>
        <link>https://medium.com/@Mikulas?source=rss-494df6d4c162------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*fgYEbfVA2uBPqDHXgwGzLQ.jpeg</url>
            <title>Stories by Mikuláš on Medium</title>
            <link>https://medium.com/@Mikulas?source=rss-494df6d4c162------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 09:14:01 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@Mikulas/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Kubectl REPL]]></title>
            <link>https://medium.com/@Mikulas/kubectl-repl-e6f86cac8626?source=rss-494df6d4c162------2</link>
            <guid isPermaLink="false">https://medium.com/p/e6f86cac8626</guid>
            <category><![CDATA[tech]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[kubernetes]]></category>
            <dc:creator><![CDATA[Mikuláš]]></dc:creator>
            <pubDate>Mon, 23 Oct 2017 16:43:25 GMT</pubDate>
            <atom:updated>2017-10-23T16:43:25.089Z</atom:updated>
            <cc:license>https://creativecommons.org/licenses/by-nc-sa/4.0/</cc:license>
            <content:encoded><![CDATA[<p><a href="https://github.com/Mikulas/kubectl-repl">Mikulas/kubectl-repl</a></p><p>The official kubectl tool is great. <a href="https://github.com/Mikulas/kubectl-repl/"><em>Kubectl REPL</em></a><em> </em>improves on it by persisting current namespace and adding variables.</p><p><em>Kubectl REPL</em> starts by asking for a namespace to begin in. This very well suits the use-case where every application has its own namespace. You answer with the closest abbreviation: for example, kube orksys forkube-system. Small typos such as kybe-system will work as well.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/450/1*PuGHlp9JGwN_cxAUdhPsNA.gif" /><figcaption>Kubectl REPL starts by offering a list of available namespaces.</figcaption></figure><p>With namespace selected the REPL presents a prompt. Your input is prefixed with kubectl -n $NAMESPACE and evaluated in a shell. This means pipes, redirection and other constructs work as expected. <strong>The goal is to enhance kubectl without you even noticing. </strong>Kubectl REPL should be very intuitive.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/686/1*pP6IXeigSAQY43g9MJWhBw.gif" /><figcaption>Invoking a kubectl command in REPL.</figcaption></figure><p>Finally, <strong>Kubectl REPL introduces variables</strong>. You might have noticed the output lines are numbered. Those are variables and can be used in subsequent commands.</p><p>In the above example, get pods sets variables from $1 up to $5. Instead of copy pasting the pod name, you can invoke logs $3, which evaluates to logs logspout-mzbc8. Variables can be used anywhere, not just the logs subcommand, such as delete pod $3 &amp;&amp; echo $3 &gt; /tmp/pod.txt. More realistically, this is how <strong>you can use a variable to quickly exec into a pod</strong>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*Je7Xy-rbFh2NxznvluYbwQ.gif" /><figcaption>Using <strong>variable substitution</strong> to quickly exec into a pod. Note that REPL properly manages pipes, so exec and other interactive commands work as expected.</figcaption></figure><p>Head over to <a href="https://github.com/Mikulas/kubectl-repl">GitHub repo</a> for complete readme, <strong>releases to install</strong> and docker image: <a href="https://github.com/Mikulas/kubectl-repl/">https://github.com/Mikulas/kubectl-repl/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e6f86cac8626" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Analyzing AWS VPC Flow logs]]></title>
            <link>https://medium.com/@Mikulas/analyzing-aws-vpc-flow-logs-365f5e07c808?source=rss-494df6d4c162------2</link>
            <guid isPermaLink="false">https://medium.com/p/365f5e07c808</guid>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[sysadmin]]></category>
            <category><![CDATA[tutorial]]></category>
            <dc:creator><![CDATA[Mikuláš]]></dc:creator>
            <pubDate>Fri, 28 Jul 2017 11:50:27 GMT</pubDate>
            <atom:updated>2017-07-28T11:50:27.742Z</atom:updated>
            <cc:license>https://creativecommons.org/licenses/by-nc/4.0/</cc:license>
            <content:encoded><![CDATA[<blockquote>Take those simple steps to reduced your AWS Bill by half! Well, it worked for us.</blockquote><p>You open an AWS Bill and one entry surprises you:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6mh5U-OwIHQsbfVDl1rtYA.png" /></figure><p>Searching for the “data transfer out beyond the global free tier” yields no actionable results. Even if you open CloudWatch and find what instance had a lot of traffic, there is not much you can do about it retroactively. Unless you are extremely lucky, the traffic (and the bill) will repeat next month.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HHOtnTWHxtzaxxdy65JrJw.png" /><figcaption>CloudWatch &gt; Metrics &gt; Per-Instance Metrics &gt; search for NetworkOut &gt; chart all. Make sure to set Statistic to Sum, the default is Average which is not very helpful in this case!</figcaption></figure><p>What you have to do immediately is turning on <a href="http://docs.aws.amazon.com/AmazonVPC/latest/UserGuide/flow-logs.html">VPC Flow Logs</a>: a log of almost all traffic, including source and destination address and port. Go to <em>VPC &gt; Your VPCs &gt; select a VPC you want to monitor &gt; switch to Flow Logs tab &gt; Create Flow Log</em>. The logs are then saved into <a href="http://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/CloudWatchLogsConcepts.html"><em>CloudWatch Log Group</em></a>. Wait for the data to gather (again, it does not get populated retroactively, it starts logging from the time you set it up).</p><p>To process the Flow Log, you need to <a href="https://forums.aws.amazon.com/thread.jspa?messageID=658669">export the data</a>; I’ve chosen to download the data and <a href="https://www.postgresql.org/docs/9.6/static/sql-copy.html">import them into PostgreSQL</a>. In the CloudWatch dashboard, select Logs and with the Flow Log <em>Log Group</em> selected, click<em> Action &gt; Export all data to Amazon S3</em>. There seems to be no notification when this is completed, so wait a reasonable amount of time and then download the data.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/751c6b4fcd8bf73ed2c54f63ec61a716/href">https://medium.com/media/751c6b4fcd8bf73ed2c54f63ec61a716/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/aeb52ff824d5a83c20cd33977ad4870a/href">https://medium.com/media/aeb52ff824d5a83c20cd33977ad4870a/href</a></iframe><p>Unfortunately this data is too granular and again, hard to act on. Since our goals is finding what traffic contributes to the data-out cost, we will find what rows are between availability zones.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3pqWDJ8OyiU6Lvv3AcRAZw.png" /><figcaption>List the subnets in your VPC and note the CIDRs.</figcaption></figure><p>If the srcaddr and dstaddr do not correspond to the same subnet CIDR, it’s a cross-zone traffic. Those rows count to the high Bill we got. I’ve also included an external field, which is true if the traffic is not in your VPC.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4cf1de6a924e5a025f5a15db1244bb55/href">https://medium.com/media/4cf1de6a924e5a025f5a15db1244bb55/href</a></iframe><p>If you are going to explore the data beyond the queries here, I suggest creating proper indexes. Our 14 days of traffic logs are roughly 20 GBs, so the queries can take many minutes.</p><p>Unfortunately, if the traffic is between two interfaces under the VPC you monitor, there will be two rows for the same packets. You could try to map those together with a start/end+ports+packets+bytes but I didn’t bother.</p><p>This block is a sanity check. You can skip it if you believe I made no mistake so far, but I suggest you verify.</p><p>A simple SELECT Sum(bytes) FROM vpc WHERE crosszone=1 should return from 100% to 200% of your current data-out bill. If none of the traffic was between your interfaces, it would be equal; if all of the traffic was inside your VPC, it would be logged exactly twice. This may tell you what is the ratio of internal vs external traffic.</p><p>This query yielded 5.6 TB for me, but the bill shows 3.7 TB. This tells me there is 1.9 TB of traffic between our instances. This traffic is logged twice, for a total of 3.8 TB. This leaves 1.8 TB of external traffic.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sa0BXgm6Gf1pMOe14iGtLg.png" /></figure><p>Running SELECT external, Sum(bytes) FROM vpc WHERE crosszone=1 GROUP BY external returns 4.4 TB of internal (doubled) and 1.2 TB of external traffic. I don’t understand where the discrepancy came from.</p><p>This overview is interesting, but again, not immediately actionable.</p><p>At this point, we are ready to find out what causes the traffic. Lets list our most used application ports so we can query those later:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c7a639d613536cd73a7d41cab6739f07/href">https://medium.com/media/c7a639d613536cd73a7d41cab6739f07/href</a></iframe><p>I was delighted to find there are 2 TB of traffic associated with a single recipient IP 172.31.29.150, which incidentally corresponds to a running EC2 instance. <strong>Note that if the instance was already removed, we wouldn’t be able to associate the IP with any service; for this reason, I think AWS should log all IP allocations and also provide a easy overview of all currently allocated IPs.</strong></p><p>Next I would like to know where the traffic to this single offender originates:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/796b74614801d3d21af5b9e7671e5456/href">https://medium.com/media/796b74614801d3d21af5b9e7671e5456/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nWC01opIZeoAm0x0aFvNQw.png" /><figcaption>Ok so there is definitely a problem here. Port 3306 indicates that source is MySQL.</figcaption></figure><p>I was fairly confident 172.31.2.59 is a MySQL RDS instance, but to be sure I verified with a DNS query with the RDS endpointdig a mysql-foo.1knj23n.eu-central-1.rds.amazonaws.com. This did indeed return the IP I was expecting.</p><p>At this point we know the original Traffic Bill of 3.7 TB which costs us $333 includes a 1.9 TB cross-zone traffic from MySQL to our instance. This is pretty good information: I know it’s worthwhile to either optimize database access (there may be an app pushing ridiculous amounts of data), or consolidate everything into a single availability zone (with failovers in other zones).</p><h3>Useful queries</h3><p>Presented mostly without commentary.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/468e5871352ec8431556381b466971fd/href">https://medium.com/media/468e5871352ec8431556381b466971fd/href</a></iframe><p>Check if there are no outlying external recipients:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e5d1558cdb41360df28123f5b4a73a24/href">https://medium.com/media/e5d1558cdb41360df28123f5b4a73a24/href</a></iframe><p>Disclaimer: reproducing those steps will incur multiple additional charges from Amazon. You will pay for the Flow Log as for any CloudWatch. Exporting the logs to S3 and downloading the files will also cost you some.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=365f5e07c808" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Blender Rendering on AWS P2]]></title>
            <link>https://medium.com/@Mikulas/blender-rendering-on-aws-p2-61f7fb8405d8?source=rss-494df6d4c162------2</link>
            <guid isPermaLink="false">https://medium.com/p/61f7fb8405d8</guid>
            <category><![CDATA[blender]]></category>
            <category><![CDATA[aws]]></category>
            <dc:creator><![CDATA[Mikuláš]]></dc:creator>
            <pubDate>Fri, 28 Jul 2017 07:48:42 GMT</pubDate>
            <atom:updated>2017-07-28T07:48:42.734Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>This article is an incomplete draft, but I figured there are some interesting snippets that could help someone.</strong></p><p>This post documents how I set up my own low cost GPU Render Farm on Amazon Web Services.</p><p>Obviously, you first need and AWS account. The registration is pretty straight forward. You need to enter your credit card, but don’t worry, you will be only charged a dollar or so as a verification, which will be refunded. Head over to <a href="https://aws.amazon.com/">https://aws.amazon.com/</a> and set up an account.</p><p>AWS offers multiple services, but we will only use their EC2 service; it’s similar to renting a virtual server. There are <a href="https://aws.amazon.com/ec2/instance-types/">many types of those servers</a>, varying by amount of cores/CPUs, available RAM, network bandwidth etc. We will be using <a href="https://aws.amazon.com/ec2/instance-types/p2/">P2 instances</a> which have <a href="http://www.nvidia.com/object/tesla-k80.html">NVIDIA Tesla K-80</a>. A single P2 instance may contain up to 16 of those GPUs!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DHW8avfixdUdmacFNNZPtA.jpeg" /><figcaption>A single NVIDIA Tesla K-80 card. Photo by <a href="https://www.flickr.com/photos/ibm_media/19316857560">ibmphoto24</a>.</figcaption></figure><h3>P2 Instance Pricing</h3><p>P2 are AWS EC2 instances dedicated for working with GPUs. There is a simple trick to saving over 70 % costs: <a href="https://aws.amazon.com/ec2/spot/">Spot Instances</a>. There are many differences to traditional instances, but none effect us when used for rendering. For $0.25 / hour, we can basically rent a machine with 61 GB RAM and a single K-80. Given that <a href="http://www.anandtech.com/show/8729/nvidia-launches-tesla-k80-gk210-gpu">retail price of K-80 is $5000</a>, you would need to render for 20,000 hours to get even; that is over 2 years of continuous rendering. Also, there would be power costs, which at 300W are nontrivial.</p><p>There are even larger instances: namely p2.8xlarge and p2.16xlarge. Those contain 8 and 16 K-80s respectively, for linear increase in price.</p><p>Note that <a href="https://aws.amazon.com/premiumsupport/knowledge-center/ec2-instance-hour-billing/">AWS bills per-hour</a>. This means you pay the same price whether you terminate the instance after 10 minutes and 59 minutes. Meaning that if your scene takes an hour to render on xlarge, it will presumably take an eighth of that on 8xlarge: roughly 8 minutes. You would still pay for a full hour. The render would be faster, but also more costly. However, if the original render would take 8 hours on xlarge, you would completely render it in one hour on 8xlarge and for the same price!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*j8g7HwqWlB8pJa5jEUQxgw.png" /><figcaption><a href="https://aws.amazon.com/ec2/pricing/on-demand/">P2 pricing table from AWS</a>, with Spot Price included as observed be me. Spot pricing for p2.16xlarge is fluctuating a lot and the price is often more than on-demand.</figcaption></figure><h3>Applying for P2 Instances</h3><p>Most resources on AWS are available on-demand out of the box. Alas, P2 instances are presumably in high demand and are very resource constrained, so you need to issue a one-time support request to gain access to those. In the AWS Dashboard, open Services, navigate to EC2, and select Limits in the left-side panel. Click any of the <em>Request limit increase</em> links on top of the page. This will take you to a support ticket editor.</p><p>First thing in the support request you need to fill is a Region. It denotes a place on Earth and you should generally pick the one closest to you that actually has P2 instances. If you are on the West coast go for Oregon, on the East coast select Northern Virginia and for Europe, pick Ireland. For other continents consult <a href="https://aws.amazon.com/ec2/pricing/on-demand/">these tables</a>.</p><p>Next up you need to pick a <em>Primary Instance Type:</em> pick p2.xlarge. Afterwards, a new field labeled <em>Type Limit</em> will appear already populated with value <em>Instance Limit</em>, leave it at that. Finally, fill in a <em>New limit value.</em> It’s unlikely you will need more than 1 instance at a time, so enter 1.</p><p>Click <em>Add another request beneath </em>and repeat those steps for p2.8xlarge. (You don’t need to also add p2.16xlarge as it’s very costly and not available for spot requests.)</p><p>In the Use Case description, truthfully enter what you need the instances for. I submitted this:</p><blockquote>Hi, I’m setting up a spot request based personal render farm. Thanks</blockquote><p>The next day the ticket was resolved, my request was approved and I was given access to P2 instances.</p><h3>Preparing Instance</h3><p>TODO HOW TO EXEC AND CONNECT TO AWS</p><p>To fully utilise P2 instances, K-80 drivers need to be installed. AWS has <a href="http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/accelerated-computing-instances.html#install-nvidia-driver">great tutorial here</a>, or you can follow this script (it involves multiple reboots so don’t just blindly paste it):</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d7e2ab8592e2b38e97fb741b3156d445/href">https://medium.com/media/d7e2ab8592e2b38e97fb741b3156d445/href</a></iframe><p>Finally, install Blender:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/93e64538d11a494a2fcc847e727241df/href">https://medium.com/media/93e64538d11a494a2fcc847e727241df/href</a></iframe><h3>Rendering</h3><p>Thanks to <a href="https://blender.stackexchange.com/questions/5281/blender-sets-compute-device-cuda-but-doesnt-use-it-for-actual-render-on-ec2">Ritwik and Ben Jaguar Marshall</a>, I came up with this setup for rendering on GPU on P2 EC2 AWS instance:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/436503516e8b1171e58d6877c5616451/href">https://medium.com/media/436503516e8b1171e58d6877c5616451/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=61f7fb8405d8" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>