{"id":219324,"date":"2021-04-05T15:00:36","date_gmt":"2021-04-05T12:00:36","guid":{"rendered":"https:\/\/en.buradabiliyorum.com\/kubernetes-resources-explained-cloudsavvy-it\/"},"modified":"2021-04-05T15:00:36","modified_gmt":"2021-04-05T12:00:36","slug":"kubernetes-resources-explained-cloudsavvy-it","status":"publish","type":"post","link":"https:\/\/buradabiliyorum.com\/en\/kubernetes-resources-explained-cloudsavvy-it\/","title":{"rendered":"#Kubernetes Resources Explained \u2013 CloudSavvy IT"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_84 counter-hierarchy ez-toc-counter ez-toc-custom ez-toc-container-direction\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<label for=\"ez-toc-cssicon-toggle-item-6a2d524f8e634\" class=\"ez-toc-cssicon-toggle-label\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #dd3333;color:#dd3333\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #dd3333;color:#dd3333\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/label><input type=\"checkbox\"  id=\"ez-toc-cssicon-toggle-item-6a2d524f8e634\" checked aria-label=\"Toggle\" \/><nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/buradabiliyorum.com\/en\/kubernetes-resources-explained-cloudsavvy-it\/#Pods\" >Pods<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/buradabiliyorum.com\/en\/kubernetes-resources-explained-cloudsavvy-it\/#Replica_Sets\" >Replica Sets<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/buradabiliyorum.com\/en\/kubernetes-resources-explained-cloudsavvy-it\/#Deployments\" >Deployments<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/buradabiliyorum.com\/en\/kubernetes-resources-explained-cloudsavvy-it\/#Other_Kinds_of_Resource\" >Other Kinds of Resource<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/buradabiliyorum.com\/en\/kubernetes-resources-explained-cloudsavvy-it\/#Conclusion\" >Conclusion<\/a><\/li><\/ul><\/nav><\/div>\n<p><strong>&#8220;#Kubernetes Resources Explained \u2013 CloudSavvy IT&#8221;<\/strong><\/p>\n<div id=\"article-content-area\">\n<img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-9632\" data-pagespeed-lazy-src=\"https:\/\/www.cloudsavvyit.com\/p\/uploads\/2021\/02\/748108a6.jpg?width=1200&amp;trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"Graphic showing the Kubernetes logo\" width=\"1602\" height=\"902\" src=\"\/pagespeed_static\/1.JiBnMqyl6S.gif\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>Kubernetes is not known for being <a href=\"https:\/\/buradabiliyorum.com\/en\/category\/download-scripts-themes-apps\/\" data-internallinksmanager029f6b8e52c=\"9\" title=\"Download Scripts &amp; Themes &amp; Apps\" target=\"_blank\" rel=\"noopener\">app<\/a>roachable. To master Kubernetes, you need to understand how its abstractions fit together. Kubernetes comes with dozens of resource types which you can use within your applications. Let\u2019s look at the roles of the most frequently used resources.<\/p>\n<h2 id=\"pods\"><span class=\"ez-toc-section\" id=\"Pods\"><\/span>Pods<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>If there\u2019s one Kubernetes term to learn, it\u2019s \u201cPod.\u201d <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/kubernetes.io\/docs\/concepts\/workloads\/pods\">Pods<\/a> are the fundamental compute unit used by Kubernetes. They host your running containers. For this reason, it\u2019s common to liken a pod to an instance of a Docker container.<\/p>\n<p>This likeness isn\u2019t exact as a single Kubernetes pod may have multiple containers running within it. Pods are better seen as a \u201cgroup\u201d of containers that have a shared execution context. The Pod\u2019s environment is isolated; the individual container environments within are further sub-isolated.<\/p>\n<p>Containers in a pod are always scheduled onto the same Kubernetes node. They\u2019ll run on the same physical machine and can share storage and network resources.<\/p>\n<div class=\"wp-geshi-highlight-wrap5\">\n<div class=\"wp-geshi-highlight-wrap4\">\n<div class=\"wp-geshi-highlight-wrap3\">\n<div class=\"wp-geshi-highlight-wrap2\">\n<div class=\"wp-geshi-highlight-wrap\">\n<div class=\"wp-geshi-highlight\">\n<div class=\"yaml\">\n<pre class=\"de1\"><span class=\"co3\">apiVersion<\/span><span class=\"sy2\">: <\/span>v1<span class=\"co3\">\nkind<\/span><span class=\"sy2\">: <\/span>Pod<span class=\"co4\">\nmetadata<\/span>:<span class=\"co3\">\n  name<\/span><span class=\"sy2\">: <\/span>my-pod<span class=\"co4\">\nspec<\/span>:<span class=\"co4\">\n  containers<\/span>:<span class=\"co3\">\n    - name<\/span><span class=\"sy2\">: <\/span>my-container<span class=\"co3\">\n      image<\/span><span class=\"sy2\">: <\/span>my-image:latest<\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<p>The above manifest would manually create a single Pod. The Pod would run a container using the <code>my-image:latest<\/code> image.<\/p>\n<p>You don\u2019t normally manage Pods directly in Kubernetes. Pods are created as a consequence of adding other resources, such as a Deployment (see below). You should treat your Pods as ephemeral units. Kubernetes has control over the Pod and could reschedule it to another node if cluster resources become constrained.<\/p>\n<h2 id=\"replica-sets\"><span class=\"ez-toc-section\" id=\"Replica_Sets\"><\/span>Replica Sets<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/kubernetes.io\/docs\/concepts\/workloads\/controllers\/replicaset\">Replica Sets<\/a> (usually written as <code>ReplicaSets<\/code>, without a space) are another abstraction layer on top of Pods. ReplicaSets guarantee that there will be a specific number of identical Pods running at any given time.<\/p>\n<p>When using ReplicaSets, you get to enforce a minimum number of Pods for your application. You specify the number of Pods that should be run concurrently. Kubernetes then schedules enough Pods to meet the minimum availability you define. Remember that each Pod may consist of multiple running containers, depending on how your application is configured.<\/p>\n<p>When a Pod is created by a ReplicaSet, Kubernetes updates the Pod\u2019s <code>metadata.ownerReferences<\/code> field to include the ReplicaSet\u2019s identity. The ReplicaSet can then establish the Pods it controls, so it knows whether the minimum availability target has been met.<\/p>\n<p>ReplicaSets have a <code>replicas<\/code> field that defines the number of Pods to run. Change this value and apply the updated ReplicaSet manifest to your cluster to have Kubernetes reschedule your Pods to match the new replica count.<\/p>\n<p>This detail highlights an important point about ReplicaSets: Kubernetes only guarantees the number of running Pods will <em>eventually<\/em> match the replica count you\u2019ve specified. If you change the replica count, there will be a period of time where more or fewer Pods are running than your manifest indicates. The ReplicaSet will create or delete Pods until the desired number are operational.<\/p>\n<div class=\"wp-geshi-highlight-wrap5\">\n<div class=\"wp-geshi-highlight-wrap4\">\n<div class=\"wp-geshi-highlight-wrap3\">\n<div class=\"wp-geshi-highlight-wrap2\">\n<div class=\"wp-geshi-highlight-wrap\">\n<div class=\"wp-geshi-highlight\">\n<div class=\"yaml\">\n<pre class=\"de1\"><span class=\"co3\">apiVersion<\/span><span class=\"sy2\">: <\/span>apps\/v1<span class=\"co3\">\nkind<\/span><span class=\"sy2\">: <\/span>ReplicaSet<span class=\"co4\">\nmetadata<\/span>:<span class=\"co3\">\n  name<\/span><span class=\"sy2\">: <\/span>my-replicaset<span class=\"co4\">\n  labels<\/span>:<span class=\"co3\">\n    my-label<\/span><span class=\"sy2\">: <\/span>my-value<span class=\"co4\">\nspec<\/span>:<span class=\"co3\">\n  replicas<\/span><span class=\"sy2\">: <\/span>3<span class=\"co4\">\n  selector<\/span>:<span class=\"co4\">\n    matchLabels<\/span>:<span class=\"co3\">\n      my-label<\/span><span class=\"sy2\">: <\/span>my-value<span class=\"co4\">\n  template<\/span>:<span class=\"co4\">\n    metadata<\/span>:<span class=\"co4\">\n      labels<\/span>:<span class=\"co3\">\n        my-label<\/span><span class=\"sy2\">: <\/span>my-value<span class=\"co4\">\n    spec<\/span>:<span class=\"co4\">\n      containers<\/span>:<span class=\"co3\">\n        - name<\/span><span class=\"sy2\">: <\/span>app-container<span class=\"co3\">\n          image<\/span><span class=\"sy2\">: <\/span>my-image:latest<\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<p>The manifest above would run three replicas of the <code>my-image:latest<\/code> container image using a ReplicaSet. You could change the number of replicas by updating the value in the manifest and re-applying it (<code>kubectl apply -f my-manifest.yml<\/code>).<\/p>\n<h2 id=\"deployments\"><span class=\"ez-toc-section\" id=\"Deployments\"><\/span>Deployments<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>While ReplicaSets make it easier to work with Pods, they too are rarely used directly. <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/kubernetes.io\/docs\/concepts\/workloads\/controllers\/deployment\"><em>Deployments<\/em><\/a> are an abstraction atop ReplicaSets. You usually create a deployment when adding a new workload into a cluster.<\/p>\n<p>Deployment resources enable declarative updates of Pods and ReplicaSets. They let you perform rolling updates of ReplicaSets, where Pods are rescheduled without any service downtime. The Pods and ReplicaSets are replaced individually, allowing old and new versions to briefly coexist.<\/p>\n<p>The need for Deployments arose out of Kubernetes\u2019 historical approach to replicas. ReplicaSets evolved out of <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/kubernetes.io\/docs\/concepts\/workloads\/controllers\/replicationcontroller\">Replication Controllers<\/a>. Replication Controllers offered functionality similar to ReplicaSets but with built-in scaling support.<\/p>\n<p>Replication Controllers did not offer declarative scaling though. You had to manually use <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/jamesdefabia.github.io\/docs\/user-guide\/kubectl\/kubectl_rolling-update\"><code>kubectl rolling-update<\/code><\/a> to scale the replicas without downtime. This was at odds with the declarative manifest-based approach of other Kubernetes resources.<\/p>\n<p>Compared to ReplicaSets, the primary advantage of Deployments is their support for rolling updates. Changing the number of replicas in a ReplicaSet does not guarantee any number of Pods will remain in any given state during the rollout. With a Deployment, you can be sure your application will continue handling traffic, even if the Deployment hasn\u2019t yet completed.<\/p>\n<p>Today, Kubernetes advises using Deployments to represent your workloads. Your Deployments will run and scale ReplicaSets automatically; ReplicaSets will in turn manage your Pods. You can perform a rolling update of a Deployment by updating the <code>replicas<\/code> field in its manifest. Kubernetes will then ensure your application remains available throughout the change, allowing new and old Pods to temporarily co-exist.<\/p>\n<div class=\"wp-geshi-highlight-wrap5\">\n<div class=\"wp-geshi-highlight-wrap4\">\n<div class=\"wp-geshi-highlight-wrap3\">\n<div class=\"wp-geshi-highlight-wrap2\">\n<div class=\"wp-geshi-highlight-wrap\">\n<div class=\"wp-geshi-highlight\">\n<div class=\"yaml\">\n<pre class=\"de1\"><span class=\"co3\">apiVersion<\/span><span class=\"sy2\">: <\/span>apps\/v1<span class=\"co3\">\nkind<\/span><span class=\"sy2\">: <\/span>Deployment<span class=\"co4\">\nmetadata<\/span>:<span class=\"co3\">\n  name<\/span><span class=\"sy2\">: <\/span>my-deployment<span class=\"co4\">\n  labels<\/span>:<span class=\"co3\">\n    my-label<\/span><span class=\"sy2\">: <\/span>my-value<span class=\"co4\">\nspec<\/span>:<span class=\"co3\">\n  replicas<\/span><span class=\"sy2\">: <\/span>3<span class=\"co4\">\n  selector<\/span>:<span class=\"co4\">\n    matchLabels<\/span>:<span class=\"co3\">\n      my-label<\/span><span class=\"sy2\">: <\/span>my-value<span class=\"co4\">\n  template<\/span>:<span class=\"co4\">\n    metadata<\/span>:<span class=\"co4\">\n      labels<\/span>:<span class=\"co3\">\n        my-label<\/span><span class=\"sy2\">: <\/span>my-value<span class=\"co4\">\n    spec<\/span>:<span class=\"co4\">\n      containers<\/span>:<span class=\"co3\">\n        - name<\/span><span class=\"sy2\">: <\/span>app-container<span class=\"co3\">\n          image<\/span><span class=\"sy2\">: <\/span>my-image:latest<\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<p>The manifest above would create a Deployment consisting of three replicas, each running the <code>my-image:latest<\/code> container image. Changing the <code>replicas<\/code> value would trigger a rolling update of the underlying ReplicaSets and Pods.<\/p>\n<h2 id=\"other-kinds-of-resource\"><span class=\"ez-toc-section\" id=\"Other_Kinds_of_Resource\"><\/span>Other Kinds of Resource<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>The three types of resource we\u2019ve looked at are the most common objects you\u2019ll encounter when working with Kubernetes. They are used to configure your application\u2019s workloads and manage your containers.<\/p>\n<p>You\u2019ll need to use other kinds of resource type as you work more with Kubernetes. <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/kubernetes.io\/docs\/concepts\/configuration\/configmap\">ConfigMaps<\/a> and <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/kubernetes.io\/docs\/concepts\/configuration\/secret\">Secrets<\/a> let you inject configuration into your Pods, enabling them to access outside values. <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/kubernetes.io\/docs\/concepts\/storage\/volumes\">Volumes<\/a> and <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/kubernetes.io\/docs\/concepts\/storage\/persistent-volumes\">Persistent Volumes<\/a> provide Pods with a shared writable filesystem that can be used to store data, instead of the default ephemeral storage that\u2019s lost when the Pod exits.<\/p>\n<p>A further set of resources help to manage your workload\u2019s networking options. <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/kubernetes.io\/docs\/concepts\/services-networking\/service\">Services<\/a> allow you to expose a set of Pods as a single network service with one IP address. <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/kubernetes.io\/docs\/concepts\/services-networking\/ingress\">Ingresses<\/a> let you expose services externally. They route traffic into your cluster to a destination service based on attributes like hostname, port and URL path.<\/p>\n<p>Finally, there\u2019s meta-resources that describe your cluster. Namespaces are used to isolate individual workloads, preventing name collisions. You should usually create a new namespace for each of your independent workloads. Nodes are a kind of resource which represent the physical machines running your Pods. Each Node will usually host multiple Pods. Kubernetes works out how to schedule workloads based on the availability of each Node and the constraints you enforce.<\/p>\n<p>You can view the full resource list for your cluster by running <code>kubectl api-resources<\/code>. In addition to the built-in resources, workloads can add their own Custom Resource Definitions (CRDs) which let you create new kinds of object. Kubernetes automatically provides API endpoints for Custom Resource Definitions.<\/p>\n<h2 id=\"conclusion\"><span class=\"ez-toc-section\" id=\"Conclusion\"><\/span>Conclusion<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Learning Kubernetes means getting acquainted with new abstractions and terminologies. While this makes for a broad API surface area, each Kubernetes object has a relatively narrow purpose.<\/p>\n<p>You\u2019ll often be able to stick with the high-level abstractions such as Deployments. You shouldn\u2019t need to micro-manage fundamental resource types, like Pods, unless you have complex requirements that can\u2019t be solved with Deployments and ReplicaSets alone.\n<\/p><\/div>\n<blockquote><p><strong><span style=\"color: #ff6600;\">If you liked the article, do not forget to share it with your friends. Follow us on\u00a0<span style=\"color: #ff0000;\"><a style=\"color: #ff0000;\" href=\"https:\/\/news.google.com\/publications\/CAAqBwgKMLG0nwswvr63Aw\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Google News<\/a><\/span>\u00a0too, click on the star and choose us from your favorites.<\/span><\/strong><\/p><\/blockquote>\n<blockquote>\n<p style=\"text-align: center;\">For forums sites go to <span style=\"color: #ff9900;\"><a style=\"color: #ff9900;\" href=\"https:\/\/forum.buradabiliyorum.com\/\" target=\"_blank\" rel=\"noopener\">Forum.BuradaBiliyorum.Com<\/a><\/span><\/strong><\/p>\n<\/blockquote>\n<blockquote>\n<p style=\"text-align: center;\"><strong>If you want to read more like this article, you can visit our <span style=\"color: #ff9900;\"><a style=\"color: #ff9900;\" href=\"https:\/\/en.buradabiliyorum.com\/technology\/\" target=\"_blank\" rel=\"noopener\">Technology category.<\/a><\/span><\/strong><\/p>\n<\/blockquote>\n<p><span style=\"color: black;\"><a style=\"color: #ff9900;\" href=\"https:\/\/www.cloudsavvyit.com\/10107\/pods-deployments-and-replica-sets-kubernetes-resources-explained\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>&#8220;#Kubernetes Resources Explained \u2013 CloudSavvy IT&#8221; Kubernetes is not known for being approachable. To master Kubernetes, you need to understand how its abstractions fit together. Kubernetes comes with dozens of resource types which you can use within your applications. Let\u2019s look at the roles of the most frequently used resources. Pods If there\u2019s one Kubernetes&#8230;<\/p>\n","protected":false},"author":1,"featured_media":219325,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"fifu_image_url":"https:\/\/www.cloudsavvyit.com\/p\/uploads\/2021\/02\/748108a6.jpg","fifu_image_alt":"","footnotes":""},"categories":[18],"tags":[],"class_list":["post-219324","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-technology"],"_links":{"self":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/posts\/219324","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/comments?post=219324"}],"version-history":[{"count":0,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/posts\/219324\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/media\/219325"}],"wp:attachment":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/media?parent=219324"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/categories?post=219324"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/tags?post=219324"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}