<?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 Ricardo A. on Medium]]></title>
        <description><![CDATA[Stories by Ricardo A. on Medium]]></description>
        <link>https://medium.com/@ricardoalkain?source=rss-db2bfdc09e85------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*ciihF9GyaGCOEY86zvusXg.jpeg</url>
            <title>Stories by Ricardo A. on Medium</title>
            <link>https://medium.com/@ricardoalkain?source=rss-db2bfdc09e85------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 12:30:00 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ricardoalkain/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[Azure Functions 2.0]]></title>
            <link>https://medium.com/@ricardoalkain/azure-functions-2-0-5a86aec7ea13?source=rss-db2bfdc09e85------2</link>
            <guid isPermaLink="false">https://medium.com/p/5a86aec7ea13</guid>
            <category><![CDATA[azure]]></category>
            <category><![CDATA[net-core-2]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[azure-functions]]></category>
            <category><![CDATA[software-engineering]]></category>
            <dc:creator><![CDATA[Ricardo A.]]></dc:creator>
            <pubDate>Wed, 04 Dec 2019 11:48:23 GMT</pubDate>
            <atom:updated>2019-12-04T11:48:23.485Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*n90sYbojd5c7RACb1Z6ANA.png" /></figure><p><strong>The .NET Core Way</strong></p><p>I think we can all agree that serverless concept is awesome and so it is Microsoft implementation of it: <strong>Azure Functions</strong>.</p><p>Of course they have their restrictions and caveats, like cold start and a limited amount of memory available. However for most of tasks, those are not really impediments and in the end some advantages like cost, auto-scaling and almost-zero infrastructure concerns make serverless apps a very good choice for a huge set of solutions.</p><p>Not long ago Microsoft introduced version 2.0, implemented on the top of .NET Core. In this article I will focus on this new version of Azure Functions and how it evolved from version 1.</p><h3>.NET Core: Cross-platform &amp; Performance</h3><p>When Microsoft released the first versions of Azure Functions they were basically a .NET Framework application running somewhere else and reacting to some triggers. This is still pretty much the same in version 2 with a key difference: they now run as a <strong>.NET Core </strong>application. I’m sure that for the ones whom already worked with .NET Core the advantages are quite clear.</p><p>The most visible advantage of using .NET Core as the underlying framework is the possibility to have your functions working not only on Windows but also in all supported platforms as MacOS and Linux. This brings to developers the option to chose where to develop and test their application. Another good side-effect is the performance, being a well known fact how faster .NET Core is compared to .NET Framework in many aspects.</p><p>The big difference here is the fact an Azure Functions project is a class library not an application, so it doesn’t have a Program class neither a Main function, the “start” is made under the covers by Azure, exactly like a class library being executed by an application. However it may have an optional <strong>Startup</strong> class, just like an application, where you can configure how your functions are gonna be initialized, especially regarding <strong>dependency injection </strong>configuration (we’ll talk more about DI in the next topic).</p><p>This class is slightly different than it is in a conventional .NET Core application. First, as we don’t have a Program class there’s not a <em>UseStartup </em>statement anywhere, thus <em>Startup </em>needs to have an annotation explicitly declaring it as the startup class using an assembly annotation where we pass the type of our class (because it really doesn’t need to be called <em>Startup</em>, you know). Finally, if you want to use DI, the class needs to be inherited from <em>Microsoft.Azure.Functions.Extensions.DependencyInjection.FunctionStartup</em>.</p><p>It should look something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/725/1*gQhnOncPeU9VOYWb-1dbzw.png" /><figcaption>Example of Startup class for Azure Functions 2.0</figcaption></figure><h3>Dependency Injection</h3><p>As expected, running as a .NET Core application also makes available all of its inherent functionalities, including the native <strong>dependency injection </strong>mechanism. Before version 2.0, DI wasn’t even officially supported by Azure Functions and many developers have implemented their own solution. But now dog days are over and we can rely on all advantages .NET Core DI.</p><p>As shown in the topic above, simply inherit your Startup class from <em>FunctionStartup</em>, override the Configure method and use <em>IFunctionHostBuilder </em>the same way you’d use <em>IServiceCollection </em>in a regular .NET Core application.</p><p><strong><em>Note:</em></strong><em> Remember though, the more dependencies your function have the longer will be your </em><a href="https://azure.microsoft.com/en-gb/blog/understanding-serverless-cold-start/"><em>function app cold start</em></a><em>.</em></p><h3>Languages</h3><p>Here we may have some limitations if compared to Azure Functions version 1, although I believe most of developers won’t ever notice:</p><ul><li>All functions inside a same function app need to be written using the same language. So if you create your app and choose C# you’ll need to stick with it. This is supposed to speed up app initialization minimizing the infamous <a href="https://azure.microsoft.com/en-gb/blog/understanding-serverless-cold-start/">function app cold start</a> (I really should write an article about this 🤔).</li><li>No more experimental languages. Say goodbye to Bash, Batch (.cmd) and PHP. F# is not supported anymore on the portal but you still can make your app using Visual Studio or VS Code and deploy the compiled version.</li><li>On the other hand, say hello to <strong>Java 8</strong>!</li></ul><h3>Packages and Features</h3><p>In order to increase performance, some bindings, triggers and features are not available out-of-the-box anymore. It means that depending on what your function reacts to or depends on, you’ll have to include and register the corresponding package, which is a very trivial task nowadays.</p><p>In practice, only HTTP and timing bindings are automatically added to a new function app. All the other bindings need to be included by the developer. This way only what is really used is loaded at runtime, which means a better decoupling. It also allows us to update the version of a binding independently of the rest and (again) to speedup function cold start.</p><h3>Conclusion</h3><p>It’s been a year since Azure Functions v2 has been released and available and it’s a big improvement compared to it predecessor. Although we can argue there’s a lot of things to be improved yet (like better portal UI, storage triggers, direct function-to-function calls, etc), in my opinion Microsoft is moving in the right direction here. This is the way…</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5a86aec7ea13" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Fantastic Probes And How To Configure Them — A kubernetes Story]]></title>
            <link>https://medium.com/swlh/fantastic-probes-and-how-to-configure-them-fef7e030bd2f?source=rss-db2bfdc09e85------2</link>
            <guid isPermaLink="false">https://medium.com/p/fef7e030bd2f</guid>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[microservices]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[containers]]></category>
            <dc:creator><![CDATA[Ricardo A.]]></dc:creator>
            <pubDate>Tue, 12 Nov 2019 11:18:57 GMT</pubDate>
            <atom:updated>2020-09-25T10:01:08.585Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Qz93alITsYBh5txFuAZ3zg.png" /></figure><h3>Fantastic Probes And How To Configure Them — A Kubernetes Story</h3><p>Distributed systems are great, right? But manage them and monitor all components to be sure everything is up and running synchronized like musicians in an orchestra is not that great. At least, not that easy…</p><p>Fortunately, nowadays most platforms offer tools to help us to keep the house in order and ensure we won’t run into big surprises. And Kubernetes is not different in this aspect, providing a set of tools to monitor applications and to automatically take actions based upon their state.</p><p>In this article I’ll talk about one of these tools and probably the easiest to setup: <strong>probes</strong>. Despite the name resemble some sophisticated spacecraft/sci-fi artifact, they are nothing more than actions performed by the internal <strong><em>kubelet</em></strong> process to check which pods have their applications available and running properly.</p><p>Probes are defined inside container’s definition in the <em>.yaml</em> resource file used to create the pod:</p><pre>apiVersion: v1<br>kind: Pod<br>metadata:<br>   (...)<br>spec:<br>  containers:<br>  - name: my-awesome-container<br>    image: some-awesome-image<br>    (...)<br>    <strong><em>&lt;probe-type&gt;</em></strong><strong>:<br>      </strong><strong><em>&lt;probe-action&gt;</em></strong><strong>: (...)<br>      initialDelaySeconds: 5<br>      periodSeconds: 10<br>      timeoutSeconds: 3<br>      successThreshold: 2<br>      failureThreshold: 4</strong></pre><p>Kubernetes supports <strong><em>Readiness </em></strong>and <strong><em>Liveness </em></strong>probes. For clusters running version 1.16 or higher, there’s a third type as well called <strong><em>Startup</em></strong>. All of them are optional and, as you can see, each container running inside the pod may have it’s own set of probes.</p><h3>Probe Mechanism</h3><p>No matter what type of probe is executed, Kubernetes uses a common set of properties to control and decide when to execute it and the criteria to consider it successful or failed.</p><p>The first one is the initial delay (<strong>initialDelaySeconds</strong>) which defines the amount of time in seconds to wait before executing the probe for the first time. This interval is particularly good when we have applications with lots of dependencies and/or large loading time. If this property is not set, the probe will be executed as soon as the container is loaded.</p><p>After this initial delay, the probe is executed and <em>kubelet</em> waits for a certain amount of time for a result before assuming a fail for timeout (<strong>timeoutSeconds</strong>). Keep in mind that if you have a short timeout, you may have false results just because your application had no time enough to process the action. The default value is 1 second which is enough for most situations but I highly recommend to define a realistic value for each application.</p><p>If the probe fails, <em>kubelet</em> tries again how many times as set in the <strong>failureThreshold</strong> property, this way any temporary unavailability won’t cause the probe to put the container in a failed state. Only after the last consecutive failed attempt the container will be considered failed. If not set, the default number of attempts is 3.</p><p>In some situations a single successful result may not be enough to really ensure the health of our container. In this case, the <strong>successThreshold</strong> property sets how many consecutive times the action needs to be successful to change the state of a container from failed to successful.</p><p>We can also set the interval between one execution and another, in seconds, using the <strong>periodSeconds</strong> property. If not set, the probe will be executed every 10 seconds.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/658/1*hpuMx_1BvJ5BDqqxhJ18PA.png" /><figcaption>Kubernetes Probes — General flow</figcaption></figure><p>A quick observation: In my experience, I’ve seen more than once developers wrongly interpreting the fact that, except for the new <em>Startup</em>, all probes are periodically executed during the pod’s lifespan (yeah, I’m looking to you <em>Readiness</em> probe… we’ll talk about this later on).</p><h3>Probe Actions</h3><p>Each application is different and so is the way to define their healthiness. Based upon this premise, probes can execute different <strong>actions </strong>to interact with applications running in a container.</p><h4>HTTP Request</h4><p>As Kubernetes is usually used in micro-services architectures, the most common probe action you’ll see around and probably setup is the <strong>HTTP request</strong> (<a href="https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.16/#httpgetaction-v1-core"><em>HTTPGetAction</em></a>).</p><pre><em>&lt;probe-type&gt;</em>:<br><strong>   httpGet:<br>     path: /my/healthcheck/endpoint?param=value<br>     port: 8080<br>     httpHeaders:<br>     - name: SomeHeaderName<br>       value: someHeaderValue<br>     - name: AnotherHeaderName<br>       value: &quot;Another Header Value&quot;<br>   </strong>initialDelaySeconds: 5<br>   periodSeconds: 10<br>   (...)</pre><p>In this case, <em>kubelet</em> sends a GET request to the configured endpoint (<em>path</em>) and port (if not specified, port 80 is used) and check the response. Path needs to be accessible from inside the cluster and relative to the container’s address, allowing normal URL encoded parameters (as seen the previous exemple).</p><p>This action also can be configured to send custom HTTP headers, allowing for example to use authentication tokens.</p><p>The action is considered <em>failed</em> if there’s no response or if the response is <strong>not</strong> between 200 and 399.</p><p><strong><em>Note: </em></strong><em>As you may have noticed, Kubernetes considers redirection codes as success, so keep this in mind when developing your application’s probe endpoint.</em></p><h4>Shell Command</h4><p>Another option is to configure the probe to run a <strong>shell command </strong>(<a href="https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.16/#execaction-v1-core"><em>ExecAction</em></a>) which is executed in pod’s shell context and considered failed if the execution returns any result code different from 0 (zero).</p><pre><em>&lt;probe-type&gt;</em>:<br><strong>   exec:<br>     command:<br>     - /app/bin/myFantasticConsoleApp.exe<br>     - param1<br>     - &quot;param 2&quot;<br>   </strong>initialDelaySeconds: 5<br>   periodSeconds: 10<br>   (...)</pre><p>An array of strings is passed through the <em>command</em> property and then executed inside pod’s context. The first element is the application path (relative or absolute) and each other element is passed as a command line argument.</p><p><strong><em>Note:</em></strong><em> The command does not necessarily needs to call your application. It can simply check if a file has been created, for exemple, with </em><em>test -f &quot;fileName&quot;.</em></p><h4>TCP Port Check</h4><p>The last action that can be performed by a probe is the <strong>TCP port check </strong>(<a href="https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.16/#tcpsocketaction-v1-core"><em>TCPSocketAction</em></a>) which checks if a port in the pod is open. If <em>kubelet</em> is able to connect to a specific port, the action is considered successful. As simple as it sounds.</p><pre><em>&lt;probe-type&gt;</em>:<br><strong>   tcpSocket:<br>     port: 5677<br>   </strong>initialDelaySeconds: 5<br>   periodSeconds: 10<br>   (...)</pre><p>In both TCPSocketAction and HttpGetAction we can use named ports instead of a number, but this is subject for another time.</p><h3>Probe Types</h3><p>There are currently three different types of probes in a Kubernetes cluster: <em>Readiness, Liveness</em> and <em>Startup</em>. Although they have the same properties and behavior, each one is executed in a specific moment with slightly different outcome, and it’s crucial to clearly understand their purpose to optimize usage and avoid problems.</p><h4>Readiness Probe</h4><p>When a new pod is created, its services are <strong>not </strong>immediately registered in cluster’s load balancer and so they’re not allowed to serve external traffic (services running inside the same cluster still can access them). This way Kubernetes can prevent an instance of a service to receive requests when it is still loading or too busy to process them properly. <strong>Readiness probes </strong>are used to check when the containers running in that pod are (guess what?) ready and able to receive external requests.</p><p>The most common use of this probe is to check if all dependencies of a pod are available. For example, if your application depends on a database, two other services and a message bus, you could implement a method to verify all these external components are ready. In case of failure, you can even provide different codes and responses for different kinds of fails to track down what component is failing.</p><p>However (and here comes a big however) some developers seems to ignore or forget the fact that this probe is not executed only during the startup of a container. It will be repeatedly executed and every time if fails the container will be removed from the list of available services for requests. Thus this probe should not execute long/heavy tasks to avoid overloading services. A busy service also my take longer to execute the probe and return false failures due to timeout.</p><p><strong><em>Note: </em></strong><em>I am currently writing another article detailing a solution for this problem using a list of dependencies and it’s current state, distributing dependency checking along the code and making this probe light-speed fast (as soon as I finish it, I will publish the link here).</em></p><h4>Liveness Probe</h4><p>Application loaded, all dependencies checked, requests free to come in... but what if the application is dead-locked? The quickest solution would be to make its container to be restarted, which would return the application to it initial healthy state.</p><p>For that purpose, Kubernetes provides <strong>Liveness probes</strong>. They work exactly like <em>Readiness </em>probes but, in case of failure, it causes the container to be killed and restarted, creating an automatic mechanism for recover applications from an unresponsive state. Needless to say this probe should have an execution interval (<em>periodSeconds</em>) short enough to ensure highest availability and also not too short to the point of impacting service performance.</p><p>As you notice, in most applications (if not all) this probe is meant to be simple and quick. For a service, for example, an endpoint returning a HTTP OK would do the trick.</p><p>Also, avoid long checks for this probe as it may cause false fails due to timeout. This scenario is even worse here than in a Readiness probe because it may cause exactly the opposite of what is expected, as killing and restarting a container is a time consuming operation and doing that to a healthy container is everything we don’t want when speaking of high availability.</p><h4>Startup Probe</h4><p>As from Kubernetes 1.16 a new type of probe is available, the <strong>Startup probe</strong>. From a logic and configuration point of view, Startups and Liveness probes are exactly the same. They have the same properties and in case of fail its container is restarted as well.</p><p>If a <em>Startup </em>probe is set, after container creation Kubernetes will execute it instead of <em>Liveness </em>probe, which will be in a “hold” state. If <em>Startup </em>probe succeeds, it is replaced by the <em>Liveness </em>probe which will then be executed normally as configured. If the <em>Startup </em>probe fails, the pod is restarted and the cycle repeated.</p><p>So, if the <em>Startup </em>probe has the same logic as <em>Liveness </em>and is executed only until it succeed and letting <em>Liveness </em>assumes afterwards, why do we need it in the first place? Can’t we just increase the initial delay (<em>initialDelaySeconds</em>) for a reasonable time?</p><p>Short answer: It depends.</p><p>Long answer: Sometimes a bigger initial delay for <em>Liveness </em>probe does the trick. Sometimes, to maximize availability, it doesn’t. If you know exactly how long your application needs to become available, go for it! However some applications have long loading periods which can’t be precisely estimated. For example, let’s suppose your application have a lot of tasks during initialization that depend on factors with unpredictable response time, like other applications that may or may not be starting and busy at that moment. How to figure it out the amount of time needed if sometimes it is less than a second and sometimes it may take a minute? If you have a short initial delay, you will cause your container to be wrongly restarted. If you set a large delay, you will have a period where you application may be having problems but there’s no probe to check it.</p><p><em>Startup </em>probes sort this out providing a mechanism where you can have a kind of a special <em>Liveness </em>probe with different configurations only during the startup. Usually we configure Startup probes with the same values as <em>Liveness </em>but a higher tolerance to failure (<em>failureThreshold</em>). For example:</p><pre>startupProbe:<br>  httpGet:<br>    path: /probes/liveness<br>    initialDelaySeconds: 5<br>    periodSeconds: 5<br>    timeoutSeconds: 3<br>    <strong>failureThreshold: 18</strong><br>livenessProbe:<br>  httpGet:<br>    path: /probes/liveness<br>    periodSeconds: 5<br>    timeoutSeconds: 3<br>    <strong>failureThreshold: 3</strong></pre><p>This configuration sets a <em>Startup </em>probe to be started 5 seconds after the container creation (<em>initialDelaySeconds</em>), and executed every 5 seconds (<em>periodSeconds</em>) with a tolerance to fail 18 times (<em>failureThreshold</em>). So only after the 18th failure, this probe will cause the container to be restarted.</p><p>On the other hand (and here is the trick) as we’re using the default success threshold, as soon as it succeeds this probe is deactivated and the <em>Liveness </em>probe starts to be executed, but the later with a more realistic failure threshold of only 3 times.</p><p>So packing everything up, now this container have up to 90 seconds to be available at startup but as soon as it becomes available, any problem can be detected in no more than 15 seconds.</p><h4>General Overview</h4><p>For people that likes diagrams (as myself), here’s one to show the execution flow of probes in a Kubernetes cluster:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/551/1*B_wvCEbp_DobOXwMAaozjA.png" /><figcaption>Kubernetes probe logic</figcaption></figure><h3>Conclusion</h3><p>Probes are an incredibly easy-to-set and useful native tool in Kubernetes clusters. However, as you brave reader who reached this point may have seen, some situations and caveats need to be taken in consideration when developing and setting up them.</p><p>I hope you have enjoyed the article, first one I make in a long time and the very first here in Medium. Any suggestion, corrections or comments, please feel free to shout any time.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fef7e030bd2f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/fantastic-probes-and-how-to-configure-them-fef7e030bd2f">Fantastic Probes And How To Configure Them — A kubernetes Story</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>