{
    "componentChunkName": "component---src-templates-blog-post-tsx",
    "path": "/blog/2021-01-29-kubernetes-wet-your-toes/",
    "result": {"data":{"blogPost":{"title":"Kubernetes: Dip your toes in this","slug":"/blog/2021-01-29-kubernetes-wet-your-toes/","authorNodes":[{"name":"Min Kim","slug":"/people/min-kim/"}],"markdown":{"html":"<p>Kubernetes is perhaps one of the most exciting developments in the DevOps world in the last 15 years. It is an open source implementation of the Borg system that was Google’s “secret sauce” – the thing that allowed them to deploy and manage thousands of services in their clusters.</p>\n<p>With modern cloud PaaS (platform as a service) like Google Cloud and AWS, most frontend and many backend developers can deploy services without learning about the architecture and technologies that power these platforms. In the past, not knowing about these platforms could be easily forgiven because the learning curve was too steep.</p>\n<p>Kubernetes changes all that. It makes understanding these platforms approachable and manageable, allowing frontend developers to learn all about them fairly quickly. The architecture of Kubernetes and the approach that the community is taking towards building Kubernetes continuously lowers the barrier for people who otherwise wouldn’t have an opportunity to learn about Cloud Native Deployment.</p>\n<p>At its core, Kubernetes is based on a concept that anyone familiar with React would recognize. It’s a declarative system for service management. Similar to how React allows you to declare what components you want to render with it handling the creation of DOM elements, Kubernetes allows you to declare what services you want to deploy and it takes care of deploying them.</p>\n<p>Grasping this comparison can take you surprisingly far into understanding Kubernetes. For example, you can use the same components’ syntax to describe their composition for both web and mobile platforms. React DOM and React Native are adapters that control how your components are rendered in these different environments. Similarly, you can use the same services and same syntax to deploy services to Google Cloud, AWS, Azure or Digital Ocean via different <a href=\"https://kubernetes.io/docs/concepts/cluster-administration/cloud-providers/\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">cloud providers</a>.</p>\n<p>React takes care of the difficult work of applying declarative state changes to DOM. Kubernetes does the hard work of applying declarative state changes to your infrastructure and services. The important part to remember is that with Kubernetes, you tell it what to do rather than how to do it.</p>\n<p>Under the hood, Kubernetes consists of a <a href=\"https://kubernetes.io/docs/concepts/overview/components/%23control-plane-components\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">control panel</a> that manages worker <a href=\"https://kubernetes.io/docs/concepts/overview/components/%23node-components\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">nodes</a>. The control panel’s API is RESTful, but most of the time you’re not going to be interacting with the API directly. Instead you’ll use the CLI, which talks to the RESTful API. The control panel’s specs are agreed on by the Kubernetes community, but the API definition makes it possible for different implementations of Kubernetes to exist.</p>\n<p>In this tutorial, we’ll show you how to set up MicroK8S, which is Ubuntu’s implementation of Kubernetes. It’s small enough to run on your machine and will allow you to play around with Kubernetes without having to pay a cloud provider to host it for you.</p>\n<h2 id=\"installation-and-start\" style=\"position:relative;\"><a href=\"#installation-and-start\" aria-label=\"installation and start permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Installation and Start</h2>\n<p>Let’s go ahead and install MicroK8S for macOS:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">$ brew install ubuntu/microk8s/microk8s</code></pre></div>\n<p><em>For installation instructions for Windows or Linux, go to the <a href=\"https://microk8s.io/\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">MicroK8S website</a>.</em></p>\n<p>Once it has finished installing, run the following commands:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">$ microk8s install\n$ microk8s start</code></pre></div>\n<p><code class=\"language-text\">microk8s install</code> will start the VM and <code class=\"language-text\">microk8s start</code> will create a Kubernetes cluster.</p>\n<p>Once you start up a cluster, you should be able to run the <code class=\"language-text\">microk8s status</code> command to display all of the available services. Entering <code class=\"language-text\">microk8s stop</code> into your terminal will shut off both the VM and the cluster.</p>\n<h2 id=\"dashboard\" style=\"position:relative;\"><a href=\"#dashboard\" aria-label=\"dashboard permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Dashboard</h2>\n<p>Although all of MicroK8S’ functionality can be accessed via your terminal, you can also start up the dashboard service and see everything through the web UI.</p>\n<p>Run <code class=\"language-text\">microk8s dashboard-proxy</code> and you should see the following output:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">$ microk8s dashboard-proxyChecking if Dashboard is running.\nWaiting for Dashboard to come up.\nDashboard will be available at https://xxx.xxx.xx.x:xxxxx\nUse the following token to login:\nabcdefgh1234567\nForwarding from 0.0.0.0:xxxx -> xxxx</code></pre></div>\n<p>Go to your browser and enter in the address provided (including the https://) and copy/paste the token to gain access to your dashboard, which will look something like this:</p>\n<p><figure class=\"figure\"><img src=\"/img/2021-01-kubernetes/dashboard.png\"><figcaption class=\"figure-caption\">Microk8s Dashboard screenshot</figcaption></figure></p>\n<p>Now when you go back to your terminal, entering the <code class=\"language-text\">microk8s status</code> command will show that the dashboard has been enabled. If you wish you can run <code class=\"language-text\">microk8s disable dashboard</code> to disable it again.</p>\n<h2 id=\"kubectl\" style=\"position:relative;\"><a href=\"#kubectl\" aria-label=\"kubectl permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Kubectl</h2>\n<p>Coo-beck-tul? Cube-control? However it’s pronounced, <code class=\"language-text\">kubectl</code> is a MicroK8S command to help you control Kubernetes clusters; like the ones we started earlier with <code class=\"language-text\">microk8s start</code>. Let’s use <code class=\"language-text\">kubectl</code> to deploy a service. For this tutorial we’ll be using a lightweight microservice: <a href=\"https://github.com/stefanprodan/podinfo\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">https://github.com/stefanprodan/podinfo</a>. The service itself does not do much. It is just to help us practice starting and stopping Kubernetes services.</p>\n<p>Use the following command to deploy Podinfo:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">$ microk8s kubectl apply -k github.com/stefanprodan/podinfo//kustomize</code></pre></div>\n<p>Now you can run <code class=\"language-text\">microk8s kubectl get deployments</code> to confirm that <code class=\"language-text\">podinfo</code> has been deployed.</p>\n<h2 id=\"k9s\" style=\"position:relative;\"><a href=\"#k9s\" aria-label=\"k9s permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>k9s</h2>\n<p>We haven’t port-forwarded our deployment so we can’t access it with a browser just yet. There’s a way to port-forward with <code class=\"language-text\">microk8s</code> but we’ll show you an easier way using <code class=\"language-text\">k9s</code>.</p>\n<p>You’ll need to first install it:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">$ brew install k9s</code></pre></div>\n<p>After it finishes installing, you can start it up using the command <code class=\"language-text\">k9s</code>. Your terminal should look something similar to this:</p>\n<p><figure class=\"figure\"><img src=\"/img/2021-01-kubernetes/k9s-terminal.png\"><figcaption class=\"figure-caption\">k9s running on terminal screenshot</figcaption></figure></p>\n<blockquote>\n<p>You can exit out of <code class=\"language-text\">k9s</code> with either <code class=\"language-text\">ctrl + c</code> or you can press <code class=\"language-text\">:</code> to initiate a command and enter <code class=\"language-text\">quit</code>.</p>\n</blockquote>\n<p>In order for <code class=\"language-text\">k9s</code> to work properly, you’ll need to add your Kubernetes configuration to your local root directory:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">$ mkdir ~/.kube &amp;&amp; microk8s config > ~/.kube/config</code></pre></div>\n<p>And now when you start up <code class=\"language-text\">k9s</code> again, you’ll notice the configurations have taken effect.</p>\n<p>If you’ve been following along with all of the previous steps, your <code class=\"language-text\">k9s</code> screen should show the pods that we deployed earlier:</p>\n<p><figure class=\"figure\"><img src=\"/img/2021-01-kubernetes/k9s-listed-pods.png\"><figcaption class=\"figure-caption\">k9s with pods listed screenshot</figcaption></figure></p>\n<p>What we’re seeing here are the pods from the service we deployed. We’ll be returning to this page very shortly, but for practice if you want to navigate to the list of deployments, press <code class=\"language-text\">:</code> and type in <code class=\"language-text\">deployments</code>.</p>\n<p><figure class=\"figure\"><img src=\"/img/2021-01-kubernetes/k9s-deployments.png\"><figcaption class=\"figure-caption\">k9s with deployments listed screenshot</figcaption></figure></p>\n<p>To port-forward this deployment, press <code class=\"language-text\">enter</code> on <code class=\"language-text\">podinfo</code> to display its pods again.</p>\n<p>Navigate to any one of the pods and press <code class=\"language-text\">shift + f</code> to port-forward the service. Then press <code class=\"language-text\">f</code> to see the hosted URL. Copy and paste this URL to your browser and you should be able to see the service.</p>\n<p><figure class=\"figure\"><img src=\"/img/2021-01-kubernetes/podinfo.png\"><figcaption class=\"figure-caption\">Podinfo screenshot</figcaption></figure></p>\n<h2 id=\"conclusion\" style=\"position:relative;\"><a href=\"#conclusion\" aria-label=\"conclusion permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Conclusion</h2>\n<p>Kubernetes is on the rise and having it in your toolkit can get you a long way. Now that you’ve set up a MicroK8S in your machine, you can play around with the basics to start getting familiar with Kubernetes.</p>","frontmatter":{"date":"January 29, 2021","description":"Kubernetes is on the rise and having it in your toolkit can get you a long way. In this article, Min shows us how to set up a MicoK8s in your local machine.","tags":["kubernetes","CI/CD"],"img":{"childImageSharp":{"fixed":{"src":"/static/9f8c35191a7b24c8f12ff00d5b656104/8088b/hero.png"}}}}}}},"pageContext":{"id":"8911cb5a-504a-5b72-b577-f9d4fabf4239"}},
    "staticQueryHashes": ["1241260443"]}