<?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 Praveen Raveendran on Medium]]></title>
        <description><![CDATA[Stories by Praveen Raveendran on Medium]]></description>
        <link>https://medium.com/@praveenr801?source=rss-a56f90a24494------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*KzHyFXUd0cNMhSjweLEz1A.jpeg</url>
            <title>Stories by Praveen Raveendran on Medium</title>
            <link>https://medium.com/@praveenr801?source=rss-a56f90a24494------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 04:01:41 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@praveenr801/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[Kubernetes — The beginners guide]]></title>
            <link>https://medium.com/@praveenr801/basics-of-kubernetes-c7e0cc0b59c1?source=rss-a56f90a24494------2</link>
            <guid isPermaLink="false">https://medium.com/p/c7e0cc0b59c1</guid>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[kubernetes-cluster]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[cloud-computing]]></category>
            <category><![CDATA[containers]]></category>
            <dc:creator><![CDATA[Praveen Raveendran]]></dc:creator>
            <pubDate>Mon, 12 Jun 2023 08:22:58 GMT</pubDate>
            <atom:updated>2023-06-12T11:10:48.561Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bXN9NE64X3eaKgF_NenGCw.jpeg" /></figure><h4><strong>Introduction</strong></h4><p>In short, Kubernetes (k8s) is a container orchestration tool that automates the container deployments, container scaling, load balancing etc. The name Kubernetes originates from Greek, meaning helmsman or pilot. K8s as an abbreviation results from counting the eight letters between the “K” and the “s”.</p><p><strong>Why we need containers?</strong></p><p>Containers are the solutions for the problems related to run the software reliably on different environment (development, testing, staging etc. Containers are used to package and run the applications along with its dependencies.</p><p>This mechanism will help us to encapsulate each application as a container image, which will help us to execute this application in any environment or system without worrying about it’s dependencies.</p><p><strong>How Kubernetes related to containers?</strong></p><p>Containerized applications can get complicated. what happens if the container dies? how to establish network between two containers? how to manage thousands of containers in production environment?</p><p>Kubernetes is the one of the solutions for above mentioned problems. It helps to manage areas like the amount compute, network, storage etc. for a containerized application.</p><p>Kubernetes manage the entire lifecycle of a container, shutting down and spinning up the resources as needed. If the container shutdown unexpectedly, the Kubernetes platform helps to launch another container in it’s place.</p><p><strong>Kubernetes Objects</strong></p><p>Kubernetes object defines the state of the entities in the system. It also act as an additional layer of abstraction over the container interface. So that the communication can be done directly with Kubernetes objects instead of containers. Kubernetes objects are usually defined by JSON or YAML files. The basics Kubernetes objects are:</p><ol><li>Pods</li></ol><p>Pod contains group of containers which usually run together. it can be referred as smallest deployment unit in a Node. Usually one pod contains at least one container.</p><p>2. Service</p><p>A Kubernetes Service provides a stable endpoint which can be used to direct traffic to the desired Pods even as the exact underlying Pods change due to updates, scaling, and failures. Services know which Pods they should send traffic to based on labels, which we define in the Pod metadata.</p><p>3. Deployment</p><p>A Deployment object contains the collection of pods defined by a template and a replica count (the copies of the pods).</p><p>4. Ingress</p><p>A service helps to expose the applications behind a stable endpoint. But this is only available inside the cluster. So how to expose the application outside the cluster? It can be done using Ingress.</p><p>Ingress exposes HTTP and HTTPs routes from outside the cluster to services within the cluster</p><p><strong>Kubernetes Control Plane</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/811/1*Z7VUT0zJI2oIUBaPIaQeew.png" /><figcaption>Kubernetes cluster image</figcaption></figure><p>The Kubernetes control plane manages clusters and resources. The control plane receives information about cluster activity, internal and external requests, and more. Based on these activities, control plane changes the resources from their current state to the desired state.</p><p>Master Node</p><p>The master node makes global decisions about the cluster and they also detect and respond to the cluster events.</p><ol><li>kubectl</li></ol><p><strong>The Kubernetes command-line tool</strong>, kubectl, allows you to run commands against Kubernetes clusters. You can use kubectl to deploy applications, inspect and manage cluster resources, and view logs.</p><p>2. kube-api server</p><p>Kubernetes api server will act as an front end to the Kubernetes cluster. It validates and configures data for the API objects which include pods, services, replication controllers, and others.</p><p>3. kube-scheduler</p><p>The Kubernetes scheduler is a control plane process which assigns Pods to Nodes. The scheduler determines which Nodes are valid placements for each Pod in the scheduling queue according to constraints and available resources</p><p>4. kube-controller manager</p><p>The Kubernetes controller manager monitors the state of the Kubernetes cluster continuously via kube-api server. When the current state does not match the desired state, it makes changes to achieve the desired state.</p><p>5. etcd</p><p>This is the distributed key-value store where all cluster-related data is stored. For security reasons, it is only accessible through the API server.</p><p>Worker Nodes:</p><ol><li>kubelet</li></ol><p>The kubelet is the primary “node agent” that runs on each node. It uses container runtime to start the pod. Also it will reports the node states to the api server.</p><p>2. Kube-proxy</p><p>The kube-proxy is a network proxy that runs on each node in your cluster. kube-proxy maintains network rules on nodes. These network rules allow network communication to Pods from network sessions inside or outside of your cluster.</p><p>In the next article, we’ll see how to setup a Kubernetes cluster using minikube. Until then, <strong>Happy learning</strong>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c7e0cc0b59c1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Introduction to Redis cache using docker container]]></title>
            <link>https://medium.com/@praveenr801/introduction-to-redis-cache-using-docker-container-2e4e2969ed3f?source=rss-a56f90a24494------2</link>
            <guid isPermaLink="false">https://medium.com/p/2e4e2969ed3f</guid>
            <category><![CDATA[csharp]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[cache]]></category>
            <category><![CDATA[dotnet]]></category>
            <category><![CDATA[redis]]></category>
            <dc:creator><![CDATA[Praveen Raveendran]]></dc:creator>
            <pubDate>Tue, 31 Jan 2023 12:31:42 GMT</pubDate>
            <atom:updated>2023-02-01T18:02:12.451Z</atom:updated>
            <content:encoded><![CDATA[<p>Using caching solution is very important when we are developing a high performant application. Caching uses temporary storage for saving data with an expiration time, and it works for the data that are not changing frequently.</p><p>There are three types of caches:</p><ol><li><strong>In Memory Cache</strong>: It is used to implement cache within a single process. Cache dies after the process.</li><li><strong>Persistence Cache: </strong>In this case, cached data are stored outside the process memory, like filesystem or in database like “Litedb”. So, with this data can be persisted over a period and it will be available after the process completion.</li><li><strong>Distributed Cache: </strong>Distributed caches are used when the cache needs to be shared with multiple process or servers. Usually, cache stored as an external service and other can use it. Redis is an example distributed cache.</li></ol><p>Here we will discuss more about Redis cache, and how to implement Redis cache using .Net and docker.</p><p><strong>What is Redis?</strong></p><p>As per official documentation,</p><p><em>Redis is an open source in-memory data structure store used as a database, cache, message broker, and streaming engine. Redis provides data structures such as strings, hashes, lists, sets, sorted sets with range queries, bitmaps, hyperloglogs, geospatial indexes, and streams. Redis has built-in replication, Lua scripting, LRU eviction, transactions, and different levels of on-disk persistence, and provides high availability via Redis Sentinel and automatic partitioning with Redis Cluster.</em></p><p><strong>How to run Redis in docker container?</strong></p><p>To run Redis in docker container, please follow below mentioned steps.</p><p><strong>Step 1: Download Redis image</strong></p><p>Here is the docker command for downloading and using Redis in local environment.</p><pre>docker pull redis</pre><p>The above command is used to pull the Redis image from docker hub. After this operation, the downloaded image information can be viewed by executing below mentioned docker command.</p><pre>docker image ls</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/626/1*RqlSWcHmDpoum5qp3DLhyA.png" /><figcaption>Image details for Redis</figcaption></figure><p><strong>Step 2: Run Redis container</strong></p><p>Use below docker command to run Redis in a container .</p><pre>docker run -d -p 6379:6379 --name local-redis  redis</pre><p>This will expose port 6379 in your local environment. The docker command for displaying container information is:</p><pre>docker ps</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/780/1*DXMQNkys9A1OMNT3PiKY4w.png" /><figcaption>Redis container details</figcaption></figure><p>The initial setup is completed, Redis container is now up and running. Next, create a new project which will use this container for caching operations.</p><p><strong>Project Setup</strong></p><p>Here we can use a simple web API to demonstrate Redis cache.</p><p>First, open visual studio and create a new ASP.NET Core Web API application. Give the project name and save.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/652/1*rFFJF20B_UIdSzQh2bttIw.png" /><figcaption>Visual studio: Create a new project</figcaption></figure><p><strong>Step 1: Install required Nuget Packages</strong></p><p>Install latest version of <em>SackExchangeRedis </em>package to the application for connecting Redis cache.</p><pre>Install-Package Microsoft.Extensions.Caching.StackExchangeRedis </pre><p><strong>Step 2: Add Redis services to service collection</strong></p><p>Please add Redis services to service collection as shown below:</p><pre>builder.Services.AddStackExchangeRedisCache(options =&gt; { options.Configuration = builder.Configuration[&quot;RedisCacheUrl&quot;]; });</pre><p><strong><em>AddStackExchangeRedisCache</em></strong><em> : </em>This configuration is used to add Redis distributed caching services to the specified <em>IServiceCollection</em>.</p><p><em>RedisCacheUrl </em>configuration contains information about host and port number. For ex:</p><pre>{<br>  &quot;Logging&quot;: {<br>    &quot;LogLevel&quot;: {<br>      &quot;Default&quot;: &quot;Information&quot;,<br>      &quot;Microsoft.AspNetCore&quot;: &quot;Warning&quot;<br>    }<br>  },<br>  &quot;AllowedHosts&quot;: &quot;*&quot;,<br>  &quot;RedisCacheUrl&quot;: &quot;127.0.0.1:6379&quot;<br>}</pre><p>In this demo, we can configure host as 127.0.0.1 and port as 6379.</p><p><strong>Step 3: Redis Cache implementation using <em>IDistributedCache </em>interface</strong></p><p>As a next step, we can create a new class called<strong> </strong><em>RedisCacheService.cs </em>of type <em>IRedisCache.cs </em>(interface)<strong>.</strong> This service can be used to handle all cache related operations.</p><p>Please find the implementation here:</p><pre>public interface IRedisCache<br>    {<br>        Task&lt;byte[]?&gt; Get(string key);<br>        Task&lt;bool&gt; Add(string key, string value);<br>    }</pre><pre> public class RedisCacheService : IRedisCache<br>    {<br>        private readonly IDistributedCache _cache;<br><br>        public RedisCacheService(IDistributedCache cache)<br>        {<br>            _cache = cache;<br>        }<br>        public async Task&lt;bool&gt; Add(string key, string value)<br>        {<br>            // Setting up the cache options<br>            DistributedCacheEntryOptions options = new DistributedCacheEntryOptions()<br>                .SetAbsoluteExpiration(DateTime.Now.AddMinutes(5))<br>                .SetSlidingExpiration(TimeSpan.FromMinutes(3));<br>            var dataToCache = Encoding.UTF8.GetBytes(value);<br>            await _cache.SetAsync(key, dataToCache, options);<br>            return true;<br>        }<br><br>        public async Task&lt;byte[]?&gt; Get(string key)<br>        {<br>            return await _cache.GetAsync(key);<br>        }<br>    }</pre><p><em>IRedisCache </em>interface act as a wrapper of <em>IDistributedCache </em>interface. Next step is to add the newly created service to <em>IServiceCollection</em>.</p><pre>builder.Services.AddSingleton&lt;IRedisCache, RedisCacheService&gt;();<br>builder.Services.AddStackExchangeRedisCache(options =&gt; { options.Configuration = builder.Configuration[&quot;RedisCacheUrl&quot;]; });</pre><p>AbsoluteExpirationRelativeToNow and SlidingExpiration usage is explained below.</p><p><strong>AbsoluteExpirationRelativeToNow: </strong>The cached data will remain in the memory for the specified time, after that the entry will be removed from the cache. Basically, this will indicate the expiration time.</p><p><strong>SlidingExpiration</strong> : as per Microsoft documentation, Gets or sets how long a cache entry can be inactive (e.g. not accessed) before it will be removed. This will not extend the entry lifetime beyond the absolute expiration (if set). For example, if we set <em>sliding expiration</em> as 60 minutes and <em>absolute expiration </em>as 24 hr. If the cached data is not accessed within 60 minutes then the item will be removed from the cache.</p><p><strong>How to Test?</strong></p><p>Please follow below steps to validate the cache implementation.</p><p>Step 1: Check Redis container is up and running</p><p>Step 2: Add a new API controller for reading and updating cached data. As shown below.</p><pre>    [ApiController]<br>    [Route(&quot;[controller]&quot;)]<br>    public class RedisController : ControllerBase<br>    {<br>        private readonly ILogger&lt;RedisController&gt; _logger;<br>        private readonly IRedisCache _cache;<br><br>        public RedisController(ILogger&lt;RedisController&gt; logger, IRedisCache rcache)<br>        {<br>            _logger = logger;<br>            _cache = rcache;<br>        }<br><br>        [HttpGet(Name = &quot;GetCache&quot;)]<br>        public async Task&lt;string?&gt; GetCache(string key)<br>        {<br>            try<br>            {<br>                var byteData = await _cache.Get(key);<br>                if (byteData != null)<br>                    return Encoding.UTF8.GetString(byteData);<br>                return default;<br>            }<br>            catch (Exception ex)<br>            {<br>                return ex.Message;<br>            }<br>        }<br><br>        [HttpPost(Name = &quot;AddToCache&quot;)]<br>        public async Task&lt;bool&gt; AddToCache(string key,string val)<br>        {<br>            try<br>            {<br>                return await _cache.Add(key, val);<br>            }<br>            catch<br>            {<br>                return false;<br>            }<br>        }<br>    }</pre><p>Step 3: Run the application, and test your implementation as shown below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FHKnYB4xhkiRWypkLLS9Kg.png" /><figcaption>Insert data to cache using key as “hello” and value as “Hello world!”</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kStivNNaLdDCWxVUvLDSdA.png" /><figcaption>Retrieve data from cache using same key “hello”</figcaption></figure><p><strong>Conclusion</strong></p><p>In this Article, we just covered basic implementation of Redis cache using .Net and Docker.</p><p>Please share your suggestions and ideas in comment box. <strong>Happy coding</strong>!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2e4e2969ed3f" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>