<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Boris Sobolev on Medium]]></title>
        <description><![CDATA[Stories by Boris Sobolev on Medium]]></description>
        <link>https://medium.com/@bsobolev?source=rss-2942f3d02a77------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*96cK9tsCcwEvWHXm</url>
            <title>Stories by Boris Sobolev on Medium</title>
            <link>https://medium.com/@bsobolev?source=rss-2942f3d02a77------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 09:34:24 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@bsobolev/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Serverless Services with Knative: Complex Application migration experience]]></title>
            <link>https://medium.com/@bsobolev/serverless-services-with-knative-complex-application-migration-experience-92f35c62c0de?source=rss-2942f3d02a77------2</link>
            <guid isPermaLink="false">https://medium.com/p/92f35c62c0de</guid>
            <category><![CDATA[knative]]></category>
            <category><![CDATA[microservices]]></category>
            <category><![CDATA[serverless]]></category>
            <category><![CDATA[instana]]></category>
            <category><![CDATA[modernization]]></category>
            <dc:creator><![CDATA[Boris Sobolev]]></dc:creator>
            <pubDate>Mon, 14 Aug 2023 21:15:21 GMT</pubDate>
            <atom:updated>2023-08-14T21:15:21.161Z</atom:updated>
            <content:encoded><![CDATA[<p>Serverless is an often overloaded term. Some define it as “a way to deploy applications without worrying about provisioning any infrastructure”. Actually, that’s what Heroku did back in 2011, and Cloud Foundry later built on top of it. It’s called Platform as a Service and we’ve been able to ask for a Ruby, Java, or Python environment to deploy our cloud-native applications without any thoughts about the infrastructure for 12 years now.</p><p>The new thing about serverless is its ability to scale to zero. Platforms like Kubernetes can dynamically scale containers but they only scale down to one instance. Initially, serverless was introduced as Functions as a Service which are individual functions that are only run when they are called upon. This placed a huge burden on developers to decompose their applications into single functions which is not always desirable. In addition, there is no serverless standard and each cloud provides implemented their own proprietary service forcing vendor lock-in. Open-source serverless platforms like Knative enable serverless for Kubernetes clusters.</p><p>At its foundation, Knative provides a set of higher-level abstractions for deploying and managing serverless workloads on Kubernetes. With Knative Serving, developers can easily deploy and manage serverless applications without worrying about the underlying infrastructure. It also provides built-in auto-scaling, routing, and revision management, making it easier to handle traffic spikes and implement canary deployments.</p><p>This got us thinking about the implications of applying this technique to application modernization efforts that were decomposing monoliths and breaking them into microservices. Why not break them into serverless microservices? Which raises the question, “When would that be a good idea?”</p><p>In this post, we explore the migration process for complex applications and provide an approach to make it more efficient.</p><h3>The Candidate Application</h3><p>One of the downsides of serverless is known as “cold start” time. This is the time it takes for a microservice to start up from zero and be ready to service a request. In Kubernetes, this can be determined by the <em>ReadinessProbe</em>. Cold start is not the same for every programming language. Interpreted languages like JavaScript, Python, and Ruby start up quickly. While byte compiled languages like Java need a runtime to be brought up first causing significant delays in startup as the Java Virtual Machine (JVM) must be started before the application can be run. We needed an application that was a polyglot of microservices so that we could measure multiple languages and compare them.</p><p>We chose <strong>Stan’s robot-shop </strong>demo from <strong>Instana</strong> as an example microservices-based application because it features multiple services written in different languages and is a microservices-based application to start with. Secondly, it simulates a realistic e-commerce scenario, where customers can browse, order, and pay for items, allowing developers to gain insight into real-world use cases. Thirdly, it is open-source and freely available, allowing developers to easily experiment with different architectures and configurations. Lastly, the use of Robot-Shop in combination with Instana provides a comprehensive solution for monitoring and troubleshooting serverless applications so that we can measure the arrival time, latency, CPU, and memory utilization before and after conversion.</p><figure><img alt="Screenshot of robot-shop Application deployment before the migration" src="https://cdn-images-1.medium.com/max/1024/1*HnuhNdv7kPvAGfvWEqxRXg.png" /></figure><h3>Setting up the environment</h3><p>We chose to deploy Robot-Shop on an OpenShift Kubernetes cluster. One of the ways to install Knative is to use operators which includes the Kourier ingress. OpenShift has operator hub integration built in so you can select Operator from the left menu and search for “serverless”. Then click on the <strong>Red Hat OpenShift Serverless</strong> panel so select it and press the Install button to install it. This will install Knative Service, Knative Eventing, and Knative Kafka. You can also go to <a href="https://operatorhub.io/">https://operatorhub.io</a>, search for “serverless” and select the <strong>Knative Operator (</strong><a href="https://operatorhub.io/operator/knative-operator">https://operatorhub.io/operator/knative-operator</a><strong>),</strong> click on Install and it will give you the commands to manually install the operator.</p><pre>curl -sL https://github.com/operator-framework/operator-lifecycle-manager/releases/download/v0.24.0/install.sh | bash -s v0.24.0<br>kubectl create -f https://operatorhub.io/install/knative-operator.yaml</pre><p>To install robot-shop on the cluster, we followed the instructions <a href="https://ibm.github.io/waiops-tech-jam/labs/instana/robot-shop-installation/">https://ibm.github.io/waiops-tech-jam/labs/instana/robot-shop-installation/</a></p><p>These are the steps that we took to implement the conversion. They form the structure for the remainder of this article.</p><p>For <strong>each service</strong> that you decide to convert:</p><blockquote>1. Change API version to Knative</blockquote><blockquote>2. Remove all attributes not supported by Knative</blockquote><blockquote>3. Set visibility to cluster.local so the services can be discoverable by other services</blockquote><blockquote>4. Modify the address to have a .cluster.local extension (for services that require internal communication)</blockquote><blockquote>5. Remove the deployment files</blockquote><blockquote>6. Knative defaults to port 80, change the deployment files to it</blockquote><blockquote>7. Make sure there are no hardcoded port references</blockquote><blockquote>8. Disable scaling down to zero and test the new deployement</blockquote><h3>Converting the code</h3><p>Our modernization strategy was to convert microservices one by one and test the application after each step. The <em>robot-shop</em> is deployed using a helm chart, so our initial assumption was that we would introduce several minor changes to the deployment artifacts, and the application should continue to work. We picked the <strong>ratings</strong> service as our first service because it is less dependent on other services.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dqwsHh-aO1_zp-0p2X2Plg.png" /></figure><p>The observability platform allows us to inspect the dependencies and figure out how other services can be affected by new changes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*th-26rd2W67GyAQFFIrw2g.png" /></figure><p>We were hoping that Robot-shop followed good 12-Factor principles that guide the creation of cloud-native microservices. For the most part, it did, but where it didn’t become problematic. Here is what we encountered:</p><h3>Change API version to Knative</h3><p>Unlike regular Kubernetes deployments that have a Deployment resource definition and a Service resource definition, Knative describes the serverless service in a single Service resource definition. The first task was to remove the <em>deployment.yaml </em>file and <em>service.yaml</em> files and combine them into a single Knative service <em>serverless.yaml</em> file.</p><p>This turned out to be harder than it looked. Knative serverless serving doesn’t support all of the Kubernetes pod specs so we had to decide what to do with unsupported yaml tags.</p><p>For reference, this is the list Kubernetess PodSpec attributes not supported by Knative Service:<br><em>InitContainers, RestartPolicy, TerminationGracePeriod-<br>Seconds, ActiveDeadlineSeconds, DNSPolicy, NodeSelector,<br>AutomountServiceAccountToken, NodeName, HostNetwork,<br>HostPID, HostIPC, ShareProcessNamespace, SecurityContext, Hostname, Subdomain, Affinity, SchedulerName, Tolerations, HostAliases, PriorityClassName, Priority, DNSConfig, ReadinessGates, RuntimeClassNam</em></p><p>For some reason, the Instana agent need to know the IP address of the pod it was running in. The following environment variable was defined in the <em>deployment.yaml</em> file of several microservices which is not supported so we had to remove them:</p><pre>env:<br>    - name: INSTANA_AGENT_HOST<br>      valueFrom:<br>      fieldRef:<br>          fieldPath: status.hostIP</pre><h3>Visibility changes</h3><p>Knative services are defined to be called from outside the cluster by default. This means that the other microservices could no longer call the knative service by name as you can with regular Kubernetes services. We had to make two changes. The first was to change the visibility of each service using the metadata label <em>networking.knative.dev/visibility</em>: set to: <em>cluster-local</em> like this:</p><pre>spec:<br>    template:<br>        metadata:<br>            labels:<br>                networking.knative.dev/visibility: cluster-local</pre><p>Next, we had to fully qualify the names of the service. Luckily the Dockerfile defined an environment variable for the DNS name of each microservice. For example, the Catalogue service host was defined in the environment variable: CATALOGUE_HOST. To fully qualify this name, we had to add the Kubernetes namespace and the qualifier: svc.cluster.local. The yaml can be seen below.</p><pre> - name: CATALOGUE_HOST<br>       value: {{ .Values.host.CATALOGUE_HOST }}.{{ .Release.Namespace }}.svc.cluster.local</pre><h3>Port binding</h3><p>12 Factor guideline VII. Port binding: Export services via port binding. Typically this is accomplished by specifying the port in an environment variable that the application can pick up. Unfortunately, this was not done consistently and some services actually had the port hard-coded in the application. Obviously, this required additional coding to remove this restriction.</p><p>We found that the `web/default.conf.template` file had hardcoded port `8080` for every service. This required us to change the template and rebuild the image each time we converted one of the microservices to serverless.</p><p>There was an additional problem in that most microservices can listen on any port. Knative serverless services can only listen on port 80. This is because you never actually talk to the service. You talk to a proxy listening on port 80 that will bring up the service if it has scaled to zero. The services themselves can listen on any port but to other services, they all looked as if they were listening on port 80 (the proxy port). This was another thing that needed to be changed in the deployment descriptors that had most services configured to listen on port 8080.</p><p>We opted to also create environment variables for the ports so many deployment artifacts needed new environment variables for the port, which also caused changes in some of the code (seen later). Below you can one example where see we had to introduce a CATALOGUE_PORT environment variable:</p><pre>env:<br>    - name: CATALOGUE_HOST<br>      value: {{ .Values.host.CATALOGUE_HOST }}.{{ .Release.Namespace }}.svc.cluster.local<br>    - name: CATALOGUE_PORT<br>      value: &quot;{{ .Values.host.CATALOGUE_PORT }}&quot;</pre><h3>Code Changes</h3><p>As mentioned earlier, some of the microservices have the ports of other services hard-coded like in the cart service which is written in Javascript. We had to introduce an environment variable for the port and change the request call that the cart makes to the catalog to use it.</p><p>From this:</p><pre>request(&#39;http://&#39; + catalogueHost + &#39;:8080/product/&#39; + sku, (err, res, body) =&gt; {</pre><p>To this:</p><pre>var cataloguePort = process.env.CATALOGUE_PORT || &#39;8080&#39;<br><br> . . . unchanged code here . . . <br><br>request(&#39;http://&#39; + catalogueHost + &#39;:&#39; + cataloguePort + &#39;/product/&#39; + sku, (err, res, body) =&gt; {</pre><p>The payment service also had some hard code ports which we removed as well. Had the developers followed 12-Factor guidelines all of these changes would have been unnecessary.</p><h3>Preventing Cold Starts</h3><p>Initially, we wanted to compare the microservice version with the serverless version without worrying about the cold start problem and unexpected behavior caused by scaling down to zero. In order to mitigate this behavior, we set <em>autoscaling.knative.dev/minScale</em>: to “1” in each of the service yaml files.</p><pre>spec:<br>    template:<br>        metadata:<br>            annotations:<br>                # the minimum number of pods to scale down to<br>                autoscaling.knative.dev/minScale: &quot;1&quot;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*M1348UCBpqDpSiW_GWmAGw.png" /></figure><h3>Evaluation</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fviAJSxh9X5-guzxt3n-sA.png" /></figure><p>In line with our migration strategy, we tested the performance of two versions of the application against the same workload and with the same resources provisioned. In order to rule out cold start overhead, and just evaluate the performance of the serverless platform, we disabled scaling down to zero. As a result of the migration, the Knative Serving version of the application displayed much lower CPU utilization. This is a result of the optimizations that Knative offered on top of the vanilla Kubernetes.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2F0IwysONytqc%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D0IwysONytqc&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2F0IwysONytqc%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/0a72a44722d0c3799c597885e617317f/href">https://medium.com/media/0a72a44722d0c3799c597885e617317f/href</a></iframe><h3>Conclusion and Next Steps</h3><p>After making all of the above changes, we finally got Stan’s Robot Shop to run under Knative serverless serving. What we learned is that converting a set of Kubernetes-based microservices to a serverless serving framework like Knative was not as easy as we first thought. While the migration process seems seamless, part of the impact was understanding the restrictions that Knative imposed. Other serverless solutions may have more or less restrictions. We also learned that strictly adhering to 12-factor guidelines would have made this transition much easier.</p><p>The main purpose of this article is to provide a framework to structure the process of migration. Enabling Scaling to Zero was left out of the scope due to the complexity of the topic: in order to yield benefits, it has to be properly configured.</p><p>In the context of Application Modernization, migration to a serverless platform seems like the next logical step for optimizing the cost of deployment at a relatively low upfront development investment. Furthermore, the current state of Large Language Models allows to think about supporting developers by automating the process of migration at scale.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=92f35c62c0de" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>