<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: wiggitywhitney</title>
    <description>The latest articles on DEV Community by wiggitywhitney (@wiggitywhitney).</description>
    <link>https://dev.to/wiggitywhitney</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F242708%2Fc6a0eabb-8b52-45ae-83d0-671062334b70.png</url>
      <title>DEV Community: wiggitywhitney</title>
      <link>https://dev.to/wiggitywhitney</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/wiggitywhitney"/>
    <language>en</language>
    <item>
      <title>٩( ᐛ )و What is Knative Serving? A Friendly Guide</title>
      <dc:creator>wiggitywhitney</dc:creator>
      <pubDate>Mon, 31 Jan 2022 21:37:42 +0000</pubDate>
      <link>https://dev.to/wiggitywhitney/9-waa-w-what-is-knative-serving-a-friendly-guide-28f6</link>
      <guid>https://dev.to/wiggitywhitney/9-waa-w-what-is-knative-serving-a-friendly-guide-28f6</guid>
      <description>&lt;p&gt;Although Knative has been community-maintained since 2018, there has been buzz around the project lately because &lt;a href="https://knative.dev/blog/steering/knative-cncf-donation/" rel="noopener noreferrer"&gt;Google has recently submitted Knative to the Cloud Native Computing Foundation&lt;/a&gt; (CNCF) for consideration as an incubating project.&lt;/p&gt;

&lt;p&gt;Cool! But what is Knative, exactly?&lt;/p&gt;

&lt;p&gt;Simply put, Knative is a technology that &lt;strong&gt;simplifies&lt;/strong&gt; and &lt;strong&gt;enhances&lt;/strong&gt; the way that applications run on Kubernetes. Knative itself runs on Kubernetes and has two main facets: Knative Serving and Knative Eventing. This article is about Knative Serving.  &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2egl13zn35nybn4jonz9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2egl13zn35nybn4jonz9.png" alt="Image1"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Vanilla Kubernetes is complicated
&lt;/h2&gt;

&lt;p&gt;How does Knative simplify the process of running an application on Kubernetes? To understand that, you must first understand this: &lt;strong&gt;deploying an application on vanilla Kubernetes is complex&lt;/strong&gt;. You first make a &lt;em&gt;deployment&lt;/em&gt;, which eventually manages many &lt;em&gt;ReplicaSets&lt;/em&gt; (one for each version of your application), and each ReplicaSet runs one or many &lt;em&gt;pods&lt;/em&gt;, which is where your application containers run, usually one workload container per pod.  &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fi4f04m2rczb2xy7qwr4o.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fi4f04m2rczb2xy7qwr4o.png" alt="Image2"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;But then you also need to create a &lt;em&gt;service&lt;/em&gt; to expose your application internally to the cluster (so that other parts of your application can access it), and an &lt;em&gt;ingress&lt;/em&gt; to make your application available outside of the cluster (so that the end user can access it). If you want autoscaling, you need to make a &lt;em&gt;HorizontalPodAutoscaler&lt;/em&gt; (HPA). You also need to manage your configuration and secrets separately from your application.  &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzou81yts471jhw4nv0s3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzou81yts471jhw4nv0s3.png" alt="Image3"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;That is a lot to consider. And it can be a high barrier of entry for developers—developers who should be spending their time writing application code anyway.  &lt;/p&gt;

&lt;p&gt;Enter Knative.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fd3alcm3sl4zakgc7l4b2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fd3alcm3sl4zakgc7l4b2.png" alt="Image4"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;With Knative, you need to make only one resource—a Knative Service—and then Knative reconciles a set of resources for you that accomplishes everything that we went over in the Kubernetes example above! In addition, defaults are set in such a way that you can run your application and access it externally with one command (or one applied YAML) right out of the box.  &lt;/p&gt;

&lt;h2&gt;
  
  
  Knative simplifies application deployment
&lt;/h2&gt;

&lt;p&gt;How does it work?&lt;/p&gt;

&lt;p&gt;&lt;code&gt;kn service create sunshine –image=rainbows&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Run the &lt;strong&gt;kn service create&lt;/strong&gt; command*, supply your application name, application image, and any configuration (environment variables, preferred ports, that sort of thing), and Knative will create for you a Knative Service**.  &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F10fzzzr7smbdmh5620c6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F10fzzzr7smbdmh5620c6.png" alt="Image6"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The Knative Service automatically creates a &lt;em&gt;configuration&lt;/em&gt; and a &lt;em&gt;route&lt;/em&gt; for your Service. The Configuration manages a stream of &lt;em&gt;revisions&lt;/em&gt;, and each revision is associated with a Kubernetes deployment and a &lt;em&gt;Knative Pod Autoscaler (KPA).&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9fsnnin7b2o0rxmu3pia.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9fsnnin7b2o0rxmu3pia.png" alt="Image7"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I will explain what each of these components is momentarily. But for now I want you to know two things:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;When you run the &lt;strong&gt;kn service create&lt;/strong&gt; command, all of these objects are created for you, and the command returns to you a URL where you can access your running application. It is that easy.
&lt;/li&gt;
&lt;li&gt;You can view, access, and manipulate all of these Knative resources in your Kubernetes cluster, in addition to the Kubernetes resources that underpin the Knative ones. Knative builds on top of Kubernetes, but it does not obscure it.
&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Knative scales to zero
&lt;/h2&gt;

&lt;p&gt;How does traffic move through these Knative abstractions to get to the running application in the Kubernetes Deployment?&lt;/p&gt;

&lt;p&gt;At this point, our system has only one Revision so it moves through like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhxmhpvzdiyj2e6azdai1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhxmhpvzdiyj2e6azdai1.png" alt="Image8"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Traffic comes into the cluster via the Knative Route. By default the Route sends 100 percent of the traffic to the latest revision, but this is configurable, as we discuss later in this article.  &lt;/p&gt;

&lt;p&gt;The Knative Pod Autoscaler (KPA) is watching the number of requests that are received to the Revision and will automatically scale the number of pods in the Kubernetes Deployment up and down as needed. (Again, I’ll dig in on what revisions are here in a bit).  &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsnlucjcje503yxc3mu8i.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsnlucjcje503yxc3mu8i.png" alt="Image9"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And then check this out: when there is no traffic going to your application, Knative scales the number of pods to zero. That’s right! Unlike Kubernetes, where you need at least one instance of a pod up and running at all times in order to serve an application, Knative can &lt;strong&gt;scale to zero&lt;/strong&gt;***. Then, when a client makes a request to access your application, that is when Knative starts actually running the application Pod. Impressive! This can save a lot of money that is wasted on keeping pods of seldom-used applications running every hour, every day, every year.  &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2ic2qww6qwhyl27fg97u.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2ic2qww6qwhyl27fg97u.png" alt="Image10"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Tidier release management with Knative revisions
&lt;/h2&gt;

&lt;p&gt;As I mentioned earlier, the Knative Configuration object manages a stream of revisions. What is a Knative revision? A revision is a &lt;strong&gt;snapshot in time&lt;/strong&gt; of your current code and configuration, containing all of the information needed to run that particular version of your application. This is different (and in my humble opinion, superior) to how Kubernetes manages configuration, separately from source code.  &lt;/p&gt;

&lt;p&gt;You want to upgrade your application to use the latest container image? Bam! Knative makes a new revision. Now you want to update your application’s configuration? Bam! New revision. These revisions are ordered, immutable, and can persist indefinitely.  &lt;/p&gt;

&lt;h3&gt;
  
  
  Traffic splitting
&lt;/h3&gt;

&lt;p&gt;Managing your releases using revisions has two major benefits. First, you can easily split traffic between revisions. This is especially useful when rolling out a new release. Say you currently have 100 percent of traffic going to Revision 2 and you are ready to upgrade to a newer version, Revision 3. At first, you can send a small amount of traffic to Revision 3, say 10 percent. Then you run some user tests, feel more confident, and now send 20 percent of your traffic to the new application. You can continue in this manner until 100 percent of traffic is going to Revision 3, and 0 percent to Revision 2.  &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhjwn3cv55ka7csojkp11.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhjwn3cv55ka7csojkp11.png" alt="Image11"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Rollbacks
&lt;/h3&gt;

&lt;p&gt;The second major benefit to revisions is rollbacks. Since a Knative revision represents a snapshot in time, you have the ability to jump back to any version of your application that you please. If you find out that one of your application dependencies has a vulnerability, you can direct traffic back to the most recent revision that doesn’t use that dependency—even if that vulnerability got introduced last year and there have been 20 releases since then. Sure, with Kubernetes you can roll back too, but with Kubernetes the rollbacks can be complex. It is a hard problem to track the configuration associated with each release, and rolling back more than one or two cycles can be especially difficult.  &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyodh8ncrnc0vvja42r3p.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyodh8ncrnc0vvja42r3p.png" alt="Image12"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Knative gives fine-grained control over routes and access
&lt;/h2&gt;

&lt;p&gt;What’s more, using Knative’s Route abstraction, you can set up routes to give internal access to revisions that are completely experimental and not meant to ever be exposed to the public.  You can set up a site and an internal route to do tests on different UI patterns, or to gauge the feasibility of a radical new idea. The Knative Route component gives you fine-grained control over routes and access.  &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fi1n4rxq769vqgjk47n5v.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fi1n4rxq769vqgjk47n5v.png" alt="Image13"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In summary, here are the many benefits of Knative Serving:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Ease of deployment&lt;/li&gt;
&lt;li&gt;Scale to zero&lt;/li&gt;
&lt;li&gt;Traffic splitting&lt;/li&gt;
&lt;li&gt;Rollbacks&lt;/li&gt;
&lt;li&gt;Routes and access&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Want to learn more? Get your hands dirty and play with Knative Serving in a &lt;a href="https://knative.dev/docs/getting-started/" rel="noopener noreferrer"&gt;Knative Quickstart&lt;/a&gt; environment on your local machine! Or learn &lt;a href="https://tanzu.vmware.com/content/ebooks/knative-fundamentals" rel="noopener noreferrer"&gt;Knative Fundamentals&lt;/a&gt; from Jacques Chester’s book, &lt;em&gt;Knative in Action&lt;/em&gt;! Or both!&lt;/p&gt;

&lt;p&gt;(◠‿·)—☆ &lt;/p&gt;

&lt;p&gt;* Or you can do this declaratively by supplying a Knative Service definition YAML file to your cluster with the &lt;strong&gt;kubectl apply&lt;/strong&gt; command.&lt;/p&gt;

&lt;p&gt;** The Knative Service is a totally different abstraction than a Kubernetes Service. Not understanding this distinction personally tripped me up for a good hot minute.&lt;/p&gt;

&lt;p&gt;*** This concept can also be called &lt;strong&gt;serverless&lt;/strong&gt;, which is a loaded and confusing term, and why I am relegating it to the lowly footnotes.&lt;/p&gt;

&lt;p&gt;This post first appeared &lt;a href="https://tanzu.vmware.com/developer/guides/knative-serving-wi/" rel="noopener noreferrer"&gt;here&lt;/a&gt; in VMware Tanzu Developer Center.&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>kubernetes</category>
      <category>knative</category>
      <category>cloud</category>
    </item>
  </channel>
</rss>
