<?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 Ryan van Niekerk on Medium]]></title>
        <description><![CDATA[Stories by Ryan van Niekerk on Medium]]></description>
        <link>https://medium.com/@iamnayr?source=rss-92caf99bbe36------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*Kjcw61JezbvAqVtIx2hUdQ.jpeg</url>
            <title>Stories by Ryan van Niekerk on Medium</title>
            <link>https://medium.com/@iamnayr?source=rss-92caf99bbe36------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 06:41:46 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@iamnayr/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[2.5 months on the Ketogenic diet: How Keto has impacted my life]]></title>
            <link>https://medium.com/@iamnayr/2-5-months-on-the-ketogenic-diet-how-keto-has-impacted-my-life-fca8e9adb790?source=rss-92caf99bbe36------2</link>
            <guid isPermaLink="false">https://medium.com/p/fca8e9adb790</guid>
            <category><![CDATA[health]]></category>
            <category><![CDATA[developer]]></category>
            <category><![CDATA[diet]]></category>
            <category><![CDATA[keto]]></category>
            <category><![CDATA[ketogenic-diet]]></category>
            <dc:creator><![CDATA[Ryan van Niekerk]]></dc:creator>
            <pubDate>Thu, 12 Jul 2018 18:45:20 GMT</pubDate>
            <atom:updated>2018-07-12T18:45:22.479Z</atom:updated>
            <content:encoded><![CDATA[<p>Just over two months ago I began my transition over to a strict <a href="https://www.perfectketo.com/guide/the-ketogenic-diet/">Ketogenic diet</a>. At the time I had very little understanding of what being on a Ketogenic diet meant, what the effects would be on my body, the core metabolical differences and basically <strong>0 expectations as to what might occur</strong>. I’ve always been the type to dive into things and learn while fully immersed in the subject, so why treat a dietary change any differently?</p><p>A <a href="https://irok.co/">good friend of mine</a> suggested that we make the transition together (thank god for this, It would have been much more difficult without her guidance early on). Here is the full story of my Ketogenic transformation in hopes that it can help inspire or motivate someone that can’t quite make it over the mental hurdle to switch to a Keto diet to improve their own quality of life.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*JQdBXnfjyD5V9iWFSuHlRQ.jpeg" /><figcaption>More pics further down in the post</figcaption></figure><h3>My life prior to Keto</h3><p>It’s hard to talk about the progress I’ve made without first touching on where I began, or what my diet was like prior to Keto. For the last 4–5 years I really made it a conscious effort to be a more active person. In 2016 I spent 10 months of my life working with a personal trainer 4–5 days a week at Equinox to help me achieve my fitness goals. I really gained a ton of knowledge about fitness in general, but never made the dietary aspect of my life a priority. I effectively used my gym time as a “get out of jail free card” in the sense that because I was so active that I could basically eat whatever I wanted all the rest of the time and still come out ahead.</p><p>I never had much of a relationship with the foods I ate. I wasn’t particularly interested in cooking and much preferred the convenience of simply ordering in or walking down the street to grab a quick take-out meal. For the most part I engaged in what is known as SAD, or the Standard American Diet. The majority of the food I took in was made up of Carbohydrates. Hell, I didn’t even know or care for the most part what that actually meant. One of my favorite breakfast options for a long time was a fresh, homemade fruit/veggie shake nearly every morning. I’d cram as much fruit and veggies along with some frozen packets of Acai berry and assumed I was getting a healthy dose of everything my body needed to function like a normal human being. I was likely getting upwards of 100g of sugar in a single drink.</p><p>Around the same time I started working out heavily, I noticed some not-so-great side effects that were starting to take a toll on my body. For starters I’ve lived with a <a href="https://ketovirgin.com/ketogenic-diet-for-tmj-disorder/">chronic TMJ disorder</a> for nearly 15+ years of my life. It’s something that started out as an annoyance as a teenager that I easily ignored as so many of us do. In my mid to late 20’s however, the pain and inflammation were relentless, the DOMS effects of a workout were multiplied by 5x at times, making my life an endless cycle of discomfort for the most part.</p><p>On top of my chronic TMJ disorder I also began to develop a series of heart related complications. Occasionally during a workout my heart rate would make a rather drastic jump from the low 100’s to right around 220 or so. We’re not talking a gradual build-up, but a lose-your-breath, holy-shit I’m about to die type of shift. In 2017 I had to have a friend call 911 while I was sprawled out on the pavement after my heart rate remained over 200bpm for nearly 2 hours. That day I was diagnosed with SVT. My options were to live with it permanently, take medication until I die or have wires stuck into my heart to burn off the problematic tissue. It’s been a constant part of my life since.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2Ft2fBjFjuURc%3Fstart%3D5%26feature%3Doembed%26start%3D5&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3Dt2fBjFjuURc&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2Ft2fBjFjuURc%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/71ea1900fb2fdf7930a94a2b1bd6b405/href">https://medium.com/media/71ea1900fb2fdf7930a94a2b1bd6b405/href</a></iframe><p>I began to have moderate to severe sleep related disorders on top of everything else that already plagued me- waking up gasping for air, constantly twitching and flailing my limbs around, waking up feeling like a zombie and even suffer recurring episodes of <a href="https://en.wikipedia.org/wiki/Sleep_paralysis">sleep paralysis</a> (this one is truly fun for those of you that aren’t familiar).</p><p>The combination of these problems truly began to compound and weigh heavily on my day-to-day ability to function. There were few days where I was able to make a solid 8 waking hours without feeling like ready to collapse. I was plagued with anxiety, constant digestive discomfort, vision and auditory problems (tinnitus anyone??), rapid mood swings, etc. There were very few aspects of my life that weren’t negatively affected by this spectrum of problems. Relationships, friendships and basically every portion of living a normal life were thrown totally out-of-whack. My life became a constant cycle of bearing as much pain as possible before either lashing out or shutting down completely. Needless to say, I was very sick.</p><p>As of 2018, I’ve spent well over $30k out of pocket seeing countless specialists, dentists and all manner of holistic healing practitioners with only mild, temporary relief. I never truly considered that the crux of nearly all of my chronic issues could have been something as simple as my diet. It seemed too obvious, something was <strong>WRONG</strong> with me, other people eat these foods and get by just fine…why would I be any different? I thought my problem was purely physiological, a muscle strained or in spasm, a joint malfunctioning, crooked teeth…something..ANYTHING.</p><h3>Enter Ketosis</h3><p>Fast-forward to the first week of May 2018, <strong><em>Tuesday May 1st 2018</em></strong> to be specific. After talking with my friend I was fairly easily convinced to try this Keto thing out. She told me about a<a href="https://www.netflix.com/title/80238655"> documentary on Netflix</a>, I checked it out and was very intrigued. It seemed like a fun experiment and I’m never one to turn down a good challenge in my life. Hell, if a diabetic can basically stop using all of their medication after a couple months of Keto, surely I’ll reap some benefit from the switch, right?!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*edBnwDsIE-dRoHjCWWlztg.jpeg" /><figcaption>My first “keto” meal. I went to Chipotle because I didn’t have groceries for this.</figcaption></figure><p><strong>Week 1 — I think I’m dying</strong></p><p>I won’t lie to you, this week was grueling. My laundry list of health complications was only exasperated further. My heart felt like it was completely unhinged, beating out of control at times, skipping beats at others. My brain felt like San Francisco during the summer time, constantly and completely shrouded in fog. I could hardly keep my eyes open. Nearly all of my muscles were cramping or spasming.</p><p>I was suffering from <a href="https://www.healthline.com/nutrition/keto-flu-symptoms#what-it-is">The Keto Flu</a>, a well documented and common series of symptoms that nearly all Keto noobs succumb to. It’s the part of the journey where most will fail. As I’m so prone to do, I set out to solve my problems. I dove into all of the research about Keto that I could get my hands on. I bought books on Amazon, dove deep in to the Keto subreddit and spent every waking minute immersed in Keto-land.</p><p>I landed on a few key findings: <a href="https://ketovirgin.com/how-much-salt-should-i-eat-on-ketogenic-diet/">I needed to supplement my electrolytes more.</a> My body was craving more salt, more sodium, more fat. I was learning very quickly that my old lifestyle of eating out simply wasn’t going to fly with my new Keto self. I had to start cooking my own food. I had to start eating high-quality meats and cheeses and whole foods. I was completely shocked at the realization that almost EVERY SINGLE item of food we consume is fortified with sugar. I had to eliminate 95% of the things in my cupboard and fridge (I HIGHLY encourage this “keto-purge”).</p><p>With these realizations I was able to push through some of the most difficult days I have experienced in recent times. Nearing the end of week one, I felt more like my “old” carb-reliant self, only my body had undergone a dramatic shift. I was now in <a href="https://ketodash.com/blog/what-is-ketosis/">Ketosis</a>. My body no longer relied on sugar and carbohydrates to power my brain. <strong>I was totally reliant on fat</strong>. Whoa.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NYNnycP9-DBTNu-olQrzrg.jpeg" /><figcaption>My first time testing “positive” for being in Ketosis</figcaption></figure><p><strong>Week 2 — BRB, going to Europe</strong></p><p>Admittedly the timing was quite poor here, but low and behold at the very beginning of week 2 of totally changing everything about the way I eat, I was heading to Europe for a 10 day trip. I was almost completely sure the diet would fall apart early on in my travels, but I had made it through the most difficult phase already and was motivated to give it my best shot.</p><p>I recommend taking a look at the blog post that I wrote immediately after coming back from my trip as I talk in detail about how I was able to remain on a relatively <a href="https://ketovirgin.com/5-tips-for-traveling-on-a-ketogenic-diet/">strict Ketogenic diet while traveling</a>. In short, I pulled through and with a bit of perseverance I was able to remain Keto adapt while traveling.</p><p>I also noticed a rather dramatic revelation during my trip. It wasn’t so much a sudden change, but almost every day around noon or so I noticed that my normal cycle of pain and inflammation was actually <em>decreasing </em>rather than getting progressively worse throughout the day. I was feeling better as the day went on. This was…unusual…to say the least.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TFuUCGz8oJTKWA47Or8Z2A.jpeg" /><figcaption>An airport quality Keto meal, packaged cheese and meat</figcaption></figure><p>A secondary side-effect that was completely out of the ordinary for me was the almost complete and utter absence of jet lag, something I have never experienced while traveling internationally. Normally around the second or third day I would start waking up closer to noon or 1pm after having struggled to fall asleep all night. Yet here I was, sleeping like a baby at night and waking up fully refreshed every morning around 9am. My energy levels were consistent through the day, I was extremely active and my body wasn’t telling me it needed any sort of break.</p><p>I still was extremely weary of crediting any of the side-effects to Keto, being the natural skeptic that I am. It was just too early to claim victory.</p><p><strong>Week 3–4 — I feel good, like really, really good</strong></p><p>Having reached the conclusion of my trip, I returned home. Once more I was rewarded with the sheer pleasure of experiencing 0 jet lag. I transitioned right back into my normal work schedule. It was business as usual, only I was drinking the Keto koolaide more than ever.</p><p>The anti-inflammatory effects I started to experience during my trip were becoming more and more a constant, and much welcomed, benefit. My neck, jaw, shoulder and back muscles were starting to release more and more with every day that passed. In turn, my anxiety was starting to melt away, my digestion was starting to regulate, I wasn’t a hungry ravaging animal 24/7 and I was sleeping normally for what felt like the first time in…forever.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*guEhtbmqd1K2mYLyrSxLAQ.jpeg" /><figcaption>A selection of Keto friendly dressings I acquired along the way.</figcaption></figure><p>Nearly all of the symptoms I’d attributed to my TMJ disorder were rapidly diminishing to the point where I was having days where I dared to call myself “normal”. I was so inspired by what I was experiencing that I started the very blog you are reading that very same week. I felt like I was undergoing, for lack of a better term, a personal rebirth. I was no longer a slave to my body. I was in control of my mind. I was a smart, functional, stable person. The normality I had craved for so long was no longer a fever dream. It felt achievable, I could taste it.</p><p>I doubled-down on every aspect of the diet. I was cooking every meal, I was only eating high-quality, pasture raised meats (grass-fed of course..). I shied away from social engagements that revolved around eating. I lived and breathed fats. Coconut oils, avocados, butter, ghee, bacon, steaks, nuts. Food became my <strong>FUEL.</strong></p><p><strong>Week 5–8 — Ok. I’m a believer now.</strong></p><p>The past month has really only been about fine-tuning what knowledge I had already gained during the first 30 days. I found out I needed to <a href="https://ketovirgin.com/how-much-salt-should-i-eat-on-ketogenic-diet/">eat a bunch more salt</a>. I’m now intermittently fasting almost every day. I tend to not really even have hunger cravings around lunch time, if I do it usually means I didn’t get enough sodium earlier in the day.</p><p>My days don’t revolve around mealtime any longer. I eat when I get hungry, otherwise I don’t really think about food. It’s truly a liberating feeling. For my entire life I was always looking forward to the next time I would eat a meal. My social life mainly revolved around going out to eat with friends. If I wasn’t eating a meal, my brain was craving sugar. “Go walk across the street and buy a chocolate chip cookie from the local bakery”. I wasn’t in control of my own mind, sugar was driving my thoughts. My energy levels, much like my mood, were like a roller coaster in complete darkness.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0ANnJ0IiLkYd6Kz6nkN-8A.jpeg" /><figcaption>A bunch of Keto friendly supplements. Powdered bone broth is an…interesting…one.</figcaption></figure><p>My transformation into Keto has only just begun, yet I can’t imagine for one second going back to my prior lifestyle. It’s been such a dramatic transformation in quality of life for me. <strong>Nearly every derogatory health issue I’ve experienced for so long has either diminished greatly or been eradicated.</strong> Even the cardiovascular problems that made it so difficult to live an active lifestyle have remained under control. I workout almost every day again without my heart becoming a runaway train.</p><h3>Yeah, but are you HEALTHY?</h3><p>I’ve had plenty of concerned friends and family ask me about the longevity of this diet. They are concerned for my cholesterol levels and a myriad of other things that we’ve come to accept as fact in our everyday lives (like that carbs are a crucial part of our livelihood). Needless to say, Keto for me has turned much of my life upside-down. The answer is…I don’t know if I’ll remain Keto forever. There are plenty of long-term case studies that mostly show nothing but positive effects. I do know this: I feel<strong> DAMN</strong> good.</p><p>I had full blood work analysis done during the first week of my Ketogenic transition and as recently as two weeks ago. I’m functioning well within normal limits. My body and mind feel better than ever. I don’t ever remember my skin, hair and nails looking as nice as they do. I sleep for the most part like a normal functioning person would (I noticed I just need LESS sleep now). I’ve dropped close to 10lbs in weight and have more muscle mass and am leaner than I’ve ever been.</p><p>How do you even define “healthy”? I would pose another question in response: “<strong>Is your body telling you that things are OK?</strong>”. One of the most important things I’ve learned from this experience is that our bodies are VERY attuned at telling us what they need. On a sugar and carb heavy diet, the thing our bodies need the most is MORE SUGAR. One thing matters to your brain more than anything else: energy. Without energy, we die. On a standard carb diet our bodies rely on the constant influx of sugar and glycogen to remain energized, tapping into our fat stores only in desperation or during periods of long-term activity.</p><p>I’ve only just begun to understand some of the subtle ways my keto-adapt body hints to me what it needs, but the important point is that I’ve been able to acknowledge that this form of non-verbal communication exists. It just manifests in the form of a cramp in my leg, or a spell of dizziness, which is my body saying: <strong><em>HEY, EAT MORE SALT DUMMY</em></strong>.</p><h3>Pictures</h3><p>Admittedly I didn’t do a good job of taking pictures in the initial stage of the transformation, mainly because I hate taking pictures of myself and find it a bit cringeworthy (also I didn’t expect such a drastic change). However I thought it would be worthwhile to start documenting my journey more thoroughly, so here are some pics as of ~2 weeks ago.</p><p>It’s worth mentioning at this stage I’m hitting the gym ~3–4 times a week, but haven’t changed anything else in my routine aside from being Ketogenic.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*D0cl0IMz0gBJSv7mX9x-Nw.jpeg" /><figcaption>Back shot</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*mWTMCXo4KCHiZn8aaN98DA.jpeg" /><figcaption>Side profile</figcaption></figure><h3>Looking ahead</h3><p>I’ve been so inspired and motivated by the changes I’ve encountered during this experience that I started both a <a href="https://ketovirgin.com/">Ketogenic blog</a> and <a href="https://shop.ketovirgin.com/">Ketogenic Shop</a> to encourage and assist others with making the switch to this lifestyle.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1003/1*1zyXGGoFGLBrvjtUhEJ4rA.jpeg" /><figcaption>The logo for my new company</figcaption></figure><p>Some of the most common questions I’ve received are as follows:</p><p><strong>“Yeah but is that Keto thing sustainable?</strong>” — Yes, 100%. As long as my body doesn’t tell me otherwise. In terms of finances, I’m also saving money because I don’t eat out and I meal prep all the time.</p><p><strong>“Don’t you miss X?”</strong> — Nope, not really at all. I don’t crave sugar anymore. I don’t crave carbs at all. For the rare occasion where I just have to have something sweet, I’ll make an alternative with some 0 sugar, 0 carb sweetener and some combination of almond flour or coconuts. Simple.</p><p><strong>“But have you tried like, being a vegan or something?” — </strong>No. I love meat. And you don’t undergo any metabolic transformations in those <strong>other </strong>diets.</p><p><strong>“Are you crazy?</strong>” — I suppose so, but only in the sense that it took me so long (29 years to be exact) to figure out that maybe there is something to this whole “food is medicine” thing.</p><p><strong>“You’re dumb” </strong>— Well, that’s just like…your opinion man.</p><p>If there is one last nugget I leave you with, let it be this. Since the beginning of our existence some two and a half million years ago, fat and protein have been the dominant macronutrients in our diets. We didn’t have endless supplies of agriculturally farmed foods. We hunted animals and ate basically every last scrap of them. A Keto adapted diet is arguably the closest you can be to a “natural” human..if you believe in evolution that is. To quote <a href="https://www.marksdailyapple.com/mark-sisson/">Mark Sisson</a>: <strong>Human metabolism is pre-programmed by evolution to be primarily fat-based.</strong></p><p><em>Eat more fat. Don’t be a slave to sugar.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fca8e9adb790" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to write faster, leaner Dockerfiles for Node with Yarn and Alpine]]></title>
            <link>https://medium.com/@iamnayr/a-multi-part-analysis-of-node-docker-image-sizes-using-yarn-vs-traditional-npm-2c20f034c08f?source=rss-92caf99bbe36------2</link>
            <guid isPermaLink="false">https://medium.com/p/2c20f034c08f</guid>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[node]]></category>
            <category><![CDATA[yarn]]></category>
            <category><![CDATA[npm]]></category>
            <dc:creator><![CDATA[Ryan van Niekerk]]></dc:creator>
            <pubDate>Thu, 23 Feb 2017 22:38:33 GMT</pubDate>
            <atom:updated>2017-03-10T00:04:45.255Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AXKFHIhiZzmYZwo1J3On9g.png" /></figure><p><strong>TLDR; </strong>Utilizing <a href="https://yarnpkg.com/en/">Yarn</a> in place of NPM for your node dependency management is an easy win with Docker, combined with taking advantage of smaller base images like Alpine and it becomes a no-brainer if you are looking to trim the fat of your Docker images. In some cases (as demonstrated below), you can save close to <strong>90%</strong> of the original image size and shave valuable time off of your builds. A <strong>Yarn</strong> + <strong>Alpine</strong> build yields <strong>640mb</strong> of size and over <strong>30</strong> seconds of time over a traditional <strong>Node</strong> + <strong>NPM </strong>standard image in this simple example<strong>.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1023/1*Pn625PmGuWFqxBny61BnAA.png" /><figcaption>Summary of image sizes and build times</figcaption></figure><h3>Overview</h3><p>One of the goals the Operations team at <a href="http://www.lonelyplanet.com/careers/">Lonely Planet</a> has is to define standards for our Docker development and build processes. Part of this goal is to determine how we balance the trade-off of size vs simplicity in terms of our Docker images. Often times there are significant savings in image artifact size with very little added complexity just by utilizing a different base image. We prefer to deploy “slim” images to our Kubernetes clusters whenever possible, as they are faster to build, publish and run (and subsequently roll-back if necessary).</p><p>There are <a href="https://www.datawire.io/not-engineer-running-3-5gb-docker-images/">no shortage</a> of <a href="http://chrisstump.online/2016/02/23/docker-image-reduction-techniques/">posts</a> explaining <a href="http://dev.im-bot.com/docker-reduce-image-size/">how to slim</a> your images down, this post won’t necessarily be an exercise of that. Instead it focuses specifically on Node applications, comparing two base images (<a href="https://hub.docker.com/r/library/node/tags/6.9.5-alpine/">Alpine base image</a> and the standard <a href="https://hub.docker.com/r/library/node/tags/6.9.5/">Node base image</a>) and how the usage of Yarn as opposed to NPM affects the overall size of the image artifact.</p><p>I will also do an analysis on how utilizing Alpine and Yarn affects our overall image build times, as these are very relevant metrics.</p><p>All build time metrics should take into consideration I’m running these tests on a Late 2013, 15-inch Macbook Pro with 16 GB ram and 2Ghz Intel Core i7. All tests were performed using <a href="https://docs.docker.com/docker-for-mac/">Docker for Mac</a> version 1.13.1-rc2-beta41</p><p>Build time metrics also include a “<strong>cold</strong> build” and a “<strong>warm</strong> build”. Cold means the <strong>FROM</strong> image was not available on the host already. Warm means the <strong>FROM</strong> image was already fetched and available locally, without any additional layer caching.</p><h3>Setting up our application</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/823/1*KNAbh2FWrdQFOGpiN2it2g.png" /><figcaption>Our kickstart application</figcaption></figure><p>Our Node app paradigm will utilize <a href="https://github.com/vesparny/react-kickstart">react-kickstart</a> starter kit (I found it <a href="http://andrewhfarmer.com/starter-project/">here</a>) as I believe it accurately reflects the base state of many modern Node web applications (node + babel + react). You can see the finished product at my <a href="https://github.com/thenayr/react-webpack-babel">forked repository</a>. There is a feature branch for each image type (node-npm, node-npm-slim, node-yarn, node-yarn-slim)</p><p>For brevity sake, I will not be using docker-compose in this project, our only goal is to determine the production image artifact size, so development niceties like volumes and onbuild commands will be purposefully omitted. The Dockerfiles will also be constructed in a knowingly lazy manner, do <strong>not</strong> copy them.</p><h3>Bootstrapping our bootstrapper</h3><p>This section is intentionally brief and won’t explain much of what is happening. The summary is that we add a shell script that will run the webpack build command to generate our production artifacts followed by executing our Node server application.</p><h4>Docker image 1 — Node base image + NPM</h4><p>Our first image will utilize the standard Node 6.9.5 base image.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8a8dc7152e33f8d0a9263c308b4321c5/href">https://medium.com/media/8a8dc7152e33f8d0a9263c308b4321c5/href</a></iframe><p>Running docker build and docker run gets our app into a “production” ready state, our image contains all of the dependencies it needs to run.</p><p>Here are the build times for this image:</p><ul><li>Cold build: <strong>119 seconds</strong></li><li>Warm build: <strong>89 seconds</strong></li></ul><p>Using Microbadger we can see a breakdown of our total (<a href="https://github.com/docker/hub-feedback/issues/331">compressed</a>) image size:</p><p><a href="https://microbadger.com/images/thenayr/node-npm">MicroBadger - thenayr/node-npm</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/656/1*RU0XF0AqIPfUe0XGmBhM0w.png" /><figcaption>Microbadger for Node + NPM image</figcaption></figure><p>Compressed the image is <strong>282MB</strong>, uncompressed on disk it is <strong>742 MB</strong>. I would consider this a fairly bloated image considering how very little the application is doing.</p><pre>REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE<br>thenayr/node-npm    6.9.5               3954ac331877        2 hours ago         742 MB</pre><h4>Docker image 2 — Alpine Node base image + NPM</h4><p>Now let’s switch out the base image to an Alpine base and see what how much space we save:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fe6afcd68897b5eb7e6d37d8fce01bb9/href">https://medium.com/media/fe6afcd68897b5eb7e6d37d8fce01bb9/href</a></iframe><p>Here are the build times for this image:</p><ul><li>Cold build: <strong>99 seconds</strong></li><li>Warm build: <strong>91 seconds</strong></li></ul><p>Let’s check out Microbadger again and see how this image stacks up:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/758/1*4v3h5ITefgKdZG-AhdamwQ.png" /><figcaption>Microbadger image layer size breakdown</figcaption></figure><p>It is obvious right away that the image we are inheriting from: node:6.9.5-alpine is significantly smaller (<strong>16mb vs 245mb</strong>).</p><p>Our total compressed image size is now only <strong>51.8MB</strong>, an 80% reduction.</p><pre>REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE<br>thenayr/node-npm    6.9.5-alpine        4298630b62dc        About an hour ago   132 MB<br>thenayr/node-npm    6.9.5               3954ac331877        2 hours ago         742 MB</pre><p>The total on-disk image size is also significantly smaller, <strong>132MB</strong> compared to <strong>742MB</strong>.</p><h4>Docker image 3 — Node base image + Yarn</h4><p>Yarn promises us three benefits over using standard NPM to install depedencies: consistency, speed and security. All three of these things become even more important in a Dockerized environment. Let’s take a look at how it impacts our image size.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0129909c3e186c3b6adda56f0407a196/href">https://medium.com/media/0129909c3e186c3b6adda56f0407a196/href</a></iframe><p>A couple things worth noting here, it takes a <a href="https://github.com/docker/docker/issues/7477">bit more work with Yarn</a> to replicate the behavior of npm prune --production. The end-game is to be able to build our app for production mode, but then remove all of the non-production dependencies from our image. For this we utilize a custom script to iterate over devDependencies and delete each one. Yarn also caches modules in a directory *outside* of node_modules we need to run an extra step to remove those from our image: yarn cache clean.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dffd5a5edc12f6c412e72570ed5f3754/href">https://medium.com/media/dffd5a5edc12f6c412e72570ed5f3754/href</a></iframe><p>Here are the build times for this image:</p><ul><li>Cold build: <strong>110 seconds</strong></li><li>Warm build: <strong>78 seconds</strong></li></ul><p>So let’s see how this image stacks up:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bnSkJ3x80Ee8RP4zC_V4HQ.png" /><figcaption>Microbadger for Node + Yarn</figcaption></figure><p>This one weighs in at <strong>259MB</strong> compressed, compare to our first image (Node + NPM) which came in around <strong>280MB</strong>. Saving us around <strong>8%</strong>. On disk they come in at <strong>706MB </strong>(yarn)<strong> </strong>and <strong>742MB</strong> (NPM) respectively. Not too bad for such an easy switch.</p><pre>REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE<br>thenayr/node-npm    6.9.5-yarn          e0c6ba52878a        8 minutes ago       706 MB<br>thenayr/node-npm    6.9.5-alpine        4298630b62dc        18 hours ago        132 MB<br>thenayr/node-npm    6.9.5               3954ac331877        19 hours ago        742 MB</pre><p>Here is a breakdown of all of our current images. Alpine + NPM is in the lead by far, weighing in at a paltry <strong>132MB</strong>.</p><h4>Docker image 4 — Alpine Node base image + Yarn</h4><p>Our last and final image will be built using our earlier Alpine image, with Yarn in place of NPM for installing our packages.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2c64caa75bad58e584f3a36c189b100a/href">https://medium.com/media/2c64caa75bad58e584f3a36c189b100a/href</a></iframe><p>Our Dockerfile doesn’t change much from the previous yarn image, we just inherit from the Alpine base image now.</p><p>Here are the build times for this image:</p><ul><li>Cold build: <strong>86 seconds</strong></li><li>Warm build: <strong>79 seconds</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HEQ2RHkq2pqIsXwD1cULTw.png" /></figure><p>Our new compressed image size is a mere <strong>29MB</strong>! That’s pretty impressive even in comparison to our first Alpine image which totaled around <strong>51MB</strong>. We shaved off over <strong>50%</strong> of an already small image.</p><p>Uncompressed the image comes in around <strong>97MB</strong>, reasonable by any means. Let’s tally up all of the uncompressed image sizes:</p><pre>Repository           Size<br>6.9.5-alpine-yarn :  97.7 MB<br>6.9.5-yarn :         706 MB<br>6.9.5-alpine :       132 MB<br>6.9.5 :              742 MB</pre><p>Our final image (alpine + yarn) is just <strong>13%</strong> the size of our first image! Pretty impressive results.</p><h3>Summary</h3><p>Yarn <strong><em>will</em> </strong>yield you faster Docker images. It seems like an obvious choice to start migrating over to Yarn. It’s backwards compatible with most of the critical functions of NPM and is an easy win. It has the biggest effect on build time from our testing as the benchmarks for Node vs Node-Alpine didn’t make a huge difference in terms of <strong><em>warm</em></strong> build time.</p><p>In the words of the great Shia Labeouf:</p><blockquote><strong>DO IT</strong>.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/718/1*R8MkLCQOiL2wjBYcQ61R-w.gif" /><figcaption>DO IT.</figcaption></figure><p>With increased support by many NPM modules, it also makes sense to start migrating your Node images over to Alpine. It’s worth mentioning that in this really basic example there aren’t a whole lot of factors in play, so a more in-depth application might encounter some difficulty, for example, missing build utilities etc.</p><p>In both scenarios we tested, there are significant time savings in using both Yarn and Alpine for <strong><em>cold</em></strong> builds. The initial <strong>FROM</strong> image fetch is much quicker when that layer is 10’s of MB instead of 100’s.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2c20f034c08f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building the Kubernetes virtual reality experience]]></title>
            <link>https://medium.com/@iamnayr/building-the-kubernetes-virtual-reality-experience-b681464f0c98?source=rss-92caf99bbe36------2</link>
            <guid isPermaLink="false">https://medium.com/p/b681464f0c98</guid>
            <category><![CDATA[virtual-reality]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[vr]]></category>
            <category><![CDATA[docker]]></category>
            <dc:creator><![CDATA[Ryan van Niekerk]]></dc:creator>
            <pubDate>Tue, 22 Nov 2016 20:09:08 GMT</pubDate>
            <atom:updated>2016-11-22T22:07:54.663Z</atom:updated>
            <content:encoded><![CDATA[<h3>Kubernetes in virtual reality: Building the K8s VR experience</h3><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FQb1siOeTIrk%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DQb1siOeTIrk&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FQb1siOeTIrk%2Fhqdefault.jpg&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/72ce6426e10e229ee4962d6121ccdfa3/href">https://medium.com/media/72ce6426e10e229ee4962d6121ccdfa3/href</a></iframe><p><strong>TLDR;</strong></p><p>I made a Kubernetes pod visualizer / interactive experience for the HTC Vive. You can try out the code from the following repos:</p><ul><li>Frontend: <a href="https://github.com/thenayr/kuberentes-vr-frontend">https://github.com/thenayr/kuberentes-vr-frontend</a></li><li>API: <a href="https://github.com/thenayr/kubernetes-vr-api">https://github.com/thenayr/kubernetes-vr-api</a></li></ul><p>If you want to run it in VR mode, you MUST have the following:</p><ul><li>HTC vive</li><li>Experimental build of Chrome from <a href="http://webvr.info/">http://webvr.info</a> (<a href="https://github.com/Web-VR/iswebvrready/wiki/Instructions%3A-Chromium-for-HTC-Vive-on-Windows">Make sure to read all of the instructions to enable the required flags!</a>)</li><li>A local Kubernetes cluster and a running kubectl proxy --port=8090 (I recommend <a href="https://github.com/kubernetes/minikube">Minikube</a> for this)</li><li>The API server linked above running locally.</li><li>The Frontend linked above running locally.</li></ul><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FlipBMZ4andI%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DlipBMZ4andI&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FlipBMZ4andI%2Fhqdefault.jpg&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;schema=youtube" width="640" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/468f94188a9af179900eb1211a3ef1bb/href">https://medium.com/media/468f94188a9af179900eb1211a3ef1bb/href</a></iframe><p>This is the first project I’m aware of that attempts to bring virtual infrastructure into an interactive Virtual Reality world. Before I dive into the more technical aspects about why you are likely here in the first place (Kubernetes in virtual reality), I just want to take a moment to acknowledge what an incredible community we have supporting the Kubernetes project. I’ve been an avid user for just under a year now, and have never been more excited to profess my love for a piece of open-source software.</p><p>It’s truly GAME changing (please excuse the pun) for the technology community as a whole. The <a href="https://www.google.com/url?sa=t&amp;rct=j&amp;q=&amp;esrc=s&amp;source=web&amp;cd=1&amp;cad=rja&amp;uact=8&amp;ved=0ahUKEwid07Lk8ZzQAhVCKWMKHd4LAsYQFggdMAA&amp;url=http%3A%2F%2Fslack.k8s.io%2F&amp;usg=AFQjCNGucJnpU4_1JMpJgj72g2K5GbprrA">Slack</a> channel has been an invaluable resource and direct line of communication to people much smarter than me throughout my entire learning process over the last 10 months. I’m happy to say that we at <a href="http://lonelyplanet.com/">Lonely Planet</a> have adopted Kubernetes in our production environment and it is now a key component of our software delivery pipeline.</p><p>Please check out my Kubecon talk to learn more about the project that might have gone unmentioned in this post.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FRyKzTb0Q0O4%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DRyKzTb0Q0O4&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FRyKzTb0Q0O4%2Fhqdefault.jpg&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/0ad90ee0fc2d16e61eb67a818581292d/href">https://medium.com/media/0ad90ee0fc2d16e61eb67a818581292d/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bScC_Om4ROpxExfNTwOarg.png" /></figure><h3>Just an idea…</h3><p>That’s all this really was 8 months ago. VR was just going mainstream with the release of the consumer grade Vive and Oculus. I was inspired to create this project by the previous “<em>infrastructure in a game</em>” prototypes of <a href="https://github.com/docker/dockercraft">Dockercraft</a> and <a href="https://gideonred.com/dockerdoom/">Docker DOOM</a>. Whilst the practicality of such hacks is open for debate, it was fun and refreshing to see people thinking about visualization of Docker in new and exciting ways.</p><p>I wanted to build upon these ideas and take them to a whole ‘nother level. The seed had been planted, I knew this was something I wanted to take on. I submitted my CFP (call for papers) to Kubecon in March. And waited. And waited. And waited. In September I finally got word that I was going to be speaking.</p><p>Now all that was left was to figure it all out…</p><h3>The current VR landscape</h3><p>I’m not going to talk about all the players here, but I do just want to highlight a few of the major choices a VR developer has to choose from at the moment.</p><p><strong>Unity</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/338/1*6QSSyweA2lTlCaUhWpAUyw.png" /></figure><p>Chances are if you own a mobile phone, you’ve played a game powered by the Unity game engine. Valve also built much of the (awesome) <a href="http://store.steampowered.com/app/450390/">The Lab</a> VR experience using the Unity game engine and have even open-sourced many of the components they added. I spent about a week exploring Unity before deciding that it wouldn’t fit well into the Kubernetes ecosystem. Building a event-based or restful framework into the engine seemed like a rather daunting task and requiring a user to download and install a binary seemed prohibitive to my end goal.</p><p><strong>Pros</strong>:</p><ul><li>Free to start</li><li>Stable</li><li>Awesome community</li><li>Great cross-platform editor</li><li>Drag-and-drop support for VR</li></ul><p><strong>Cons</strong>:</p><ul><li>You need to know C# to be effective with it</li><li>Users of your “product” need to download and install your application in order to use it.</li><li>Free version isn’t open-source</li></ul><p><strong>Unreal</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/288/1*SmpqtJCAnAhIOotlrWYY6A.png" /></figure><p>I really won’t do Unreal justice, it’s a fantastic and proven game engine. That being said, it’s incredibly deep and I was overwhelmed in figuring out where to even start. I never considered it a viable option for what I set out to accomplish.</p><p><strong>WebVR</strong></p><p>Now for the cool new-kid-on-the-block, <a href="https://webvr.info/">WebVR</a>. You may or may not have even known it was a thing that exists, but it’s here. And it’s <a href="https://mozvr.com/#showcase">gaining momentum <em>fast</em></a><em>. </em>Mozilla is in large part to thank for this, they have a <a href="https://mozvr.com/#team">team</a> dedicated to nothing but VR on the web, and they are doing a fantastic job. I recommend reading over the <a href="https://medium.com/immersion-for-the-win/why-webvr-matters-9f383fee04e5#.o1vb6zfz9">article on why WebVR matters</a>.</p><p>There is one WebVR framework that stands out from the rest (and the one I ultimately decided to build upon), <a href="https://aframe.io/">A-Frame</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/408/1*GiuGDCi7I-mGLQ4K0ntZHQ.gif" /><figcaption>A-Frame logo animation</figcaption></figure><p><a href="https://github.com/aframevr/aframe">A-Frame</a> is a WebVR framework self-described as the following:</p><blockquote>An open-source web framework for building virtual reality experiences. We can build VR web pages that we can walk inside with just HTML. Under the hood, it is a <a href="http://threejs.org/">three.js</a> framework that brings the <a href="https://aframe.io/docs/0.3.0/docs/core">entity-component-system</a> pattern to the DOM.</blockquote><p>Yes, you can build VR applications using nothing but the HTML and Javascript knowledge you have already. You can see the appeal here, both for the users and developers. Not having to learn a completely new language or be forced to download and install something just to view what other people have built is a pretty compelling reason to go with WebVR.</p><p>Here is a short example of how easy it is to render a VR scene using A-Frame:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodepen.io%2Fmozvr%2Fembed%2Fpreview%2FBjygdO%3Fheight%3D600%26amp%3Bslug-hash%3DBjygdO%26amp%3Bdefault-tabs%3Dhtml%2Cresult%26amp%3Bhost%3Dhttp%253A%252F%252Fcodepen.io%26amp%3Bembed-version%3D2&amp;url=https%3A%2F%2Fcodepen.io%2Fmozvr%2Fpen%2FBjygdO&amp;image=https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fi.cdpn.io%2F358505.BjygdO.small.a90dd023-f65a-4034-ab19-b86680d3e94e.png&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;schema=codepen" width="800" height="600" frameborder="0" scrolling="no"><a href="https://medium.com/media/4bc3a4b945dbd5425fd4154f0be3e367/href">https://medium.com/media/4bc3a4b945dbd5425fd4154f0be3e367/href</a></iframe><h3>Building blocks</h3><p>Now that I had settled on a framework for building the VR component of the application, I still had another big piece of the puzzle to solve. How do I tie it together with an actual Kubernetes back-end?</p><p>A Kubernetes cluster consists of a fairly wide range of different types of resources, including but not limited to:</p><ul><li><strong>Pods</strong> (with 1 or more containers)</li><li><strong>Deployments</strong></li><li><strong>Replication Controllers</strong></li><li><strong>Volumes</strong></li><li><strong>Secrets</strong></li><li><strong>Config Maps</strong></li><li><strong>Services</strong></li></ul><p>I knew it wouldn’t be feasible to attempt to build a representation of all of these. I chose only to represent individual Pods for the first iteration. Regardless of whether a Pod was part of a Deployment, a Replication Controller or something else, it would be visualized as a single physical object in VR.</p><p>These were my main remaining objectives for the first attempt:</p><p><strong>Provide a physical representation of a Pod in VR</strong></p><p>A Pod would need to be represented by an actual three-dimensional object in the scene as opposed to just an item in a list that you would get from running :</p><pre><strong>kubectl get pods</strong></pre><p>I settled on the built-in primitive &lt;a-box&gt; (a cube) that comes with A-Frame as it’s simple enough to use, I can render a lot of them and it wouldn’t require loading loads of custom object models. Here is an example:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodepen.io%2Fthenayr%2Fembed%2Fpreview%2FrWeBGg%3Fheight%3D600%26amp%3Bslug-hash%3DrWeBGg%26amp%3Bdefault-tabs%3Dhtml%2Cresult%26amp%3Bhost%3Dhttp%253A%252F%252Fcodepen.io%26amp%3Bembed-version%3D2&amp;url=https%3A%2F%2Fcodepen.io%2Fthenayr%2Fpen%2FrWeBGg&amp;image=https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fi.cdpn.io%2F915926.rWeBGg.small.fd7eaaa2-a3cd-4e46-82f5-4a85224eaf3b.png&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;schema=codepen" width="800" height="600" frameborder="0" scrolling="no"><a href="https://medium.com/media/cf539fb9cf5edcdc26bb7e5032adeb8b/href">https://medium.com/media/cf539fb9cf5edcdc26bb7e5032adeb8b/href</a></iframe><p><strong>Handle real-time Pod events from a Kubernetes cluster</strong></p><p>This meant that anytime a new Pod was created or deleted on the API end, that event should propagate to my VR application in near real-time. This was critical for my use case as the user would be connected to VR and requiring them to have to refresh a page in order to see changes would be a deal-breaker.</p><p>Kubernetes has a pretty awesome “watch” flag built right in. You’ve probably used it if you ran the following command:</p><pre><strong>kubectl get pods -w</strong></pre><p>I decided to use NodeJS to build the back-end API for a number of reasons, mainly:</p><ul><li>The front-end was already going to be javascript, might as well save time and do the same for the back-end.</li><li>There are many great Kubernetes API client libraries in the NPM package repository. I went with “<a href="https://www.npmjs.com/package/kubernetes-client">kubernetes-client</a>” by Godaddy as it has nice built in support to stream the watch API and act on different events.</li><li>The asynchronous nature of the language would be useful in having a single application that dealt with non-blocking streaming events as well as one-off requests for additional information.</li></ul><p>I give a deeper dive into the Kubernetes watch API in the section “<strong>Kubernetes watch API in-depth</strong>”.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FJWPO4q5CuqjO8%2Ftwitter%2Fiframe&amp;src_secure=1&amp;url=http%3A%2F%2Fgiphy.com%2Fgifs%2FJWPO4q5CuqjO8&amp;image=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2FJWPO4q5CuqjO8%2Fgiphy.gif&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="244" frameborder="0" scrolling="no"><a href="https://medium.com/media/2db5ffda7ffbcb1b3e54733664be2e1d/href">https://medium.com/media/2db5ffda7ffbcb1b3e54733664be2e1d/href</a></iframe><p><strong>Handle propagation of real-time events in the browser</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/470/1*6doFRNg_2eaOCvu334CqEQ.png" /></figure><p>There were a few requirements to consider on the browser side. I knew I was going to be rendering dynamic (and sometimes stateful) components in the DOM. For this reason, choosing <a href="https://facebook.github.io/react/">React</a> was a no-brainer. This is actually the first time I’ve used React and it turned out to be pretty painless for the most part.</p><p>Luckily for me, <a href="https://github.com/ngokevin">Kevin Ngo</a> (one of the uber-genius core members on the A-Frame team) already built a <a href="https://github.com/ngokevin/aframe-react">fantastic package</a> to take advantage of all of the power of React directly in A-Frame. This meant I could build <em>stateful</em> (or <em>stateless</em>) components in React that represent A-Frame primitives. A-Frame + A-Frame React allows me to tie directly into the render loop in A-Frame (key to building a performant 3D application).</p><p>In order to propagate these events from the back-end API to the browser I decided to utilize the web sockets powered framework <a href="http://socket.io/">Socket.io</a>. It’s very similar to another framework I worked with previously on a Docker hackathon project to <a href="https://github.com/mjbright/thephedds">visualize real-time Docker events</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*dBKMcaKHDCLkQRAaFGoZXA.png" /></figure><p>Socket.io utilizes web sockets to enable real-time event based communication between browser and server. This was a key component of my project given the real-time requirements for the VR aspect of it.</p><p>I should mention there was another strong competitor in the open-source web sockets space called <a href="https://deepstream.io/">Deepstream</a>. I mainly ended up using Socket.io based on the number of examples that utilized React in combination with Socket.io that I could reference.</p><p><strong>Allow the user to interact with a Pod in VR</strong></p><p>At minimum I wanted a user to be able to delete a Pod from inside of the VR application itself. Initially I wanted to allow for Pod creation as well, but given the timeline I decided to limit interactions to just allow for deletion. I also wanted each Pod to be able to display specific meta-data about itself. My initial goal was just to get the name overlayed on top of the Pod, but I eventually convinced myself to pull in more information and came up with a fairly decent mechanism to display that data.</p><p><strong>Maintain a steady 90 FPS performance</strong></p><p>Having played my fair share of Virtual Reality titles released for the Vive, I knew performance was a must. Anything less than 90 FPS in a virtual reality environment was begging for motion sickness. If you ever got your hands on one of the earlier Oculus Rift dev kits, you know what I’m talking about. The low update-rate and screen tearing were extremely apparent and significantly reduce the immersion factor. This turned out to be one of the more challenging aspects of the project. It was a constant trade-off between features and maintaining a steady 90FPS.</p><p><strong>Component overview</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LslT_lXXv-WcZZg7943lZQ.png" /><figcaption>Kubernetes VR component overview (powered by Cloudcraft)</figcaption></figure><h3>The Kubernetes watch API in-depth</h3><p>A key piece of this entire project was being able to act on real-time information from the Kubernetes API. I didn’t want to have to rely on a polling mechanism to query for changes from the cluster, but rather receive the changes that happen directly through a stream.</p><p>The Node.js backend utilizes a <a href="https://github.com/godaddy/kubernetes-client">Kubernetes client library</a> written by engineers at Godaddy. This particular library makes it easy to utilize the watch flag that you can pass to the Kubernetes API to keep a persistent connection open (via HTTP or websocket) and stream in changes to resources in real-time.</p><p>Here is an example of how this code works:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/101fbce9d0622cf793d45f5aa661ccf0/href">https://medium.com/media/101fbce9d0622cf793d45f5aa661ccf0/href</a></iframe><p>I did run into a few caveats in dealing with the watch API. Unbeknownst to me at the time, the Kuberenetes API will actually assign a timeout to your connection regardless of what you set on the client side. I made the assumption that the watch request would persist until I killed it on the client side. You can read a bit more about how to deal with that bit here: <a href="http://stackoverflow.com/questions/33480560/kubernetes-api-server-drops-watch-connections">http://stackoverflow.com/questions/33480560/kubernetes-api-server-drops-watch-connections</a></p><h3>Determining when a new pod was created AND ready</h3><p>Another “gotcha” to mention with the way the <em>watch</em> responses come through deals with the events <strong>ADDED</strong> and <strong>MODIFIED</strong>. When I was debugging an earlier version of the project, I noticed that pods that come through on the <strong>ADDED</strong> event were missing a lot of the metadata that I needed to pull in (IP address, labels, etc). It turns out that <strong>ADDED</strong> is the first event that fires for a new pod, even before that pod actually enters any sort of <strong><em>ready</em></strong> state.</p><p>Even more troublesome, creating a single new pod would fire off a series of events like so:</p><ul><li><strong>ADDED</strong></li><li><strong>MODIFIED</strong></li><li><strong>MODIFIED</strong></li><li><strong>MODIFIED</strong></li><li><strong>MODIFIED</strong></li></ul><p>Each phase that the pod went through after first being added would send another event to the stream. Given that my goal was simply to take a newly created pod and it’s metadata and insert it into my A-Frame scene, this made it rather difficult to distinguish when a new pod was actually created and ready, especially when multiple pod creations and deletions were happening simultaneously. I eventually found the right combination of events to determine when that state occurs:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/059c318a3dbba9e394c4867229003fce/href">https://medium.com/media/059c318a3dbba9e394c4867229003fce/href</a></iframe><p>That is to say, I couldn’t use the <strong>ADDED</strong> event in the stream to generate new objects in my scene, instead I had to rely on a combination of the <strong>MODIFIED</strong> event and a series of metadata objects that show up in that event. It would be nice to have a <strong>READY</strong> event added to the API that would in effect do the same thing.</p><h3>Placing Pods into a A-frame VR scene</h3><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2F0Fn_MBnVHzU%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D0Fn_MBnVHzU&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2F0Fn_MBnVHzU%2Fhqdefault.jpg&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/a8f907bd2ce172e90a96e2e03d697057/href">https://medium.com/media/a8f907bd2ce172e90a96e2e03d697057/href</a></iframe><p>Now that I had the event stream properly detecting pods upon creation and deletion, I had to come up with a way to get them to render directly into my VR scene in real-time.</p><p>This is where React really shines, I was able to build a Pod component which I could then have dynamically added or removed from the scene whenever the appropriate event was triggered. The following is a simplified gist of what that component looks like (I stripped out some of the dynamic texturing and extraneous functionality)</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cdcdee4d67f102b4e4d779a925c3dec4/href">https://medium.com/media/cdcdee4d67f102b4e4d779a925c3dec4/href</a></iframe><p>I then built a parent component to handle the actual spawning of the child Pods which would handle the positioning, retrieval of metadata via web sockets and overall lifecycle of the child pod.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/436eedaa5018425888076cf0d0769ec8/href">https://medium.com/media/436eedaa5018425888076cf0d0769ec8/href</a></iframe><p>There is quite a lot of code here that handles communication via websockets to and from the backend Node.js API. Important to note is the initial provisioning that happens via the <strong>loadPodsFromServer </strong>function. This emits a websocket event to the Node application which in turn responds with a JSON blob including my existing pods.</p><p>I wanted the pods to spawn in random positions in the scene and fall out of the sky. The function <strong>randomPosition </strong>handles that by setting the X,Y,Z coordinates each time a new pod component is going to be created.</p><p>Later on in the development cycle I decided I wanted to texturize the boxes depending on the type of image the pod was actually running. To implement this I added a simple labeling system to my (example) Kubernetes manifest files.</p><pre>spec:<br>  replicas: x<br>  revisionHistoryLimit: x<br>  template:<br>    metadata:<br>      labels:<br>        type: nginx</pre><p>When the Node API emits an event over web sockets, it includes this metadata label <strong>type</strong> and uses it to map back to a texture image in the front-end application:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3badebb774ee7d5d36b2e111133de5ce/href">https://medium.com/media/3badebb774ee7d5d36b2e111133de5ce/href</a></iframe><p>The Node API side of the code checks to see if a pod has this label assigned, otherwise gives it a default pod texture (blue with the Kubernetes logo):</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1d7d990e8b22a2022d1221d6b30963e7/href">https://medium.com/media/1d7d990e8b22a2022d1221d6b30963e7/href</a></iframe><p>Inside of a separate React component I define my A-frame assets using the <a href="https://aframe.io/docs/0.3.0/core/asset-management-system.html">asset management system</a> :</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ae693d5f6b2284d72179af7aa6566b66/href">https://medium.com/media/ae693d5f6b2284d72179af7aa6566b66/href</a></iframe><p>This entire system is very rudimentary and rigid for the most part (it has no notion of textures for types that don’t exist), but it got the job done for the limited subset of pods I was dealing with for my demonstration.</p><p>Here is the (browser and keyboard) result of what these texture mappings look like:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FgINrdO2EtwU%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DgINrdO2EtwU&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FgINrdO2EtwU%2Fhqdefault.jpg&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/4de7692a3c65f3dea9de8c2d25cad5da/href">https://medium.com/media/4de7692a3c65f3dea9de8c2d25cad5da/href</a></iframe><h3>Deleting Pods from inside of VR</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*j_QzuI1Y4TvSGuRRvKJR0Q.gif" /><figcaption>Deleting a pod from inside VR</figcaption></figure><p>I wanted the interactions with the cluster to be bi-directional, not only should newly added and deleted pods propagate to the front-end, but pods that I delete from within a scene should also propagate to the Kubernetes back-end (adding pods from inside VR was put-off for later on). I had come up with a few ideas on how pod creation should work, but I decided to table it for a later iteration of the project.</p><p>In order to delete pods, I came up with the following scenario: A pod will always spawn within the bounds of the platform that the scene is based around, if the user takes a pod to the edge of the platform and drops it over (or throws it over from a distance), the pod will fall for a seemingly infinite distance and emit a delete message back to the Node API which will in turn run the equivalent of kubectl delete against that specific pod. This turned out to be pretty fun and easy to implement. I even added this <a href="https://github.com/bryik/aframe-vive-cursor-component">vive-cursor component</a> to the one of the controllers to allow you to point and click on a pod and send it flying into the abyss (easier and arguably more fun than having to carry it or throw it).</p><p>For the functional implementation of this, I utilized the A-frame component system to script out a polling check on the value of <strong>Y </strong>(current height in 3D space) to see if it was far below the scene in order to have it emit the delete event.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f6d199d325aa0584eeb0d2e0f711317b/href">https://medium.com/media/f6d199d325aa0584eeb0d2e0f711317b/href</a></iframe><p>A-frame components expose a gateway into the lifecycle of an entity to add additional functionality. You can run functions based on several different states of the entity. In the example above, when a pod is initialized I trigger an interval function that runs every 5 seconds and checks if the pod has fallen 50 meters below the scene, emitting an event if that becomes true. The parent component of my pods binds this event to a function which in turn emits (you guessed it) a web socket event back to the Node API with the specific pod ID as the payload.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6dc7214e52374c9eb6eed69e2bb9b78d/href">https://medium.com/media/6dc7214e52374c9eb6eed69e2bb9b78d/href</a></iframe><p>And the Node handler for this event:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b0cb6232d8312369b409448d1e08a0b9/href">https://medium.com/media/b0cb6232d8312369b409448d1e08a0b9/href</a></iframe><h3>Pod metadata UI</h3><p>Displaying textual information is notoriously challenging in a VR interface. Luckily there are already A-frame components which allowed me to render <a href="https://github.com/ngokevin/aframe-text-component">geometric text in my scene</a>. I utilized this component to build an interface which can be toggled on or off by clicking the Vive grip button while hovering the controller laser over a specific pod.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FCQujZK4Yx10%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DCQujZK4Yx10&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FCQujZK4Yx10%2Fhqdefault.jpg&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/5a91e5a1426630d0a2671fdb5f573b76/href">https://medium.com/media/5a91e5a1426630d0a2671fdb5f573b76/href</a></iframe><p>Unfortunately I did end up running into a number of performance issues by having the text UI components rendered (albeit <em>hidden</em>) when the pods get initialized. Instead I ended up having a “clicked” state on my pod component that would only render the text UI when activated. This helped significantly with the initial performance hits. I’m still not entirely happy with the state of the UI, but it was sufficient for demonstration purposes. Note that the pod ID that displays above the individual pods is actually using a separate sprite component that I hacked together (I REALLY dislike how it looks, but it functions and performance isn’t a problem like it was with the geometric text).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/585/1*Pg-fWqUlwMonplYcu-1trQ.png" /><figcaption>The gross sprite labels that I don’t like at all</figcaption></figure><h3>Cluster metadata UI</h3><p>In addition to individual pod metadata, I also wanted a way to display more generic information about the cluster as a whole. I didn’t spend a whole lot of time in building this particular component, but I was able to display the total count of pods and deployments that exist in the cluster.</p><p>There is a placeholder button where I was going to add pod creation functionality, but haven’t gotten around to it as of yet.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*jaZWju1ns6V3TD4-AHFV5A.gif" /><figcaption>Kubernetes UI in VR</figcaption></figure><p>The cluster metadata UI will pop-up when the user clicks the menu button on either vive controller. Here is the code for the cluster UI:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3ea654269e0da5c2df3c256ed34f59a8/href">https://medium.com/media/3ea654269e0da5c2df3c256ed34f59a8/href</a></iframe><h3>Vive controller functionality in A-frame</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*ayTFKefqRzRCv40szGr6-A.gif" /><figcaption>The vive controller functionality in action</figcaption></figure><p>There were several pieces of functionality that were critical in order to support the full room-scale experience with the Vive that I wanted. They are the following in no particular order:</p><ul><li>Controller teleportation</li><li>Controller physics interaction (pick up / touch objects)</li><li>Controller cursor (laser pointer) interaction</li></ul><p>Luckily for me nearly all of these components were already created by the community (some <em>JUST</em> in time for me to take advantage of them).</p><p>Here are the community projects I relied on for the core functionality of the Vive controller:</p><p><strong>Teleportation by Fernando Serrano</strong>: <a href="https://github.com/fernandojsg/aframe-teleport-controls">https://github.com/fernandojsg/aframe-teleport-controls</a></p><p><strong>Physics interaction (grab and sphere-collider by Don Mccurdy)</strong>: <a href="https://github.com/donmccurdy/aframe-extras/tree/master/src/misc">https://github.com/donmccurdy/aframe-extras/tree/master/src/misc</a></p><p><strong>Vive cursor by Ben Pyrik</strong>: <a href="https://github.com/bryik/aframe-vive-cursor-component">https://github.com/bryik/aframe-vive-cursor-component</a></p><p>Here is the code for my controller entities:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1b67cd5bc7e485cd797622766036d281/href">https://medium.com/media/1b67cd5bc7e485cd797622766036d281/href</a></iframe><p>It’s worth mentioning that the Vive controllers ONLY work in the experimental builds of Chrome with Web VR support at the moment. They will <strong>not</strong> function in Firefox nightly builds.</p><p>There were also a number of hacky workarounds I had to implement in order for the controller interactions to work with newly appended objects. Due to the way some A-frame components are implemented, you often have to remove and reinitialize them when new objects are added. Here is an example of how I did this every time a new pod was added to the scene:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a9b5859662b3ce53c5eb9e1c282e26cb/href">https://medium.com/media/a9b5859662b3ce53c5eb9e1c282e26cb/href</a></iframe><p>Using the componentDidMount() lifecycle hook via React, I can remove and add the sphere collider to my controllers (in order for them to register new objects), as well as adding the dynamic-body component to the newly created pod (so it actually gets physics applied to it).</p><h3>Don’t try this at home</h3><p>Or rather, only try this at home…All of the aforementioned code is available on my <a href="https://github.com/thenayr">Github</a>. I <strong>DO NOT RECOMMEND</strong> you try this out against any Kubernetes cluster in the wild. In its current state, you should ONLY try this out against a local or experimental (and very disposable) cluster.</p><h3>Known issues</h3><p>As mentioned before, performance was a constant struggle between new features and keeping a smooth frame rate. I haven’t tested a scene with more than 50 pods currently, though I would imagine it would start to stutter with larger amounts. I’m no expert in Javscript and I’m sure there are plenty of performance optimizations to be made in the code that I wrote.</p><p>The Node.js backend will timeout after a (mostly unknown) amount of time, at which point you will need to restart it..this can be easily coded in to prevent a restart from being required.</p><p>I’m definitely not happy with the state of the code base. If it looks like it was hacked together by someone sleep deprived and completely new to most of the technology in play, there is a very good chance that is the case.</p><h3>Wishlist</h3><p>There are a ton more features I would love to add to this project. Some additional ideas I had:</p><ul><li>Streaming pod logs into the scene.</li><li>Create new pods from within VR</li><li>View pod metrics (CPU/memory) from within VR</li><li>Organize pods based on deployments / rc’s</li></ul><h3>Contact</h3><p>If you’d like to discuss this project or schedule a demo session, please feel free to contact me via <a href="http://twitter.com/iamnayr">twitter</a> or <a href="/service/mailto:iamnayr@gmail.com">email</a>.</p><p>I’m open to collaborating and/or working on similar projects like this (and extending this project further).</p><p>Thanks for reading!</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2F6HaMHE6mlIQ%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D6HaMHE6mlIQ&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2F6HaMHE6mlIQ%2Fhqdefault.jpg&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/c81d39532e179706bc4da9d79431bae4/href">https://medium.com/media/c81d39532e179706bc4da9d79431bae4/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b681464f0c98" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>