095 Chapter 16 Deploying serverless applications with Knative
About this lesson
Watch 095 Chapter 16 Deploying serverless applications with Knative by Antonio. This content is being analysed by DeepCamp AI to generate a detailed summary.
Full Transcript
section 16.3 deploying serverless applications with K native in the previous sections you learned about spring native and how to use it with spring Cloud function to build serverless applications this section will guide you through deploying quote function to a serverless platform on top of kubernetes using the K native project native is a kubernetes-based platform to deploy and manage modern serverless workloads K native. deev it's a cncf project that you can use to deploy standard containerized workloads and event-driven applications the project offers a superior user experience to developers and higher abstractions that make it simpler to deploy applications on kubernetes you can decide to run your own K native platform on top of a kubernetes cluster or choose a managed service offered by a cloud provider such as VMware tanzoo application platform Google Cloud run or red hat open shift serverless since they are all based on open source soft software and standards you could migrate from Google Cloud run to VMware tanzoo application platform without changing your application code and with minimal changes to your deployment pipeline the K native project consists of two main components serving and Eventing K native serving is for running serverless workloads on kubernetes it takes care of autoscaling networking revisions and deployment strategies while letting Engineers focus on the application business logic k native Eventing provides management for integrating applications with event sources and syncs based on the cloud event specification abstracting back ends like rabbit mq or Kafka our Focus will be on using K native serving to run serverless workloads while avoiding vendor lockin note originally K native consisted of a third component called build that subsequently became a standalone product renamed tekon tekon dodev and donated to the continuous delivery Foundation cd. Foundation tekon is a kubernetes native framework for building deployment pipelines that support continuous delivery for example you could use tektin instead of GitHub actions this section will show you how to set up a local development environment comprising both kubernetes and K native then I'll introduce native manifests which you can use to declare the desired state for serverless applications and I'll show you how to apply them to a kubernetes cluster section 16.3 .1 setting up a local K native platform since native runs on top of kubernetes we first need a cluster let's create one with mini Cube following the same approach we've used throughout the book open a terminal window and run the following command see this code next we can install K native for Simplicity I have collected the necessary commands in a script that you'll find in the source code repository accompanying the book from the chapter 16/6 16 end polar deployment kubernetes development folder copy the install native. file to the same path in your polar deployment repository polar deployment then open a terminal window navigate to the folder where you just copied the script and run the following command to install K native on your local kubernetes cluster see this code feel free to open the file and look at the instructions before running it you can find more information about installing native on the project website see this link note on Mac OS and Linux you might need to make the script executable via the hmod plus X install K native. sh command the K native project provides a convenient CLI tool that you can use to interact with K native resources in a kubernetes cluster you can find instructions on how to install it in section a.4 of appendex a in the next section I'll show you how to deploy quote function using the K native CLI section 16.3 point2 deploying applications with the K native CLI K native provides a few different options for deploying applications in production we'll want to stick to a declarative configuration as we did for standard kubernetes deployments and rely on a gitops flow to reconcile the desired state in a git repository and actual state in the kubernetes cluster when experimenting or working locally we can also take advantage of the K native CLI to deploy applications in an imperative way from a terminal window run the following command to deploy quote function the container image is the one published by the commit stage workflow we defined before remember to replace your uncore GitHub username with your GitHub username in lowercase see this code you can refer to figure 16.3 for a description of the command figure 16.3 the K native command for creating a service from a container image K native will take care of creating all the resources necessary to deploy the applications on kubernetes the command will initialize a new quote function service in the default namespace on kubernetes it will return the public URL through which the application is exposed in a message like the following see this code Let's test it out first we need to open a tunnel to the cluster with mini Cube the first time you run this command you might be asked to input your machine password to authorize the tunneling to the cluster see this code then open a new terminal window and call the application at the root endpoint to fetch the complete list of quotes the URL to call is the same one returned by the previous command this which is in the format service name namespace domain see this code since we are working locally I configured native to use SS lip. a DNS service that when queried with a host name with an embedded IP address returns that IP address for example the 127.0.0.1 SS lip. host name would be resolved to the 127.0.0.1 IP address since we opened a tunnel to the cluster request to 127.0.0.1 will be handled by the cluster where K native will rout them to the right service K na takes care of scaling the application without any further configuration for each request it determines whether more instances are required when an instance stays idle for a specific time period 30 seconds by default K native will shut it down if no request is received for more than 30 seconds K native will scale the application to zero meaning there will be no instances of quote function running when a new request is eventually received K native starts a new instance and uses it to handle the request thanks to Spring native the startup time of quote function is almost instantaneous so users and clients won't have to deal with long wait times as would be the case with standard jvm applications this powerful feature lets you optimize costs and pay only for what you use and need using an open source platform like K native has the advantage of letting you migrate your applications to another cloud provider without any code changes but that's not all you can even use the same deployment pipeline as is or with minor modifications the next section will show you how to define K native services in a declarative way VIA yaml manifests which is the recommended approach for production scenarios before moving on make sure you have deleted the quote function instance you created previously see this code section 16.3 point3 deploying applications with the K native manifests kubernetes is an extensible system besides using built-in objects like deployments and pods we can Define our own objects via custom resource definitions crds that is the strategy used by many tools built on top of kubernetes including K native one of the benefits of using K native is a better developer experience and the possibility to declare the desired state for our applications in a more straightforward and less verbose way rather than dealing with deployments services and ingresses we can work with a single type of resource the K native service note throughout the book I talked about applications as Services K native offers a way to model an application in a single resource declaration the K native service at First the naming might not be very clear since there is already a kubernetes built-in service type in reality the K native choice is very intuitive because it Maps one to one the architectural concept with the deployment concept let's see what K native Services look like open your quote function project quote function and create a new K native folder then Define a new K service. yml file inside to declare the desired state of the K native service for quote function remember to replace your uncore GitHub uncore username with your GitHub username in lowercase listing 16.13 K native service manifest for quote function like any other kubernetes resource you can apply a k native service manifest to a cluster with Cube CTL apply F manifest file or through an automated flow like we did with Argo CD in the previous chapter for this example we'll use the kubernetes CLI open a terminal window navigate to your quote function project quote function and run the following command to deploy quote function from the K native service manifest see this code using the kubernetes CLI you can get information about all the created K native services and their URLs by running the following command the result displayed is partial to fit on the page see this code let's verify that the application is correctly deployed by sending an HTTP request to its root endpoint if the tunnel you opened earlier is not active anymore run mini Cube tunnel d-profile K native before calling the application see this code native provides an abstraction on top of kubernetes however it still runs deployments replica sets pods services and ingresses under the hood this means you can use all the techniques you learned in the previous chapters for example you can configure quote function through config maps and secrets see this code if you wait for 30 seconds and then check for the running pods in your local kubernetes cluster you'll see there are none because K native scaled the application to zero due to inactivity see this code now try sending a new request to the application on HTTP quote function. default1 127.0.0.1 slip. native will immediately spin up a new pod for quote function to answer the request see this code when you're done testing the application you can remove it with Cube CTL delete FK native service. yml finally you can stop and delete the local cluster with the following command and see this code the K native service resource represents an application service in its entirety thanks to this abstraction we no longer need to deal directly with deployment services and ingresses K native takes care of all that it creates and manages them under the hood while freeing us from dealing with those lower level resources provided by kubernetes by default K native can even expose an application outside the cluster without the need to configure an Ingress resource providing you directly with a URL to call the application thanks to its features focused on developer experience and productivity K native can be used to run and manage any kind of workload on kubernetes limiting its scale to zero functionality only to the applications that provide support for it for example using spring native we could easily run the entire polar Bookshop system on K native we could use the this link annotation to Mark the applications we don't want to be scaled to zero see this code K native offers such a great developer experience that it's becoming the deao abstraction when deploying workloads on kubernetes not only for serverless but also for more standard containerized applications whenever I provision a new kubernetes cluster K native is the first thing I install it's also a foundational part of platforms like tanzo Community Edition tanzo application platform Red Hat open shift and Google Cloud run note tanzo Community Edition tanzu Community edition. is a kubernetes platform that provides a great developer experience on top of K native it's open source and free to use another great feature offered by K native is an intuitive and developer friendly option for adopting deployment strategies like blue green deployments Canary deployments or AB deployments all via the same K native service resource implementing those strategies in plain kubernetes would require a lot of manual work instead native supports them out of the box note to get more information about serverless applications and K native you can refer to the official documentation K native. deev also I recommend checking out a couple of books from the Manning catalog on this subject K native in action by jacqu Chester Manning 2021 see this link and continuous delivery for kubernetes by Mauricio salatino see this link po Labs feel free to apply what you learned in the last sections to quote service one Define a commit stage workflow including the steps for compiling and testing the application as a native executable two push your changes to GitHub and ensure that the workflow completes successfully and publishes a container image for your application three deploy quote service on kubernetes Via the K native CLI four deploy quote service on on kubernetes Via the kubernetes CLI from a native service manifest you can refer to the chapter 166n folder in the code repository accompanying the book to check the final result see this link
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
🎓
Tutor Explanation
DeepCamp AI