{"id":1645,"date":"2019-04-19T03:23:20","date_gmt":"2019-04-19T03:23:20","guid":{"rendered":"http:\/\/kusuaks7\/?p=1250"},"modified":"2023-08-24T12:07:51","modified_gmt":"2023-08-24T12:07:51","slug":"key-kubernetes-concepts","status":"publish","type":"post","link":"https:\/\/www.experfy.com\/blog\/bigdata-cloud\/key-kubernetes-concepts\/","title":{"rendered":"Key Kubernetes Concepts"},"content":{"rendered":"<p id=\"21ac\" name=\"21ac\">Cloud computing, containerization, and container orchestration are the most important trends in DevOps. Whether you&rsquo;re a data scientist, software developer, or product manager, it&rsquo;s good to know Docker and Kubernetes basics. Both technologies help you collaborate with others, deploy your projects, and increase your value to employers.<\/p>\n<p id=\"2c74\" name=\"2c74\">In this article, we&rsquo;ll cover essential Kubernetes concepts. There are a lot of Kubernetes terms, which can make it intimidating. I&rsquo;ll help you make a mental model to speed your understanding of the technology.<\/p>\n<figure data-scroll=\"native\" id=\"3ae5\" name=\"3ae5\">\n<p><canvas height=\"50\" width=\"75\"><\/canvas><img decoding=\"async\" data-src=\"https:\/\/cdn-images-1.medium.com\/max\/2560\/1*Mg6Ii8ibJPomegYj1tn8Ag.jpeg\" src=\"https:\/\/cdn-images-1.medium.com\/max\/2560\/1*Mg6Ii8ibJPomegYj1tn8Ag.jpeg\" style=\"width: 700px; height: 471px;\" \/><\/p>\n<\/figure>\n<p name=\"f41f\" style=\"text-align: center;\">Orchestrating the movement of shipping containers<\/p>\n<p id=\"f41f\" name=\"f41f\">Kubernetes makes a lot more sense if you first know Docker concepts. Check out my Docker guides to learn the fundamentals &#8211; <a href=\"https:\/\/www.experfy.com\/blog\/learn-enough-docker-to-be-useful-part1-the-conceptual-landscape\">Learn Enough Docker to be Useful: Part 1- The Conceptual Landscape<\/a>.<\/p>\n<p>Then meet back here to learn about orchestrating those Docker containers.<\/p>\n<h3 id=\"bdda\" name=\"bdda\">Kuberwhat?<\/h3>\n<p id=\"acfa\" name=\"acfa\">Kubernetes is an open-source platform for managing containerized apps in production. Kubernetes is referred to as K8s for short. I&rsquo;ll mostly use the term&nbsp;<em>K8s<\/em>&nbsp;going forward, because who doesn&rsquo;t love efficiency?&nbsp;<\/p>\n<p name=\"acfa\" style=\"text-align: center;\"><img decoding=\"async\" data-src=\"https:\/\/cdn-images-1.medium.com\/max\/1200\/1*nJACeVQHoVi7QYcc6Eqk3w.png\" src=\"https:\/\/cdn-images-1.medium.com\/max\/1200\/1*nJACeVQHoVi7QYcc6Eqk3w.png\" \/><\/p>\n<p name=\"acfa\">K8s is hot. As you can see in the chart below, Google searches for it have grown rapidly in the past five years.<\/p>\n<p name=\"acfa\">&nbsp;<\/p>\n<p name=\"acfa\" style=\"text-align: center;\"><canvas height=\"55\" width=\"75\"><\/canvas><img decoding=\"async\" data-src=\"https:\/\/cdn-images-1.medium.com\/max\/800\/1*K2qc67GtA52dZrbpQbORmw.png\" src=\"https:\/\/cdn-images-1.medium.com\/max\/800\/1*K2qc67GtA52dZrbpQbORmw.png\" style=\"width: 700px; height: 183px;\" \/><\/p>\n<p name=\"acfa\" style=\"text-align: center;\">Worldwide search interest for&nbsp;<em>kubernetes<\/em><\/p>\n<p id=\"2349\" name=\"2349\">Why is K8s so in demand? Kubernetes makes it easier for you to automatically scale your app, reduce downtime, and increase security. No more writing scripts to check, restart, and change the number of Docker containers. Instead, you tell K8s your desired number of containers and it does the work for you. K8s can even automatically scale your containers based on resources used.<\/p>\n<p id=\"9642\" name=\"9642\">Kubernetes is all about abstracting away complexity. It provides clear points to interface with your app&rsquo;s development environment.<\/p>\n<p id=\"6e2c\" name=\"6e2c\">K8s doesn&rsquo;t make a lot of sense for a basic static website that gets a handful of visitors per day. Its use case is for larger apps that might have to scale up and down quickly.<\/p>\n<p id=\"1c26\" name=\"1c26\">For large apps, you can use K8s to get the most out of your compute and storage resources. When paired with cloud providers, K8s can save you money. No matter where you run K8s, it should help you save time and reduce DevOps headaches.<\/p>\n<p id=\"3874\" name=\"3874\">Docker has a competing product named&nbsp;<a data-href=\"https:\/\/docs.docker.com\/engine\/swarm\/\" href=\"https:\/\/docs.docker.com\/engine\/swarm\/\" rel=\"noopener noreferrer\" target=\"_blank\">Docker Swarm<\/a>&nbsp;that orchestrates containers. However, it doesn&rsquo;t have the features and market share that K8s does. While you might think that Docker wouldn&rsquo;t play nicely with K8s when it has its own offering, the two play extremely well together. I strongly suggest you use K8s to orchestrate your containers.<\/p>\n<figure data-scroll=\"native\" id=\"0c25\" name=\"0c25\">\n<p><canvas height=\"47\" width=\"75\"><\/canvas><img decoding=\"async\" data-src=\"https:\/\/cdn-images-1.medium.com\/max\/1200\/1*skAU3Q_nyw1RR9Xh6X8Zpg.jpeg\" src=\"https:\/\/cdn-images-1.medium.com\/max\/1200\/1*skAU3Q_nyw1RR9Xh6X8Zpg.jpeg\" \/><\/p>\n<\/figure>\n<p name=\"24a1\" style=\"text-align: center;\">Playing nicely<\/p>\n<p id=\"24a1\" name=\"24a1\">Keeping the many K8s abstractions straight can be tricky. I&rsquo;ll explain how the key parts fit together so you can wrap your head around this powerful platform. Let&rsquo;s explore key K8s concepts and how they relate to each other.<\/p>\n<p id=\"a5fa\" name=\"a5fa\">First we&rsquo;ll look at six layers of abstraction and the parts that make them up. Then we&rsquo;ll look at seven other key K8s API objects.<\/p>\n<h3 id=\"d2fe\" name=\"d2fe\">The Six Layers of&nbsp;K8s<\/h3>\n<p id=\"6d47\" name=\"6d47\">Let&rsquo;s assume you have an app that is running continuously and doesn&rsquo;t need to store state.<\/p>\n<p name=\"6d47\" style=\"text-align: center;\"><img decoding=\"async\" data-src=\"https:\/\/cdn-images-1.medium.com\/max\/800\/1*YggVOtB-mep_HP1C4rhpGg.png\" src=\"https:\/\/cdn-images-1.medium.com\/max\/800\/1*YggVOtB-mep_HP1C4rhpGg.png\" \/><\/p>\n<p name=\"6d47\" style=\"text-align: center;\"><span style=\"text-align: center;\">Kubernetes abstractions for a Deployment. &copy; Jeff Hale&nbsp;2019<\/span><\/p>\n<p id=\"e998\" name=\"e998\">Here are the six layers of K8s concepts, starting with the highest-level abstraction.<\/p>\n<ol>\n<li id=\"6cf7\" name=\"6cf7\">Deployment<\/li>\n<li id=\"c988\" name=\"c988\">ReplicaSet<\/li>\n<li id=\"9b94\" name=\"9b94\">Pod<\/li>\n<li id=\"50b9\" name=\"50b9\">Node Cluster<\/li>\n<li id=\"5792\" name=\"5792\">Node Processes<\/li>\n<li id=\"5785\" name=\"5785\">Docker Container<\/li>\n<\/ol>\n<p id=\"ba7d\" name=\"ba7d\">Deployments<em>&nbsp;<\/em>create and manage ReplicaSets, which create and manage Pods, which run on Nodes, which have a container runtime, which run the app code you put in your Docker image.&nbsp;Sounds like the Irish folk song &ldquo;<a data-href=\"https:\/\/en.wikipedia.org\/wiki\/The_Rattlin%27_Bog\" href=\"https:\/\/en.wikipedia.org\/wiki\/The_Rattlin%27_Bog\" rel=\"noopener noreferrer\" target=\"_blank\">The Rattlin&rsquo; Bog<\/a>&rdquo;.&nbsp;<\/p>\n<p id=\"9ba0\" name=\"9ba0\">Here&rsquo;s a diagram with the Worker Node processes broken out. Let&rsquo;s dig in a bit.<\/p>\n<figure id=\"a914\" name=\"a914\">\n<p><canvas height=\"62\" width=\"75\"><\/canvas><img decoding=\"async\" data-src=\"https:\/\/cdn-images-1.medium.com\/max\/800\/1*Y4TTxjBCff9GVRfTZy8GGw.png\" src=\"https:\/\/cdn-images-1.medium.com\/max\/800\/1*Y4TTxjBCff9GVRfTZy8GGw.png\" style=\"width: 700px; height: 586px;\" \/><\/p>\n<\/figure>\n<p name=\"6a0d\" style=\"text-align: center;\">Detailed Kubernetes abstraction Deployment levels. &copy; Jeff Hale&nbsp;2019<\/p>\n<p id=\"6a0d\" name=\"6a0d\">The levels shaded blue are higher-level K8s abstractions. The green levels represent Nodes and Node subprocess that you should be aware of, but may not touch.<\/p>\n<p id=\"5585\" name=\"5585\">Note that your K8s instances will often have multiple Pods that can run on a single Node.<\/p>\n<p id=\"bc2a\" name=\"bc2a\">The Docker container contains your application code.<\/p>\n<p id=\"7e91\" name=\"7e91\">***Grammar interlude***<\/p>\n<p id=\"4b31\" name=\"4b31\">According to K8s own&nbsp;<a data-href=\"https:\/\/kubernetes.io\/docs\/contribute\/style\/style-guide\/\" href=\"https:\/\/kubernetes.io\/docs\/contribute\/style\/style-guide\/\" rel=\"noopener noreferrer\" target=\"_blank\">style guide<\/a>, capitalization of API objects such as <i>Pods should<\/i>&nbsp;follow the &ldquo;same uppercase and lowercase letters that are used in the actual object name.&rdquo; However, this guideline is often not followed in the docs\u200a&mdash;\u200aAPI objects are capitalized or lowercased seemingly randomly.<\/p>\n<p id=\"20e1\" name=\"20e1\">I&rsquo;m going to follow the style guide&rsquo;s stated policy in my K8s articles and error on the side of capitalization.<\/p>\n<p id=\"dc11\" name=\"dc11\">***Grammar interlude over. ***<\/p>\n<p id=\"f748\" name=\"f748\">Let&rsquo;s look at the six levels individually, starting with the highest level of abstraction.<\/p>\n<h3 id=\"8657\" name=\"8657\">Deployment<\/h3>\n<p id=\"b467\" name=\"b467\">If you want to make a stateless app that will run continuously, such as an HTTP server, you want a Deployment. Deployments allow you to update a running app without downtime. Deployments also specify a strategy to restart Pods when they die.<\/p>\n<p id=\"b8ea\" name=\"b8ea\">You can create a Deployment from the command line or a configuration file. I&rsquo;ll show you both methods in future articles, so follow&nbsp;<a href=\"https:\/\/medium.com\/@jeffhale\" target=\"_blank\" rel=\"noopener noreferrer\" class=\"broken_link\">me<\/a>&nbsp;to make sure you don&rsquo;t miss them.&nbsp;<\/p>\n<h3 id=\"0b47\" name=\"0b47\">ReplicaSet<\/h3>\n<p id=\"a366\" name=\"a366\">The Deployment creates a ReplicaSet that will ensure your app has the desired number of Pods. ReplicaSets will create and scale Pods based on the triggers you specify in your Deployment.<\/p>\n<p id=\"418d\" name=\"418d\"><em>Replication Controllers<\/em>&nbsp;perform the same function as ReplicaSets, but Replication Controllers are old school. ReplicaSets are the smart way to manage replicated Pods in 2019.<\/p>\n<h3 id=\"e218\" name=\"e218\">Pod<\/h3>\n<p id=\"8142\" name=\"8142\">The&nbsp;<a data-href=\"https:\/\/kubernetes.io\/docs\/concepts\/workloads\/pods\/pod-overview\/#pods-and-controllers\" href=\"https:\/\/kubernetes.io\/docs\/concepts\/workloads\/pods\/pod-overview\/#pods-and-controllers\" rel=\"noopener noreferrer\" target=\"_blank\"><em>Pod<\/em><\/a>&nbsp;is the basic building block of Kubernetes. A Pod contains a group of one or more containers. Generally, each Pod has one container.<\/p>\n<figure id=\"ef2d\" name=\"ef2d\">\n<p><canvas height=\"50\" width=\"75\"><\/canvas><img decoding=\"async\" data-src=\"https:\/\/cdn-images-1.medium.com\/max\/800\/1*ziwaLWYlP_X4gHhf6uuYww.png\" src=\"https:\/\/cdn-images-1.medium.com\/max\/800\/1*ziwaLWYlP_X4gHhf6uuYww.png\" \/><\/p>\n<\/figure>\n<p name=\"124c\" style=\"text-align: center;\">Pod<\/p>\n<p id=\"124c\" name=\"124c\">Pods handle Volumes, Secrets, and configuration for containers.<\/p>\n<p id=\"0635\" name=\"0635\">Pods are ephemeral. They are intended to be restarted automatically when they die.<\/p>\n<p id=\"1f35\" name=\"1f35\">Pods are replicated when the app is scaled horizontally by the ReplicationSet. Each Pod will run the same container code.<\/p>\n<p id=\"6791\" name=\"6791\">Pods live on Worker Nodes.<\/p>\n<h3 id=\"5a97\" name=\"5a97\">Cluster Level<\/h3>\n<h4 id=\"a270\" name=\"a270\">Cluster<\/h4>\n<p id=\"240a\" name=\"240a\">A K8s Cluster consists of a C<em>luster Master&nbsp;<\/em>and&nbsp;<em>Worker Nodes.<\/em><\/p>\n<figure id=\"0ada\" name=\"0ada\">\n<p><canvas height=\"75\" width=\"75\"><\/canvas><img decoding=\"async\" data-src=\"https:\/\/cdn-images-1.medium.com\/max\/800\/1*vT2FsK1vXVu42yipNoagSQ.jpeg\" src=\"https:\/\/cdn-images-1.medium.com\/max\/800\/1*vT2FsK1vXVu42yipNoagSQ.jpeg\" \/><\/p>\n<\/figure>\n<p name=\"35bb\" style=\"text-align: center;\">Star Cluster. Credit:&nbsp;<a data-href=\"https:\/\/www.spacetelescope.org\/images\/heic0715a\/\" href=\"https:\/\/www.spacetelescope.org\/images\/heic0715a\/\" rel=\"noopener noreferrer\" target=\"_blank\">NASA, ESA and the Hubble Heritage (STScI\/AURA)-ESA\/Hubble Collaboration<\/a><\/p>\n<p id=\"35bb\" name=\"35bb\">Below is a representation of a Cluster. This diagram emphasizes how multiple Pods can run on a Worker Node and multiple Worker Nodes are governed by a Master.<\/p>\n<figure id=\"cc4e\" name=\"cc4e\">\n<p><canvas height=\"70\" width=\"75\"><\/canvas><img decoding=\"async\" data-src=\"https:\/\/cdn-images-1.medium.com\/max\/800\/1*gT5K52iFTJf6SDhwWBaClQ.png\" src=\"https:\/\/cdn-images-1.medium.com\/max\/800\/1*gT5K52iFTJf6SDhwWBaClQ.png\" \/><\/p>\n<\/figure>\n<p name=\"9e13\" style=\"text-align: center;\">Kubernetes Nodes, Pods, &amp; Containers &copy; Jeff Hale&nbsp;2019<\/p>\n<h4 id=\"9e13\" name=\"9e13\">Worker Node<\/h4>\n<p id=\"161d\" name=\"161d\">A&nbsp;<a data-href=\"https:\/\/kubernetes.io\/docs\/concepts\/architecture\/nodes\/\" href=\"https:\/\/kubernetes.io\/docs\/concepts\/architecture\/nodes\/\" rel=\"noopener noreferrer\" target=\"_blank\"><em>Worker Node<\/em><\/a><em>&nbsp;<\/em>is<em>&nbsp;<\/em>also referred to as a&nbsp;<em>Node<\/em>&nbsp;for short<em>.&nbsp;<\/em>A Node is an abstraction for a machine\u200a&mdash;\u200aeither a physical machine or a virtual machine. Think of a Node as a computer server.<\/p>\n<p id=\"de1d\" name=\"de1d\">One or more Pods run on a single Worker Node.<\/p>\n<p id=\"bfb2\" name=\"bfb2\">A Pod is never split between two Nodes\u200a&mdash;\u200aa Pod&rsquo;s contents are always located and scheduled together on the same Node.<\/p>\n<p id=\"adfc\" name=\"adfc\">Who&rsquo;s telling the Worker Nodes what to do? The Master.<\/p>\n<h4 id=\"7a1b\" name=\"7a1b\">Cluster Master<\/h4>\n<p id=\"c88a\" name=\"c88a\">The<em>&nbsp;<\/em><a data-href=\"https:\/\/cloud.google.com\/kubernetes-engine\/docs\/concepts\/cluster-architecture#master\" href=\"https:\/\/cloud.google.com\/kubernetes-engine\/docs\/concepts\/cluster-architecture#master\" rel=\"noopener noreferrer\" target=\"_blank\"><em>Cluster Master<\/em><\/a><em>&nbsp;<\/em>has a seriously ridiculous number of aliases. It&rsquo;s also referred to as the&nbsp;<em>Master Node, Kubernetes Master, Cluster Control Plane, Control Plane,&nbsp;<\/em>and<em>&nbsp;<\/em>just M<em>aster.&nbsp;<\/em>Whatever you call it, it directs the Worker Nodes. Masters make scheduling decisions, respond to events, implement changes, and monitor the Cluster.<\/p>\n<p id=\"3aad\" name=\"3aad\">Both the Worker Nodes and the Master have subprocess components.<\/p>\n<h3 id=\"1d22\" name=\"1d22\">Node Processes<\/h3>\n<h4 id=\"b4bc\" name=\"b4bc\">Master Components<\/h4>\n<p id=\"da7c\" name=\"da7c\">The Master components are the&nbsp;<em>API<\/em>&nbsp;<em>server (<\/em>aka<em>&nbsp;kube-apiserver)<\/em>,&nbsp;<em>etc d<\/em>, S<em>cheduler&nbsp;<\/em>(aka&nbsp;<em>kube-scheduler), kube-controller-manager, and cloud-controller manager<\/em>. **I added the controller-managers for completeness Apr. 10, 2019**<\/p>\n<figure id=\"85e0\" name=\"85e0\">\n<p><canvas height=\"47\" width=\"75\"><\/canvas><img decoding=\"async\" data-src=\"https:\/\/cdn-images-1.medium.com\/max\/800\/1*2B3eMo0iCx3GCPoHWHd1EQ.png\" src=\"https:\/\/cdn-images-1.medium.com\/max\/800\/1*2B3eMo0iCx3GCPoHWHd1EQ.png\" \/><\/p>\n<\/figure>\n<p name=\"7fee\" style=\"text-align: center;\">Cluster Master subprocesses<\/p>\n<p id=\"7fee\" name=\"7fee\">Let&rsquo;s briefly look at each one.<\/p>\n<p id=\"ac56\" name=\"ac56\"><strong><em>API Server<\/em><\/strong>\u200a&mdash;\u200aExposes the K8s API. It&rsquo;s the frontend for Kubernetes control. (aka. kube-apiserver) Think&nbsp;<em>hub<\/em>.&nbsp;<br \/>\n<strong><em>etcd\u200a<\/em><\/strong>&mdash;\u200aDistributed key-value store for Cluster state data. Think&nbsp;<em>Cluster info<\/em>.<br \/>\n<strong><em>Scheduler\u200a<\/em><\/strong>&mdash;\u200aSelects the Nodes for new Pods. Good guide&nbsp;<a href=\"https:\/\/medium.com\/@dominik.tornow\/the-kubernetes-scheduler-cd429abac02f\" target=\"_blank\" rel=\"noopener noreferrer\" class=\"broken_link\">here<\/a>. (aka kube-scheduler) Think&nbsp;<em>matcher<\/em>.<br \/>\n<strong><em>kube-controller-manager&nbsp;<\/em><\/strong>&mdash;Process that runs controllers to handle Cluster background tasks. Think&nbsp;<em>Cluster controller<\/em>.<br \/>\n<strong><em>cloud-controller-manager\u200a<\/em><\/strong><em>&mdash;\u200a<\/em>Runs controllers that interact with cloud providers. Think&nbsp;<em>cloud interface<\/em>.<\/p>\n<h4 id=\"1658\" name=\"1658\">Worker Node Components<\/h4>\n<p id=\"4bc3\" name=\"4bc3\">The Worker Node&rsquo;s&nbsp;<a data-href=\"https:\/\/kubernetes.io\/docs\/concepts\/overview\/components\/#node-components\" href=\"https:\/\/kubernetes.io\/docs\/concepts\/overview\/components\/#node-components\" rel=\"noopener noreferrer\" target=\"_blank\">components<\/a>&nbsp;are the&nbsp;<em>kubelet<\/em>,&nbsp;<em>kube-proxy<\/em>, and&nbsp;<em>Container Runtime<\/em>.<\/p>\n<figure id=\"d845\" name=\"d845\">\n<p><canvas height=\"47\" width=\"75\"><\/canvas><img decoding=\"async\" data-src=\"https:\/\/cdn-images-1.medium.com\/max\/800\/1*rrm3H9IVzNOrlLmJsvE4dg.png\" src=\"https:\/\/cdn-images-1.medium.com\/max\/800\/1*rrm3H9IVzNOrlLmJsvE4dg.png\" \/><\/p>\n<\/figure>\n<p name=\"605d\" style=\"text-align: center;\">Worker Node subprocesses<\/p>\n<p id=\"605d\" name=\"605d\"><strong><em>kubelet<\/em><\/strong>\u200a&mdash;\u200aResponsible for everything on the Worker Node. It communicates with the Master&rsquo;s API server. Think&nbsp;<em>brain<\/em>&nbsp;for Worker Node.<br \/>\n<a data-href=\"https:\/\/kubernetes.io\/docs\/reference\/command-line-tools-reference\/kube-proxy\/\" href=\"https:\/\/kubernetes.io\/docs\/reference\/command-line-tools-reference\/kube-proxy\/\" rel=\"noopener noreferrer\" target=\"_blank\"><strong><em>kube-proxy<\/em><\/strong><\/a>\u200a&mdash;\u200aRoutes connections to the correct Pods. Also performs load balancing across Pods for a Service. Think&nbsp;<em>traffic cop<\/em>.<br \/>\n<strong><em>Container Runtime<\/em>\u200a<\/strong>&mdash;\u200aDownloads images and runs containers. For example, Docker is a Container Runtime. Think&nbsp;<em>Docker<\/em>.<\/p>\n<p id=\"530a\" name=\"530a\">Let&rsquo;s drill down one final level and look at what those Container Runtimes are running.&nbsp;<\/p>\n<h3 id=\"4cd5\" name=\"4cd5\">Docker Container Level<\/h3>\n<p id=\"09ea\" name=\"09ea\">Your app needs to be in a container of some sort if you want to run it with K8s. Docker is by far the most common container platform. We&rsquo;ll assume you&rsquo;re using it.<canvas height=\"62\" width=\"75\"><\/canvas><\/p>\n<p name=\"bb67\" style=\"text-align: center;\"><img decoding=\"async\" data-src=\"https:\/\/cdn-images-1.medium.com\/max\/800\/1*glD7bNJG3SlO0_xNmSGPcQ.png\" src=\"https:\/\/cdn-images-1.medium.com\/max\/800\/1*glD7bNJG3SlO0_xNmSGPcQ.png\" \/><\/p>\n<p id=\"bb67\" name=\"bb67\">You&rsquo;ll specify which Docker image your Pods should use when you create your Deployment. The Container Runtime will download the image and create the containers.<\/p>\n<p id=\"2105\" name=\"2105\">K8s doesn&rsquo;t create containers directly. It creates Pods that hold containers inside them. The containers in a Pod share any configured resources, such as Volume storage.<\/p>\n<p id=\"0223\" name=\"0223\">There are five high-level K8s API resources that manage and run Pods:&nbsp;<em>Deployments, StatefulSets, DaemonSets, Jobs,&nbsp;<\/em>and<em>&nbsp;CronJobs<\/em>. These objects are responsible for managing and running the Pods that create and run your containers. Let&rsquo;s look at these controllers that create and manage continuous processes<\/p>\n<h3 id=\"fd17\" name=\"fd17\">ReplicaSets, StatefulSets, and DaemonSets<\/h3>\n<p id=\"3794\" name=\"3794\">As you&rsquo;ve seen, a<em>&nbsp;<\/em>ReplicaSet<em>&nbsp;<\/em>creates and manages Pods. If a Pod shuts down because a Node fails, a ReplicaSet can automatically replace the Pod on another Node. You should generally create a ReplicaSet through a Deployment rather than creating it directly, because it&rsquo;s easier to update your app with a Deployment.<\/p>\n<figure id=\"2840\" name=\"2840\">\n<p><canvas height=\"40\" width=\"75\"><\/canvas><img decoding=\"async\" data-src=\"https:\/\/cdn-images-1.medium.com\/max\/800\/1*4J08LAIHRduvtlaj_KzJGA.png\" src=\"https:\/\/cdn-images-1.medium.com\/max\/800\/1*4J08LAIHRduvtlaj_KzJGA.png\" \/><\/p>\n<\/figure>\n<p name=\"2328\" style=\"text-align: center;\">A Volume can be attached to a ReplicaSet, but it&rsquo;s required for a StatefulSet. &copy; Jeff Hale&nbsp;2019<\/p>\n<p id=\"2328\" name=\"2328\">Sometimes your app will need to keep information about its state. You can think of state as the current status of your user&rsquo;s interaction with your app. So in a video game it&rsquo;s all the unique aspects of the user&rsquo;s character at a point in time.<\/p>\n<p id=\"11c8\" name=\"11c8\">For example, the state in the original&nbsp;<a data-href=\"https:\/\/en.wikipedia.org\/wiki\/Super_Mario#Super_Mario_Bros.\" href=\"https:\/\/en.wikipedia.org\/wiki\/Super_Mario#Super_Mario_Bros.\" rel=\"noopener noreferrer\" target=\"_blank\">Super Mario Bros.<\/a>&nbsp;game would include every relevant aspect of the user&rsquo;s game: what level, what location in that level, big or small, fireballs or no fireballs, how many coins, how many points, and how many lives.<\/p>\n<figure id=\"fb7a\" name=\"fb7a\">\n<p><canvas height=\"55\" width=\"75\"><\/canvas><img decoding=\"async\" data-src=\"https:\/\/cdn-images-1.medium.com\/max\/800\/1*Ofsyr1MsOaxCerN6fa0A-w.jpeg\" src=\"https:\/\/cdn-images-1.medium.com\/max\/800\/1*Ofsyr1MsOaxCerN6fa0A-w.jpeg\" style=\"width: 700px; height: 522px;\" \/><\/p>\n<\/figure>\n<p id=\"a3c5\" name=\"a3c5\">What do you do when your app has state you need to keep track of? Use a StatefulSet.<\/p>\n<h4 id=\"75a3\" name=\"75a3\">StatefulSet<\/h4>\n<p id=\"502d\" name=\"502d\">Like a ReplicaSet, a<em>&nbsp;<\/em><a data-href=\"https:\/\/kubernetes.io\/docs\/concepts\/workloads\/controllers\/statefulset\/\" href=\"https:\/\/kubernetes.io\/docs\/concepts\/workloads\/controllers\/statefulset\/\" rel=\"noopener noreferrer\" target=\"_blank\"><em>StatefulSet<\/em><\/a><em>&nbsp;<\/em>manages deployment and scaling of a group of Pods based on a container spec. Unlike a Deployment, a StatefulSet&rsquo;s Pods are not interchangeable. Each Pod has a unique, persistent identifier that the controller maintains over any rescheduling. StatefulSets for good for persistent, stateful backends like databases.<\/p>\n<p id=\"0f60\" name=\"0f60\">The state information for the Pod is held in a Volume associated with the StatefulSet. We&rsquo;ll discuss Volumes in a bit.<\/p>\n<h4 id=\"581b\" name=\"581b\">DaemonSet<\/h4>\n<p id=\"4630\" name=\"4630\"><a data-href=\"https:\/\/kubernetes.io\/docs\/concepts\/workloads\/controllers\/daemonset\/\" href=\"https:\/\/kubernetes.io\/docs\/concepts\/workloads\/controllers\/daemonset\/\" rel=\"noopener noreferrer\" target=\"_blank\"><em>DaemonSets<\/em><\/a>&nbsp;are for continuous process. They run one Pod per Node. Each new Node added to the cluster automatically gets a Pod started by the DaemonSet. DaemonSets are useful for ongoing background tasks such as monitoring and log collection.<\/p>\n<p id=\"b864\" name=\"b864\">StatefulSets and DaemonSets are not controlled by a Deployment. Although they are at the same level of abstraction as a ReplicaSet, there is not a higher level of abstraction for them in the current API.<\/p>\n<p id=\"66b0\" name=\"66b0\">Now let&rsquo;s look at Jobs and CronJobs.<\/p>\n<h3 id=\"fe26\" name=\"fe26\">Jobs and&nbsp;CronJobs<\/h3>\n<h4 id=\"801f\" name=\"801f\">Job<\/h4>\n<p id=\"6fd1\" name=\"6fd1\">A&nbsp;<a data-href=\"https:\/\/kubernetes.io\/docs\/concepts\/workloads\/controllers\/jobs-run-to-completion\/\" href=\"https:\/\/kubernetes.io\/docs\/concepts\/workloads\/controllers\/jobs-run-to-completion\/\" rel=\"noopener noreferrer\" target=\"_blank\"><em>Job<\/em><\/a><em>&nbsp;<\/em>is a supervisor for Pods that run a batch process. A Job creates Pods and ensures they do a task by tracking the number of successful Pod completions. Unlike a ReplicaSet, once the process inside the container finishes successfully, the container is not restarted. Use a Job when you want to run a process once.<\/p>\n<h4 id=\"272c\" name=\"272c\">CronJob<\/h4>\n<p id=\"7f21\" name=\"7f21\">If you want to run a Job at regular, specified times (e.g. hourly, daily, or monthly), create a&nbsp;<a data-href=\"https:\/\/kubernetes.io\/docs\/concepts\/workloads\/controllers\/cron-jobs\/\" href=\"https:\/\/kubernetes.io\/docs\/concepts\/workloads\/controllers\/cron-jobs\/\" rel=\"noopener noreferrer\" target=\"_blank\"><em>CronJob<\/em><\/a><em>.&nbsp;<\/em>A CronJob is similar to a Job, but is scheduled to repeat at regular intervals or set times.<\/p>\n<figure id=\"d5fb\" name=\"d5fb\">\n<p><canvas height=\"47\" width=\"75\"><\/canvas><img decoding=\"async\" data-src=\"https:\/\/cdn-images-1.medium.com\/max\/800\/1*jsgssp7WXxxYULDxk_jVbw.jpeg\" src=\"https:\/\/cdn-images-1.medium.com\/max\/800\/1*jsgssp7WXxxYULDxk_jVbw.jpeg\" \/><\/p>\n<\/figure>\n<p name=\"494a\" style=\"text-align: center;\">Time<\/p>\n<p id=\"494a\" name=\"494a\">You&rsquo;ll often need to create a Service to provide consistent access to your ephemeral Pods.<\/p>\n<h3 id=\"a90b\" name=\"a90b\">Service<\/h3>\n<p id=\"894d\" name=\"894d\">A K8s&nbsp;<a data-href=\"https:\/\/kubernetes.io\/docs\/concepts\/services-networking\/service\/\" href=\"https:\/\/kubernetes.io\/docs\/concepts\/services-networking\/service\/\" rel=\"noopener noreferrer\" target=\"_blank\"><em>Service<\/em><\/a>&nbsp;creates a single access point for a group of Pods. A Service provides a consistent IP address and port to access underlying Pods. Both external users and internal Pods use Services to communicate with other Pods.<\/p>\n<p id=\"f605\" name=\"f605\">Services come in a variety of flavors. Networking with K8s a topic worthy of its own guide. Fortunately, there&rsquo;s a good one by&nbsp;<a action=\"show-user-card\" type=\"2\" value=\"bba63600816e\" href=\"https:\/\/medium.com\/@SandeepDinesh\" id=\"bba63600816e\" target=\"_blank\" rel=\"noopener noreferrer\" class=\"broken_link\">Sandeep Dinesh<\/a>&nbsp;<a href=\"https:\/\/medium.com\/google-cloud\/kubernetes-nodeport-vs-loadbalancer-vs-ingress-when-should-i-use-what-922f010849e0\" target=\"_blank\" rel=\"noopener noreferrer\" class=\"broken_link\">here<\/a>.<\/p>\n<p id=\"1fb2\" name=\"1fb2\">Now let&rsquo;s look at storing data with Volumes and PersistentVolumes.<\/p>\n<h3 id=\"d776\" name=\"d776\">Volumes, PersistentVolumes, and PersistentVolume Claims<\/h3>\n<h4 id=\"a92a\" name=\"a92a\">Volumes<\/h4>\n<p id=\"a340\" name=\"a340\">A&nbsp;<a data-href=\"https:\/\/kubernetes.io\/docs\/concepts\/storage\/volumes\/\" href=\"https:\/\/kubernetes.io\/docs\/concepts\/storage\/volumes\/\" rel=\"noopener noreferrer\" target=\"_blank\"><em>Volume<\/em><\/a>&nbsp;is a directory that can hold data. A Volume is a component of a Pod, and is not independent of it. A Volume is created in the Pod specification. A Volume cannot be deleted on its own.<\/p>\n<p id=\"eb53\" name=\"eb53\">A Volume is made accessible to all the containers in a Pod. Each container that you want to access the Volume must mount it individually.<\/p>\n<p id=\"b5fd\" name=\"b5fd\">A K8s Volume outlives any individual containers, but when the enclosing Pod dies, the Volume dies, too. However, the files of some Volume types continue to exist in local or cloud storage, even after the Volume is gone.<\/p>\n<figure id=\"0ef2\" name=\"0ef2\">\n<p><canvas height=\"47\" width=\"75\"><\/canvas><img decoding=\"async\" data-src=\"https:\/\/cdn-images-1.medium.com\/max\/800\/1*7NY9Itkqy57i_Hd8uP-FuA.jpeg\" src=\"https:\/\/cdn-images-1.medium.com\/max\/800\/1*7NY9Itkqy57i_Hd8uP-FuA.jpeg\" \/><\/p>\n<\/figure>\n<p name=\"c0bb\" style=\"text-align: center;\">Volumes<\/p>\n<p id=\"c0bb\" name=\"c0bb\">A K8s Volume has more functionality than a Docker volume. A Volume can provide access to local disk storage, memory storage, or cloud storage. A Pod can use a combination of them simultaneously.<\/p>\n<p id=\"be5a\" name=\"be5a\">K8s Volume types include empty directories, Worker Node&rsquo;s filesystems, and cloud provider-specific storage. For example, awsEleasticBlockStore and gcePersistentDisk are provider-specific options for long-term storage. See more in the docs&nbsp;<a data-href=\"https:\/\/kubernetes.io\/docs\/concepts\/storage\/volumes\/\" href=\"https:\/\/kubernetes.io\/docs\/concepts\/storage\/volumes\/\" rel=\"noopener noreferrer\" target=\"_blank\">here<\/a>.<\/p>\n<h4 id=\"f6c6\" name=\"f6c6\">PersistentVolumes and PersistentVolumeClaims<\/h4>\n<p id=\"4b33\" name=\"4b33\">To help abstract away infrastructure specifics, K8s developed&nbsp;<a data-href=\"https:\/\/kubernetes.io\/docs\/concepts\/storage\/persistent-volumes\/\" href=\"https:\/\/kubernetes.io\/docs\/concepts\/storage\/persistent-volumes\/\" rel=\"noopener noreferrer\" target=\"_blank\"><em>PersistentVolumes<\/em><\/a><em>&nbsp;<\/em>and&nbsp;<em>PersistentVolumeClaims<\/em>. Unfortunately the names are a bit misleading, because vanilla Volumes can have persistent storage, as well.<\/p>\n<p id=\"d725\" name=\"d725\">PersisententVolumes (PV) and PersisentVolumeClaims (PVC) add complexity compared to using Volumes alone. However, PVs are useful for managing storage resources for large projects.<\/p>\n<p id=\"5b0a\" name=\"5b0a\">With PVs, a K8s user still ends up using a Volume, but two steps are required first.<\/p>\n<ol>\n<li id=\"fa3f\" name=\"fa3f\">A PersistentVolume is provisioned by a Cluster Administrator (or it&rsquo;s provisioned dynamically).<\/li>\n<li id=\"3a33\" name=\"3a33\">An individual Cluster user who needs storage for a Pod creates a&nbsp;<em>PersistentVolumeClaim&nbsp;<\/em>manifest. It specifies how much and what type of storage they need. K8s then finds and reserves the storage needed.<\/li>\n<\/ol>\n<p id=\"50b0\" name=\"50b0\">The user then creates a Pod with a Volume that uses the PVC.<\/p>\n<p id=\"28a9\" name=\"28a9\">PersistentVolumes have lifecycles independent of any Pod. In fact, the Pod doesn&rsquo;t even know about the PV, just the PVC.<\/p>\n<p id=\"d77d\" name=\"d77d\">PVCs consume PV resources, analogously to how Pods consume Node resources. Wild!<\/p>\n<figure id=\"2e40\" name=\"2e40\">\n<p><canvas height=\"75\" width=\"51\"><\/canvas><img decoding=\"async\" data-src=\"https:\/\/cdn-images-1.medium.com\/max\/800\/1*58estJjCSLocLzWKP3sm0w.jpeg\" src=\"https:\/\/cdn-images-1.medium.com\/max\/800\/1*58estJjCSLocLzWKP3sm0w.jpeg\" style=\"width: 700px; height: 1043px;\" \/><\/p>\n<\/figure>\n<p name=\"c231\" style=\"text-align: center;\">Wild<\/p>\n<h3 id=\"c231\" name=\"c231\">Wrap<\/h3>\n<p id=\"2aa4\" name=\"2aa4\">I hope you found this introduction to K8s concepts helpful.&nbsp;<\/p>\n<p id=\"b2e7\" name=\"b2e7\">Let&rsquo;s recap the K8s concepts we&rsquo;ve seen. Here are the six levels of abstraction for a Deployment:<\/p>\n<ul>\n<li id=\"b952\" name=\"b952\"><strong>Deployment<\/strong>: manages ReplicaSets. Use for persistent, stateless apps (e.g. HTTP servers).<\/li>\n<li id=\"1a37\" name=\"1a37\"><strong>ReplicaSet<\/strong><em>:<\/em>&nbsp;creates and manages Pods.<\/li>\n<li id=\"3fc5\" name=\"3fc5\"><strong>Pod<\/strong><em>:&nbsp;<\/em>basic unit of K8s.<\/li>\n<li id=\"e04a\" name=\"e04a\"><strong>Node Cluster<\/strong>: Worker Nodes + Cluster Master.<br \/>\n&#8211;&nbsp;<strong>Worker<\/strong>&nbsp;<strong>Nodes<\/strong>: machines for Pods.<br \/>\n&#8211;&nbsp;<strong>Cluster Master<\/strong><em>:&nbsp;<\/em>directs worker nodes.<\/li>\n<li id=\"1d5b\" name=\"1d5b\"><strong>Node Processes<\/strong><br \/>\nMaster subcomponents:<br \/>\n&#8211;&nbsp;<strong>API server<\/strong>: hub.<br \/>\n&#8211;&nbsp;<strong>etcd<\/strong>: cluster info.<br \/>\n&#8211;&nbsp;<strong>scheduler<\/strong>: matcher.<br \/>\n&#8211;&nbsp;<strong>kube-controller-manager<em>:&nbsp;<\/em><\/strong>cluster controller.<br \/>\n&#8211;&nbsp;<strong>cloud-controller-manager:&nbsp;<\/strong>cloud interfa.<br \/>\nWorker Node subcomponents:<br \/>\n&#8211;&nbsp;<strong>kubelet<\/strong>: Worker Node brain.<br \/>\n&#8211;&nbsp;<strong>kube-proxy<\/strong>: traffic cop.<br \/>\n&#8211;&nbsp;<strong>container-runtime<\/strong>: Docker.<\/li>\n<li id=\"09fe\" name=\"09fe\"><strong>Docker Container:&nbsp;<\/strong>where the app code lives.<\/li>\n<\/ul>\n<p id=\"c29f\" name=\"c29f\">Here are the 7 additional high-level K8s API objects to know:<\/p>\n<ul>\n<li id=\"104f\" name=\"104f\"><strong>StatefulSet<\/strong>: Like a ReplicaSet for stateful processes. Think&nbsp;<em>state<\/em>.<\/li>\n<li id=\"5f24\" name=\"5f24\"><strong>DaemonSet:&nbsp;<\/strong>One automatic Pod per Node. Think&nbsp;<em>monitor<\/em>.<\/li>\n<li id=\"970c\" name=\"970c\"><strong>Job<\/strong>: Run a container to completion. Think&nbsp;<em>batch<\/em>.<\/li>\n<li id=\"2dc0\" name=\"2dc0\"><strong>CronJob:&nbsp;<\/strong>Repeated Job.<strong>&nbsp;<\/strong>Think&nbsp;<em>time<\/em>.<\/li>\n<li id=\"5ec9\" name=\"5ec9\"><strong>Service<\/strong>: Access point for Pods. Think&nbsp;<em>access point<\/em>.<\/li>\n<li id=\"d78a\" name=\"d78a\"><strong>Volume<\/strong>: Holds data. Think<em>&nbsp;disk.<\/em><\/li>\n<li id=\"67af\" name=\"67af\"><strong>PersistentVolume, PersistentVolumeClaim:<\/strong>&nbsp;System for allocating storage. Think&nbsp;<em>storage claim<\/em>.<\/li>\n<\/ul>\n<p id=\"9fc1\" name=\"9fc1\">Wrapping your head around K8s requires understanding many abstract concepts. Don&rsquo;t expect that you&rsquo;ll remember them all the first time. Check out some of the resources below to build your mental model.<\/p>\n<h4 id=\"ebc7\" name=\"ebc7\">Resources<\/h4>\n<p id=\"80c5\" name=\"80c5\">Here are resources to reinforce what you&rsquo;ve learned.<\/p>\n<ul>\n<li id=\"b9d1\" name=\"b9d1\"><a data-href=\"https:\/\/cloud.google.com\/kubernetes-engine\/kubernetes-comic\/\" href=\"https:\/\/cloud.google.com\/kubernetes-engine\/kubernetes-comic\/\" rel=\"noopener noreferrer\" target=\"_blank\">Here&rsquo;s a nice comic<\/a>&nbsp;from Google that introduces key concepts.<\/li>\n<li id=\"c165\" name=\"c165\"><a href=\"https:\/\/medium.com\/google-cloud\/kubernetes-101-pods-nodes-containers-and-clusters-c1509e409e16\" target=\"_blank\" rel=\"noopener noreferrer\" class=\"broken_link\">Another good overview<\/a>&nbsp;of key K8s concepts by&nbsp;<a action=\"show-user-card\" type=\"2\" value=\"b850cff30f35\" href=\"https:\/\/medium.com\/@sanche\" id=\"b850cff30f35\" target=\"_blank\" rel=\"noopener noreferrer\" class=\"broken_link\">Daniel Sanche<\/a>.<\/li>\n<li id=\"6900\" name=\"6900\">Check out Nigel Poulton&rsquo;s&nbsp;<a data-href=\"https:\/\/www.amazon.com\/Kubernetes-Book-Version-November-2018-ebook-dp-B072TS9ZQZ\/dp\/B072TS9ZQZ\/ref=mt_kindle?_encoding=UTF8&amp;me=&amp;qid=1509660871\" href=\"https:\/\/www.amazon.com\/Kubernetes-Book-Version-November-2018-ebook-dp-B072TS9ZQZ\/dp\/B072TS9ZQZ\/ref=mt_kindle?_encoding=UTF8&amp;me=&amp;qid=1509660871\" rel=\"noopener noreferrer\" target=\"_blank\">The Kubernetes Book<\/a>\u200a&mdash;\u200anow at v3. The Kindle Book was last updated Nov. 2018.<\/li>\n<\/ul>\n<p id=\"e4d0\" name=\"e4d0\">&nbsp;In the next article, I&rsquo;ll show you how to set up and run your first K8s Deployment. We&rsquo;ll also cover key K8s commands.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Cloud computing, containerization, and container orchestration are the most important trends in DevOps. Whether you&rsquo;re a data scientist, software developer, or product manager, it&rsquo;s good to know Docker and Kubernetes basics. Both technologies help you collaborate with others, deploy your projects, and increase your value to employers. In this article, we&rsquo;ll cover essential Kubernetes concepts. T Kubernetes is an open-source platform for managing containerized apps in production. Kubernetes is referred to as K8s for short.&nbsp; here are a lot of Kubernetes terms.<\/p>\n","protected":false},"author":369,"featured_media":2521,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"content-type":"","footnotes":""},"categories":[187],"tags":[94],"ppma_author":[2134],"class_list":["post-1645","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-bigdata-cloud","tag-data-science"],"authors":[{"term_id":2134,"user_id":369,"is_guest":0,"slug":"jeff-hale","display_name":"Jeff Hale","avatar_url":"https:\/\/secure.gravatar.com\/avatar\/?s=96&d=mm&r=g","user_url":"","last_name":"Hale","first_name":"Jeff","job_title":"","description":"Jeff Hale is a co-founder of Rebel Desk, where he oversees technology, finance, and operations for this company. He&nbsp;is an experienced entrepreneur who has managed technology, operations, and finances for several companies.&nbsp;"}],"_links":{"self":[{"href":"https:\/\/www.experfy.com\/blog\/wp-json\/wp\/v2\/posts\/1645","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.experfy.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.experfy.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.experfy.com\/blog\/wp-json\/wp\/v2\/users\/369"}],"replies":[{"embeddable":true,"href":"https:\/\/www.experfy.com\/blog\/wp-json\/wp\/v2\/comments?post=1645"}],"version-history":[{"count":1,"href":"https:\/\/www.experfy.com\/blog\/wp-json\/wp\/v2\/posts\/1645\/revisions"}],"predecessor-version":[{"id":5886,"href":"https:\/\/www.experfy.com\/blog\/wp-json\/wp\/v2\/posts\/1645\/revisions\/5886"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.experfy.com\/blog\/wp-json\/wp\/v2\/media\/2521"}],"wp:attachment":[{"href":"https:\/\/www.experfy.com\/blog\/wp-json\/wp\/v2\/media?parent=1645"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.experfy.com\/blog\/wp-json\/wp\/v2\/categories?post=1645"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.experfy.com\/blog\/wp-json\/wp\/v2\/tags?post=1645"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.experfy.com\/blog\/wp-json\/wp\/v2\/ppma_author?post=1645"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}