<?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 Aman Kumar Pandey on Medium]]></title>
        <description><![CDATA[Stories by Aman Kumar Pandey on Medium]]></description>
        <link>https://medium.com/@amandevbhardwaj?source=rss-6534ba5ab8e2------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*EizmKcw22yyDDoyW</url>
            <title>Stories by Aman Kumar Pandey on Medium</title>
            <link>https://medium.com/@amandevbhardwaj?source=rss-6534ba5ab8e2------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 14:19:50 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@amandevbhardwaj/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[Securing Communication over the Internet with SSL/TLS (Article 206)]]></title>
            <link>https://medium.com/@amandevbhardwaj/securing-communication-over-the-internet-with-ssl-tls-article-206-efeca9adca91?source=rss-6534ba5ab8e2------2</link>
            <guid isPermaLink="false">https://medium.com/p/efeca9adca91</guid>
            <category><![CDATA[certificate]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[ssl]]></category>
            <category><![CDATA[certificate-authority]]></category>
            <category><![CDATA[devops]]></category>
            <dc:creator><![CDATA[Aman Kumar Pandey]]></dc:creator>
            <pubDate>Tue, 25 Feb 2025 16:36:41 GMT</pubDate>
            <atom:updated>2025-02-25T16:36:41.736Z</atom:updated>
            <content:encoded><![CDATA[<h3>Securing Communication over the Internet with SSL/TLS (Article 20)</h3><p><strong><em>Disclaimer</em></strong>: <em>This article aims to explain SSL/TLS connections and how they provide security over the internet. It is an essential topic to understand before we understand about certificate management in Kubernetes.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pdPql-OPh6geZ-lz-iwvPA.jpeg" /></figure><p>Ensuring the privacy and integrity of data is crucial when communicating over the internet. SSL/TLS (Secure Sockets Layer/Transport Layer Security) are cryptographic protocols that establish a secure, encrypted connection between a client (such as a web browser) and a server. This article explains how SSL/TLS work, why they are needed, and their role in securing web communications.</p><h4>HTTP vs. HTTPS</h4><p>Data on the internet is transferred using the <strong>Hypertext Transfer Protocol (HTTP)</strong> or its secure counterpart, <strong>HTTPS (HTTP Secure)</strong>. The key difference is that HTTP transmits data in plaintext, making it vulnerable to eavesdropping and tampering. HTTPS, on the other hand, encrypts data to ensure secure communication, which is especially important for sensitive transactions like banking and online shopping.</p><h4>Why Encryption is Needed</h4><p>Consider a scenario where a user enters their login credentials on a website. In an unsecured HTTP connection, these credentials are sent as plaintext, making them vulnerable to hackers who can intercept the data. Encryption ensures that even if an attacker intercepts the communication, they cannot read its contents.</p><h4>Encryption Methods</h4><p>To secure data transmission, SSL/TLS use two types of encryption:</p><h4>1. Symmetric Encryption</h4><p>In symmetric encryption, the same key is used for both encryption and decryption. While fast and efficient, it poses a security risk because the encryption key must be shared between the sender and receiver. If a hacker intercepts this key, they can decrypt all communication.</p><h4>2. Asymmetric Encryption</h4><p>To solve the key-sharing problem, <strong>asymmetric encryption</strong> uses a pair of keys:</p><ul><li><strong>Public Key</strong>: Shared openly and used to encrypt data.</li><li><strong>Private Key</strong>: Kept secret and used to decrypt data.</li></ul><p>This method is more secure because the private key never leaves the server. Even if an attacker obtains the public key, they cannot decrypt the data.</p><h4>How SSL/TLS Secure HTTP Connections</h4><p>To establish a secure HTTPS connection, SSL/TLS follows a process called the <strong>TLS Handshake</strong>:</p><ol><li><strong>ClientHello:</strong> The client (browser) sends a request to the server, listing supported encryption methods (cipher suites) and a random value.</li><li><strong>ServerHello:</strong> The server responds with its chosen cipher suite, another random value, and its <strong>SSL/TLS certificate</strong>.</li><li><strong>Certificate Validation:</strong> The client verifies the server’s certificate against a list of trusted Certificate Authorities (CAs).</li><li><strong>Key Exchange:</strong> The client and server securely exchange a symmetric session key using asymmetric encryption.</li><li><strong>Session Established:</strong> The symmetric session key is now used for encrypting further communication.</li></ol><h4>Preventing Man-in-the-Middle (MITM) Attacks</h4><p>Even with encryption, attackers could attempt a <strong>Man-in-the-Middle (MITM) attack</strong>, where they intercept and alter communication. To prevent this, SSL/TLS relies on certificates.</p><h4>Certificates and Certificate Authorities (CAs)</h4><p>Instead of trusting any public-private key pair, websites use <strong>SSL/TLS certificates</strong> issued by trusted <strong>Certificate Authorities (CAs)</strong>. The process works as follows:</p><ol><li>A server generates a <strong>Certificate Signing Request (CSR)</strong> and submits it to a CA.</li><li>The CA verifies the request and domain ownership before issuing a signed <strong>SSL/TLS certificate</strong>.</li><li>The server installs the certificate, allowing clients to verify its authenticity before establishing a secure connection.</li></ol><p>Browsers trust certificates from recognized CAs, ensuring that users connect to legitimate websites instead of malicious ones.</p><h4>SSL vs. TLS: Understanding the Difference</h4><p>While SSL and TLS are often used interchangeably, <strong>TLS is the modern replacement for SSL</strong>. Older versions, <strong>SSL 2.0 and SSL 3.0</strong>, were found to have vulnerabilities (such as the <strong>POODLE attack</strong>). TLS 1.2 and TLS 1.3 are the currently recommended versions, with TLS 1.3 offering better security and performance.</p><h4>Common Security Concerns</h4><p>Despite SSL/TLS providing robust security, some attacks still pose a threat:</p><ul><li><strong>Certificate Spoofing:</strong> Attackers may use fraudulent certificates to impersonate trusted websites.</li><li><strong>Downgrade Attacks:</strong> Hackers trick servers into using outdated, less secure encryption methods.</li><li><strong>Self-Signed Certificates:</strong> Internal networks may use self-signed certificates, which are not trusted by browsers unless manually verified.</li></ul><h4>Conclusion</h4><p>SSL/TLS ensures that web communication remains <strong>confidential, authentic, and tamper-proof</strong>. By using asymmetric encryption for key exchange and symmetric encryption for data transmission, these protocols provide a secure foundation for the internet. TLS has replaced SSL due to its stronger security, and its proper implementation is essential for protecting users from cyber threats.</p><p>By understanding how SSL/TLS work, businesses and developers can ensure that their websites and applications remain secure, safeguarding sensitive user data from attackers.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=efeca9adca91" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Kubernetes ConfigMaps and Secrets: A Deep Dive (Article 19)]]></title>
            <link>https://medium.com/@amandevbhardwaj/kubernetes-configmaps-and-secrets-a-deep-dive-article-19-3ff56a279554?source=rss-6534ba5ab8e2------2</link>
            <guid isPermaLink="false">https://medium.com/p/3ff56a279554</guid>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[k8s]]></category>
            <category><![CDATA[configmap]]></category>
            <category><![CDATA[secrets]]></category>
            <category><![CDATA[kubernetes]]></category>
            <dc:creator><![CDATA[Aman Kumar Pandey]]></dc:creator>
            <pubDate>Thu, 13 Feb 2025 07:57:34 GMT</pubDate>
            <atom:updated>2025-02-13T07:57:34.474Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Disclaimer</strong><em>: This article explores the concepts of ConfigMaps and Secrets in Kubernetes, essential tools for managing configuration data and sensitive information in containerized applications. It is a part of kubernetes series articles.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Pa1UyKDYTooUhjpwhla-tw.png" /></figure><h4><strong>The Need for ConfigMaps</strong></h4><p>In Kubernetes, it’s common to use environment variables to configure applications within Pods. However, embedding these directly into the Pod’s YAML file becomes problematic as the number of variables grows or when the same variables need to be used across multiple Pods. Maintaining consistency and avoiding repetition becomes challenging in such scenarios. <strong>ConfigMaps solve this issue by allowing us to store configuration data separately from your Pod definitions</strong>.</p><h4><strong>What are ConfigMaps ?</strong></h4><p>A ConfigMap is a Kubernetes object that stores key-value pairs of configuration data. This data can then be injected into Pods as environment variables, command-line arguments, or files. This decoupling of configuration from application code makes it easier to manage and reuse configurations across different parts of your Kubernetes deployment.</p><p>If we want to pass environment variables in a container one of the way includes declaring it in the pod yaml.</p><pre>apiVersion: v1<br>kind: Pod<br>metadata:<br>  name: config-pod<br>  labels:<br>    app: config-pod<br>spec:<br>  containers:<br>    - name: config-pod<br>      image: busybox<br>      env:<br>        - name: NAME<br>          value: AMAN<br>      command: [&#39;sh&#39;, &#39;-c&#39;, &#39;echo this app is running &amp;&amp; sleep 3600&#39;]</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/967/1*rAbVHSd9OeBC5N5IjkvDxw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/978/1*ZLb2Ae4Z6gPetmXm47AxSg.png" /></figure><p>But this approach as we have discussed earlier is tedious and is not efficient.</p><p>So lets explore other ways…………</p><h4><strong>Creating ConfigMaps: Imperative Approach</strong></h4><p>In this ection we will explore how to do it in an imperative way to create a ConfigMap using the kubectl command-line tool:</p><ul><li><strong>Basic Syntax:</strong></li></ul><pre>kubectl create cm &lt;configmap-name&gt; --from-literal=&lt;key&gt;=&lt;value&gt;.</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/898/1*XxRsy-OfhkyS3Yj5jcFkvw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/873/1*NDUkjV9roM9Ap3t9lfn7DQ.png" /></figure><p><strong>Verification:</strong> We can verify our config map using the commands.</p><pre>kubectl get cm </pre><pre>kubectl decribe cm/&lt;name of config map&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/892/1*OqKWTr2uHy9Ym5VIPm3nrQ.png" /></figure><p><strong>Injecting ConfigMaps into Pods</strong></p><p>Once a ConfigMap is created, we can inject it into Pods in several ways:</p><p><strong>Individual Environment Variables:</strong> You can inject specific key-value pairs from the ConfigMap as environment variables within the container. In the Pod YAML, we’d specify the environment variable name and then use configMapKeyRef to reference the ConfigMap name and the key containing the desired value.</p><pre>apiVersion: v1<br>kind: Pod<br>metadata:<br>  name: config-pod<br>  labels:<br>    app: config-pod<br>spec:<br>  containers:<br>    - name: config-pod<br>      image: busybox<br>      command: [&#39;sh&#39;, &#39;-c&#39;, &#39;echo this app is running &amp;&amp; sleep 3600&#39;]<br>      env:<br>        - name: FIRSTNAME<br>          valueFrom:<br>            configMapKeyRef:<br>              name: data-secrets<br>              key: firstname</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/891/1*rNz_gNgbP0rsHUr-1lbiVw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/922/1*UfGRrvrrU0Jk3Rbu8iSMTQ.png" /></figure><p>In this example, the environment variable FIRSTNAME inside the container will take its value from the firstname key in the data-secrets ConfigMap.</p><p><strong>All Environment Variables:</strong> A more efficient way to inject all key-value pairs from a ConfigMap is by using the envFrom field in the container specification.</p><p>In the Pod YAML, we would use a configMapRef that references the ConfigMap name:</p><pre>apiVersion: v1<br>kind: Pod<br>metadata:<br>  name: config-pod<br>  labels:<br>    app: config-pod<br>spec:<br>  containers:<br>    - name: config-pod<br>      image: busybox<br>      command: [&#39;sh&#39;, &#39;-c&#39;, &#39;echo this app is running &amp;&amp; sleep 3600&#39;]<br>      envFrom:<br>        - configMapRef:<br>            name: app-cm</pre><p>This loads all key-value pairs from the app-cm ConfigMap as environment variables into the container.</p><p><strong>Mounting as a Volume:</strong> Another approach is to mount the ConfigMap as a volume inside the container. This makes the ConfigMap data available as files within the container’s file system. This approach is generally used with Secrets rather than ConfigMaps. We will explore more on this when we will discuss about storage in future articles.</p><p><strong>Creating ConfigMaps: Declarative Approach</strong></p><p>Besides the imperative approach, ConfigMaps can also be created declaratively by defining a YAML file.</p><p><strong>Generating YAML:</strong> You can generate a basic ConfigMap YAML using the command : —</p><pre>kubectl create cm &lt;configmap-name&gt; --from-literal=&lt;key&gt;=&lt;value&gt; --dry-run=client -o yaml &gt; cm.yaml</pre><p><strong>YAML Structure:</strong> The generated YAML file includes fields like apiVersion, kind (set to ConfigMap), metadata (including the name), and data (containing the key-value pairs).</p><pre>apiVersion: v1<br>data:<br>  name: aman<br>  department: cse<br>  class: engineering<br>kind: ConfigMap<br>metadata:<br>  name: app-cm</pre><p><strong>Applying YAML:</strong> You can create the ConfigMap by applying the YAML file using kubectl apply -f cm.yaml.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mRBJUiuNzrKun3ClQcmD0A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gsHKiUhqDOo_M0xR-Q_pww.png" /></figure><p><strong>Updating ConfigMaps</strong></p><p>It’s important to note that you cannot directly update a ConfigMap. To change a ConfigMap’s values, you must either:</p><p>Use the force option when updating kubectl apply -f &lt;configmap-file&gt; — force or by recreating the resource.</p><p>Delete the Pod using the config map and recreate it so it will read the latest config map.</p><p><strong>Key Takeaways</strong></p><p><strong>ConfigMaps are essential for externalizing configuration from Pod definitions</strong>.</p><ul><li>They store configuration data as key-value pairs.</li><li>ConfigMaps can be created imperatively or declaratively.</li><li>You can inject ConfigMap data into Pods as individual environment variables, all environment variables, or files (when mounted as a volume).</li><li><strong>Secrets are used for managing sensitive data</strong> and can also be mounted as volumes.</li><li>Updating ConfigMaps requires a forced update or Pod recreation.</li></ul><p>By using ConfigMaps and Secrets effectively, we can manage and secure our application configuration in Kubernetes much more effectively, promoting better maintainability and security for our deployments.</p><p>Thank you for coming this far, i hope to meet you all in the next part of this article series where we will dive deeper and understand more of our container orchestration Kubernetes.</p><p>I want to thank MR. PIYUSH SACHDEVA (Youtube: Tech Tutorials with Piyush) for such an amazing explanations of these concepts.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3ff56a279554" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding Kubernetes Health Probes: Liveness, Readiness, and Startup (Article 18)]]></title>
            <link>https://medium.com/@amandevbhardwaj/understanding-kubernetes-health-probes-liveness-readiness-and-startup-article-18-d40941fb5051?source=rss-6534ba5ab8e2------2</link>
            <guid isPermaLink="false">https://medium.com/p/d40941fb5051</guid>
            <category><![CDATA[k8s]]></category>
            <category><![CDATA[health-probe]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[tcp]]></category>
            <category><![CDATA[kubernetes]]></category>
            <dc:creator><![CDATA[Aman Kumar Pandey]]></dc:creator>
            <pubDate>Wed, 12 Feb 2025 05:37:09 GMT</pubDate>
            <atom:updated>2025-02-12T05:37:09.257Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AWTUYX4mICQje-sMY9J6mQ.png" /></figure><p><strong>Disclaimer : </strong><em>This article aims to dive deeper into the world of kubernetes where we discuss about health probes in k8s and what are the different ways and types for its implementation in depth. It is a continuation of the kubernetes series articles.</em></p><p>Kubernetes health probes are essential for ensuring the health and availability of applications running in a cluster. These probes continuously monitor applications and take necessary actions to recover from failures. The main goal is to ensure that applications are self-healing, automatically restarting when they fail and preventing user impact. There are three primary types of health probes: <strong>liveness</strong>, <strong>readiness</strong>, and <strong>startup</strong>. Each of these can perform three types of health checks: HTTP, TCP, or command execution.</p><h4>What are Probes?</h4><p>Before delving into the different types of health probes, it’s crucial to understand what a “probe” is in this context. A probe is a system or process that monitors your application and takes necessary actions to maintain its health. This monitoring may involve inspecting, interrogating, or observing an application.</p><h4>Liveness Probes</h4><p><strong>Liveness probes</strong> monitor our application and restart it if it fails. They are crucial for ensuring that the application automatically recovers from issues like intermittent network errors or application errors.</p><ul><li><strong>How They Work:</strong> A liveness probe continuously monitors your application after a set interval. If the application fails, the liveness probe restarts the container. If the restarts don’t fix the issue, you will receive an alert, giving you time to investigate and fix the problem.</li></ul><h4><strong>Types of Checks:</strong></h4><ul><li><strong>HTTP:</strong> The probe sends an HTTP request to a specified endpoint. A successful response indicates the application is healthy.</li><li><strong>TCP:</strong> The probe attempts to open a port on a specified endpoint. A successful connection indicates the application is healthy.</li><li><strong>Command:</strong> The probe executes a command within the container. A successful exit code indicates the application is healthy.</li></ul><p><strong>Example (Command Type):</strong></p><pre>apiVersion: v1<br>kind: Pod<br>metadata:<br>  name: liveness-c<br>  labels:<br>    probe: liveness-command<br>spec:<br>  containers:<br>    - name: liveness-container<br>      image: registry.k8s.io/busybox<br>      args:<br>        - /bin/sh<br>        - -c<br>        - touch /temp/healthy; sleep 30; rm -f /temp/healthy; sleep 600;<br>      livenessProbe:<br>        exec:<br>          command:<br>            - cat<br>            - /temp/healthy<br>        initialDelaySeconds: 5<br>        periodSeconds: 5</pre><p>A container starts, creates a file named “healthy”, and then sleeps for 30 seconds before removing it.</p><p>The liveness probe uses the cat command to check for the existence of this file.</p><p>Initially, the check passes because the file exists. After 30 seconds, when the file is removed, the liveness probe fails, and the container restarts.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Yes0Q6DA8i6f7UgwATTYHQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*deqcCRMn3F8WP4yaGdpYpg.png" /></figure><p>The probe has an initialDelaySeconds property that defines how long to wait before performing the first check. It also has a periodSeconds that specifies how often the check is performed.</p><p>The failureThreshold and successThreshold determine the number of consecutive failed or successful attempts required to trigger an action (restart or declare healthy, respectively).</p><p><strong>Example (HTTP Type)</strong></p><p>The liveness probe sends an HTTP request to the path /healthz on port 8080.</p><pre>apiVersion: v1<br>kind: Pod<br>metadata:<br>  name: hello<br>spec:<br>  containers:<br>    - name: liveness<br>      image: registry.k8s.io/e2e-test-images/agnhost:2.40<br>      args:<br>        - liveness<br>      livenessProbe:<br>        httpGet:<br>          path: /healthz<br>          port: 8080<br>        initialDelaySeconds: 3<br>        periodSeconds: 3<br>      readinessProbe:<br>        httpGet:<br>          path: /healthz<br>          port: 8080<br>        initialDelaySeconds: 15<br>        periodSeconds: 10</pre><p>Initially the container was unhealthy because it took more than the initial delay of 3 seconds to start. The error code was 500 and then it restarted.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Hr0TOWk3ro8hHtY-sL8nJA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Z0nri7MgncvO6A78TKgt8w.png" /></figure><p>If the endpoint does not return a successful response the liveness probe fails and restarts the container.</p><p><strong>Example (TCP Type)</strong></p><p>The liveness probe attempts to open a TCP port on the container on port 8080.</p><pre>apiVersion: v1<br>kind: Pod<br>metadata:<br>  name: liveness-tcp<br>  labels:<br>    probe: tcp<br>spec:<br>  containers:<br>    - name: tcp-container<br>      image: registry.k8s.io/goproxy:0.1<br>      ports:<br>        - containerPort: 8080<br>      livenessProbe:<br>        tcpSocket:<br>          port: 8080<br>        initialDelaySeconds: 5<br>        periodSeconds: 5</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RWv9zGGgMPMqf0-Mz4W_EA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fYI9SSNGlvptNFtxjEjcKQ.png" /></figure><p>If the port is open, the application is healthy. If the connection is refused, the probe fails and the container is restarted.</p><h4>Readiness Probes</h4><p><strong>Readiness probes</strong> ensure that your application is ready before it starts serving traffic. This prevents users from receiving errors while an application is booting up.</p><ul><li><strong>How They Work:</strong> The readiness probe checks if an application is fully started and ready to accept traffic. It prevents the application from being added to the load balancer until the readiness probe is successful.</li></ul><p><strong>Use Case:</strong> If an application takes time to boot up (e.g., 20–30 seconds), readiness probes ensure users don’t get errors. The application will not receive traffic until the probe passes.</p><p><strong>Differences from Liveness Probes:</strong></p><p>Unlike liveness probes, readiness probes do not restart the application if the check fails. They only ensure that the application is ready to serve traffic before adding it to the load balancer.</p><p><strong>Configuration:</strong> The syntax for readiness probes is similar to liveness probes, replacing liveness with readiness. They can perform HTTP, TCP, or command-based checks.</p><p><strong>Example:</strong></p><p>If a readiness probe configured for the path /healths on port 8080 fails because the file does not exist, the application will not serve traffic, even though the container is running.</p><p>The readiness probe will not allow traffic until the health check passes, it does not restart the container.</p><h4>Startup Probes</h4><p><strong>Startup probes</strong> are used for slow-starting or legacy applications. They allow for an extended startup period before readiness and liveness probes become active.</p><p><strong>How They Work</strong>: Startup probes ensure an application has enough time to initialize before other probes start their health checks.</p><p><strong>Use Case:</strong> For slow-starting applications, you might set a startup probe to wait for 5 minutes before the readiness and liveness probes become active.</p><p><strong>Priority:</strong> Startup probes run first. Once they succeed, readiness and liveness probes take over.</p><h4>Health Check Types</h4><p>Each probe can perform three types of health checks:</p><ol><li><strong>HTTP:</strong> The probe sends an HTTP request to a specific endpoint. A successful response indicates that the application is healthy.</li><li><strong>TCP:</strong> The probe attempts to open a TCP connection on a specific port. A successful connection indicates that the application is healthy.</li><li><strong>Command:</strong> The probe executes a command inside the container. A successful exit code indicates that the application is healthy.</li></ol><p>Best Practices</p><ul><li><strong>Use Liveness and Readiness Probes:</strong> In production environments, using both liveness and readiness probes is recommended for most applications.</li><li><strong>Set Initial Delay:</strong> Configure an appropriate initialDelaySeconds value to allow the application to boot up fully before health checks begin. Typically, this is set between 10 and 30 seconds, depending on the application boot time.</li><li><strong>Configure Failure and Success Thresholds:</strong> Use failureThreshold and successThreshold to avoid unnecessary restarts and ensure stability.</li></ul><p>Kubernetes Tolerations</p><blockquote>Kubernetes automatically adds tolerations to pods for notReady and notUnreachable taints. This means if a node becomes unreachable or not ready, the pods will be evicted from that node and moved to a healthy node, ensuring high availability.</blockquote><p>By correctly implementing and configuring these health probes, we can significantly improve the reliability and availability of our Kubernetes applications</p><p>Thank you for coming this far, i hope to meet you all in the next part of this article series where we will dive deeper and understand more of our container orchestration Kubernetes.</p><p>I want to thank MR. PIYUSH SACHDEVA (Youtube: Tech Tutorials with Piyush) for such an amazing explanations of these concepts.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d40941fb5051" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding Kubernetes Autoscaling: HPA, VPA, and Beyond (Article 17)]]></title>
            <link>https://medium.com/@amandevbhardwaj/understanding-kubernetes-autoscaling-hpa-vpa-and-beyond-article-17-85f90776a19c?source=rss-6534ba5ab8e2------2</link>
            <guid isPermaLink="false">https://medium.com/p/85f90776a19c</guid>
            <category><![CDATA[hpa]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[vpa]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[autoscaling]]></category>
            <dc:creator><![CDATA[Aman Kumar Pandey]]></dc:creator>
            <pubDate>Tue, 11 Feb 2025 07:09:12 GMT</pubDate>
            <atom:updated>2025-02-11T07:09:12.903Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Disclaimer : </strong><em>This article aims to dive deeper into the world of kubernetes where we discuss about the concept of auto-scaling in kubernetes. It is a continuation of the kubernetes series articles.</em></p><p>In the world of Kubernetes, ensuring our applications can handle varying levels of demand is crucial. This is where autoscaling comes into play. <strong>Scaling</strong> refers to the process of adjusting our server or workload capacity to match the current demand. This can be done manually, which involves actions like updating deployments or replica sets. However, manual scaling is impractical for large-scale production systems, making <strong>autoscaling</strong> essential. Autoscaling allows for automatic adjustments based on demand, workload, or resource utilization.</p><p>There are two primary types of autoscaling: <strong>horizontal and vertical</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DvKjzmSxzHzggO5d4iNJpA.png" /></figure><h4><strong>Horizontal Autoscaling</strong></h4><p><strong>Concept</strong>: Horizontal autoscaling, also known as “scaling out” or “scaling in,” involves adding or removing identical copies of a pod to meet fluctuating demand.</p><ul><li><strong>How it Works</strong>: When an application experiences increased load (e.g., higher CPU or memory usage), horizontal autoscaling adds more pods to the deployment and when the load decreases, it removes extra pods to save costs and optimize resource usage.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/982/1*J61SYXYROB4hQtsN-6fkkQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4frrFLBMjKta17qJCunCzQ.png" /></figure><p><strong>Kubernetes Implementation: Horizontal Pod Autoscaler (HPA)</strong>: In Kubernetes, horizontal autoscaling is achieved using the Horizontal Pod Autoscaler (HPA). The HPA automatically adjusts the number of pod replicas in a deployment, replica set, or stateful set based on observed metrics, such as CPU utilization.</p><p><strong>Metrics Server</strong>: HPA relies on the Metrics Server to provide the necessary metrics like CPU and memory utilization.</p><p><strong>Example</strong>: If the average CPU utilization of a pod goes above a specified threshold (e.g., 50%), HPA will add more pod replicas until the load is reduced. Conversely, if the utilization drops, HPA will reduce replicas to a minimum level.</p><p><strong>Configuration</strong>: HPA can be configured with a target CPU utilization percentage, minimum number of replicas, and maximum number of replicas.</p><p><strong>Monitoring</strong>: HPA monitors workload every few seconds, by default, to adjust the number of replicas.</p><h4><strong>Vertical Autoscaling</strong></h4><p><strong>Concept</strong>: Vertical autoscaling, also known as “scaling up” or “scaling down,” involves resizing the resources (CPU, memory) allocated to an individual pod.</p><ul><li><strong>How it Works</strong>: Instead of adding more pods, vertical autoscaling increases the resource allocation of an existing pod. This is suitable for applications that can tolerate downtime and aren’t mission-critical, since the pod must be restarted to apply these resource changes.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/791/1*mGStN3dqwjYWKN8lDwz_Mw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-lT7Yn3AOW45LSdInEQaFw.png" /></figure><p><strong>Kubernetes Implementation: Vertical Pod Autoscaler (VPA)</strong>: In Kubernetes, vertical autoscaling is handled by the Vertical Pod Autoscaler (VPA). The VPA automatically adjusts the resource requests and limits of pods.</p><p><strong>Considerations</strong>: VPA is a separate project from Kubernetes and needs to be installed and configured separately. It’s best used for applications that can tolerate restarts.</p><p><strong>Horizontal vs. Vertical Autoscaling</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/951/1*mb4A6xExBoOmqmZkpE7XJQ.png" /></figure><p><strong>Autoscaling Beyond HPA and VPA</strong></p><p><strong>Cluster Autoscaler</strong>: This tool adds or removes nodes in a Kubernetes cluster when there is a need for additional resources or when nodes are underutilized.</p><blockquote><strong>Cloud Providers</strong>: Cluster Autoscaler is often provided by cloud providers such as AWS, Google Cloud Platform, and Azure. It integrates with their managed Kubernetes services.</blockquote><p><strong>Node Autoprovisioning</strong>: Cloud providers often offer node autoprovisioning to add node pools dynamically to a cluster.</p><p><strong>Event-Based Autoscaling</strong>: Autoscaling can also be triggered by specific events like error rates or rejected requests. Tools like KEDA (Kubernetes Event-driven Autoscaling) can handle this type of autoscaling.</p><p><strong>Scheduled Autoscaling</strong>: Autoscaling can be scheduled to happen at specific times, which is useful for handling predictable load patterns.</p><h4><strong>Practical Example: HPA in Action</strong></h4><p>Lets do a practical demonstration of how HPA works using a PHP Apache application. We will need our metrics server running(Same as the one we discussed in the previous article.).</p><p><strong>Setup</strong>: A deployment and service are created for a PHP Apache application. The deployment initially has one pod replica.</p><pre>apiVersion: apps/v1<br>kind: Deployment<br>metadata:<br>  name: php-apache<br>spec:<br>  selector:<br>    matchLabels:<br>      run: php-apache<br>  template:<br>    metadata:<br>      labels:<br>        run: php-apache<br>    spec:<br>      containers:<br>        - name: php-apache<br>          image: registry.k8s.io/hpa-example<br>          ports:<br>            - containerPort: 80<br>          resources:<br>            limits:<br>              cpu: 500m<br>            requests:<br>              cpu: 200m<br>---  #This seperates k8s objects from one another in asingle yml file<br>apiVersion: v1<br>kind: Service<br>metadata:<br>  name: php-apache<br>  labels:<br>    run: php-apache<br>spec:<br>  ports:<br>    - port: 80<br>  selector:<br>    run: php-apache</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1003/1*BpU_yr8DD47iJTf3KhqW2A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/962/1*qXJ3j6Kvp2qU3ViE04aWJA.png" /></figure><p><strong>HPA Configuration</strong>: An HPA is configured to monitor the application’s CPU utilization, with a target of 50%. The minimum number of replicas was set to one, and the maximum was set to ten.</p><pre>kubectl autoscale deployment &lt;name of deployment&gt; --cpu-percent=&lt;percentage of cpu we want to scale from&gt; --min=&lt;minimum amount of pods&gt; --max=&lt;mximum amount of pods&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_UrEOVQv1QlbqxU3Pv8iSQ.png" /></figure><p><strong>Load Simulation</strong>: A load generator was used to simulate user requests to the application, increasing its CPU utilization. Use the following command.</p><pre>kubectl run -i --tty load-generator --rm --image=busybox:1.28 --restart=Never -- /bin/sh -c &quot;while sleep 0.01; do wget -q -O- http://php-apache; done&quot;</pre><p>This will generate the load and thus we can test our hpa.</p><p><strong>Scaling Up</strong>: As the CPU usage exceeded 50%, HPA automatically added more pod replicas to handle the increased load.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7iVokS2xfGhkWK4FmpmTRA.png" /></figure><p><strong>Scaling Down</strong>: After the load was stopped, HPA automatically reduced the number of replicas back to the minimum level.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1011/1*O0jEpiXjA6k8s_6vJxymyw.png" /></figure><p>It takes some time but eventually the pods will be downscaled as the load decreases.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/905/1*n9uLSFlJwp2jCMPJXdApHQ.png" /></figure><p><strong>Key Takeaways</strong></p><ul><li>Autoscaling is essential for managing application performance and resource utilization in Kubernetes.</li><li>Horizontal scaling adds more pod replicas, while vertical scaling resizes existing pods.</li><li>HPA is a built-in Kubernetes feature for horizontal autoscaling based on metrics.</li><li>VPA is a separate project for vertical autoscaling, requiring manual installation and setup.</li></ul><p>Other autoscaling methods include cluster autoscaler, event-based autoscaling, and scheduled autoscaling.</p><p>This detailed explanation should provide a comprehensive understanding of autoscaling concepts in Kubernetes as presented in the source.</p><p>Thank you for coming this far, i hope to meet you all in the next part of this article series where we will dive deeper and understand more of our container orchestration Kubernetes.</p><p>I want to thank MR. PIYUSH SACHDEVA (Youtube: Tech Tutorials with Piyush) for such an amazing explanations of these concepts.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=85f90776a19c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding Kubernetes Resource Requests and Limits (Article 16)]]></title>
            <link>https://medium.com/@amandevbhardwaj/understanding-kubernetes-resource-requests-and-limits-article-16-9e45f6635d54?source=rss-6534ba5ab8e2------2</link>
            <guid isPermaLink="false">https://medium.com/p/9e45f6635d54</guid>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[request]]></category>
            <category><![CDATA[limits]]></category>
            <category><![CDATA[k8s]]></category>
            <dc:creator><![CDATA[Aman Kumar Pandey]]></dc:creator>
            <pubDate>Mon, 10 Feb 2025 18:51:04 GMT</pubDate>
            <atom:updated>2025-02-10T18:51:04.222Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AWTUYX4mICQje-sMY9J6mQ.png" /></figure><p><strong>Disclaimer : </strong><em>This article aims to dive deeper into the world of kubernetes where we discuss about how can we efficiently manage the resource requirement of pods and how can we prevent pods from monopolising control over the node’s resources. It is a continuation of the kubernetes series articles.</em></p><p>It’s a fun yet crucial topic to go through. Lets start.</p><p>In Kubernetes, <strong>resource requests and limits</strong> are crucial for managing how pods utilize the resources of your cluster’s nodes. These settings enable you to control the amount of CPU and memory that each pod can use, ensuring efficient resource allocation and preventing any single pod from monopolizing the system. By properly defining these parameters, we can optimize our cluster’s performance and reliability.</p><p>Why Resource Management is Essential</p><p>Without resource requests and limits, pods can potentially consume all available resources on a node, leading to instability. If a pod starts using more resources than it should, this can lead to:</p><ul><li><strong>Node Instability</strong>: A single pod may take all the available memory and CPU, causing other pods on the node to crash.</li><li><strong>Out-of-Memory (OOM) Errors</strong>: If a pod attempts to use more memory than the node has, the pod may crash with an OOM error.</li><li><strong>Resource Starvation</strong>: Other pods may be unable to get the resources they need, causing performance issues.</li></ul><p>To avoid these issues, we must configure resource requests and limits in your pod definitions. These configurations allow Kubernetes to make informed decisions about pod scheduling and resource allocation.</p><h4>Resource Requests: Ensuring Minimum Resource Allocation</h4><p>A <strong>resource request</strong> specifies the minimum amount of resources a pod requires to function. When a pod is created, the Kubernetes scheduler looks for a node with enough available resources to satisfy this request. If no node has the requested resources, the pod will not be scheduled and will remain in a pending state. The request acts as a guarantee to the pod that it will have at least that amount of resource.</p><p>The scheduler uses these requests, along with other factors like node selectors and affinity rules, to determine where a pod can be placed. This ensures that pods are scheduled on nodes that can meet their minimum resource needs.</p><h4>Resource Limits: Setting Maximum Resource Usage</h4><p>A <strong>resource limit</strong> defines the maximum amount of resources a pod is allowed to use. If a pod tries to use more resources than its limit, Kubernetes will take action to prevent it from impacting the rest of the system.</p><p>For memory, if a pod tries to use more memory than its limit, the pod will be terminated with an out-of-memory (OOM) error. For CPU, if a pod uses more than its allocated CPU, the system might throttle the pod, reducing its performance. This mechanism helps in preventing one pod from monopolizing a node’s resources.</p><h4>Practical Examples and Demonstrations</h4><p>Before starting with the implementation lets first create a matrix server inside our kubernetes cluster. Use the manifest specified below. Content of the manifest we will understand with future articles as it includes concepts that are yet to be discussed.</p><pre>apiVersion: v1<br>kind: ServiceAccount<br>metadata:<br>  labels:<br>    k8s-app: metrics-server<br>  name: metrics-server<br>  namespace: kube-system<br>---<br>apiVersion: rbac.authorization.k8s.io/v1<br>kind: ClusterRole<br>metadata:<br>  labels:<br>    k8s-app: metrics-server<br>    rbac.authorization.k8s.io/aggregate-to-admin: &#39;true&#39;<br>    rbac.authorization.k8s.io/aggregate-to-edit: &#39;true&#39;<br>    rbac.authorization.k8s.io/aggregate-to-view: &#39;true&#39;<br>  name: system:aggregated-metrics-reader<br>rules:<br>  - apiGroups:<br>      - metrics.k8s.io<br>    resources:<br>      - pods<br>      - nodes<br>    verbs:<br>      - get<br>      - list<br>      - watch<br>---<br>apiVersion: rbac.authorization.k8s.io/v1<br>kind: ClusterRole<br>metadata:<br>  labels:<br>    k8s-app: metrics-server<br>  name: system:metrics-server<br>rules:<br>  - apiGroups:<br>      - &#39;&#39;<br>    resources:<br>      - nodes/metrics<br>    verbs:<br>      - get<br>  - apiGroups:<br>      - &#39;&#39;<br>    resources:<br>      - pods<br>      - nodes<br>    verbs:<br>      - get<br>      - list<br>      - watch<br>---<br>apiVersion: rbac.authorization.k8s.io/v1<br>kind: RoleBinding<br>metadata:<br>  labels:<br>    k8s-app: metrics-server<br>  name: metrics-server-auth-reader<br>  namespace: kube-system<br>roleRef:<br>  apiGroup: rbac.authorization.k8s.io<br>  kind: Role<br>  name: extension-apiserver-authentication-reader<br>subjects:<br>  - kind: ServiceAccount<br>    name: metrics-server<br>    namespace: kube-system<br>---<br>apiVersion: rbac.authorization.k8s.io/v1<br>kind: ClusterRoleBinding<br>metadata:<br>  labels:<br>    k8s-app: metrics-server<br>  name: metrics-server:system:auth-delegator<br>roleRef:<br>  apiGroup: rbac.authorization.k8s.io<br>  kind: ClusterRole<br>  name: system:auth-delegator<br>subjects:<br>  - kind: ServiceAccount<br>    name: metrics-server<br>    namespace: kube-system<br>---<br>apiVersion: rbac.authorization.k8s.io/v1<br>kind: ClusterRoleBinding<br>metadata:<br>  labels:<br>    k8s-app: metrics-server<br>  name: system:metrics-server<br>roleRef:<br>  apiGroup: rbac.authorization.k8s.io<br>  kind: ClusterRole<br>  name: system:metrics-server<br>subjects:<br>  - kind: ServiceAccount<br>    name: metrics-server<br>    namespace: kube-system<br>---<br>apiVersion: v1<br>kind: Service<br>metadata:<br>  labels:<br>    k8s-app: metrics-server<br>  name: metrics-server<br>  namespace: kube-system<br>spec:<br>  ports:<br>    - name: https<br>      port: 443<br>      protocol: TCP<br>      targetPort: https<br>  selector:<br>    k8s-app: metrics-server<br>---<br>apiVersion: apps/v1<br>kind: Deployment<br>metadata:<br>  labels:<br>    k8s-app: metrics-server<br>  name: metrics-server<br>  namespace: kube-system<br>spec:<br>  selector:<br>    matchLabels:<br>      k8s-app: metrics-server<br>  strategy:<br>    rollingUpdate:<br>      maxUnavailable: 0<br>  template:<br>    metadata:<br>      labels:<br>        k8s-app: metrics-server<br>    spec:<br>      containers:<br>        - args:<br>            - --cert-dir=/tmp<br>            - --secure-port=10250<br>            - --kubelet-preferred-address-types=InternalIP,ExternalIP,Hostname<br>            - --kubelet-use-node-status-port<br>            - --kubelet-insecure-tls<br>            - --metric-resolution=15s<br>          image: registry.k8s.io/metrics-server/metrics-server:v0.7.1<br>          imagePullPolicy: IfNotPresent<br>          livenessProbe:<br>            failureThreshold: 3<br>            httpGet:<br>              path: /livez<br>              port: https<br>              scheme: HTTPS<br>            periodSeconds: 10<br>          name: metrics-server<br>          ports:<br>            - containerPort: 10250<br>              name: https<br>              protocol: TCP<br>          readinessProbe:<br>            failureThreshold: 3<br>            httpGet:<br>              path: /readyz<br>              port: https<br>              scheme: HTTPS<br>            initialDelaySeconds: 20<br>            periodSeconds: 10<br>          resources:<br>            requests:<br>              cpu: 100m<br>              memory: 200Mi<br>          securityContext:<br>            allowPrivilegeEscalation: false<br>            capabilities:<br>              drop:<br>                - ALL<br>            readOnlyRootFilesystem: true<br>            runAsNonRoot: true<br>            runAsUser: 1000<br>            seccompProfile:<br>              type: RuntimeDefault<br>          volumeMounts:<br>            - mountPath: /tmp<br>              name: tmp-dir<br>      nodeSelector:<br>        kubernetes.io/os: linux<br>      priorityClassName: system-cluster-critical<br>      serviceAccountName: metrics-server<br>      volumes:<br>        - emptyDir: {}<br>          name: tmp-dir<br>---<br>apiVersion: apiregistration.k8s.io/v1<br>kind: APIService<br>metadata:<br>  labels:<br>    k8s-app: metrics-server<br>  name: v1beta1.metrics.k8s.io<br>spec:<br>  group: metrics.k8s.io<br>  groupPriorityMinimum: 100<br>  insecureSkipTLSVerify: true<br>  service:<br>    name: metrics-server<br>    namespace: kube-system<br>  version: v1beta1<br>  versionPriority: 100</pre><p>Apply this manifest, then we get a pod running in the control plane node that provides metrics related to different components of our cluster.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OLdlgIp3a2a1GdLMEBqBtQ.png" /></figure><p>Lets implement some practical scenarios for configuring and observing resource requests and limits using kubectl:</p><p><strong>Setting Requests and Limits:</strong> In a pod’s YAML file, we specify the resources under the containers section using requests and limits. For example:</p><pre>apiVersion: v1<br>kind: Pod<br>metadata:<br>  name: memory-demo<br>  namespace: mem-example<br>spec:<br>  containers:<br>    - name: mem-demo-ctr<br>      image: polinux/stress<br>      resources:<br>        requests:<br>          memory: &#39;100Mi&#39;<br>        limits:<br>          memory: &#39;200Mi&#39;<br>      command: [&#39;stress&#39;]<br>      args: [&#39;--vm&#39;, &#39;1&#39;, &#39;--vm-bytes&#39;, &#39;150M&#39;, &#39;--vm-hang&#39;, &#39;1&#39;]</pre><p>This configuration means that the pod requests 100 Mi of memory and will not be allowed to use more than 200 Mi.</p><p><strong>Overriding Limits:</strong> It’s possible to override the memory request at runtime, for testing purposes. Now command is used in the manifest to force the pod to use 150 MB of memory. In this case, the pod is scheduled successfully, and the memory use is within the limits of 200 Mi.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GQ9Y3Xu-4-gxANup1J2qYA.png" /></figure><p><strong>Exceeding Limits:</strong> When a pod tries to use more memory than its defined limit, Kubernetes terminates the pod with an OOM error. This prevents a single pod from impacting other pods or the node itself. Here a pod with a memory limit of 100 Mi will be overridden to use 250 Mi, which will lead to the pod being killed with an OOM error.</p><pre>apiVersion: v1<br>kind: Pod<br>metadata:<br>  name: memory-demo-2<br>  namespace: mem-example<br>spec:<br>  containers:<br>    - name: mem-demo-ctr-2<br>      image: polinux/stress<br>      resources:<br>        requests:<br>          memory: &#39;50Mi&#39;<br>        limits:<br>          memory: &#39;100Mi&#39;<br>      command: [&#39;stress&#39;]<br>      args: [&#39;--vm&#39;, &#39;1&#39;, &#39;--vm-bytes&#39;, &#39;250M&#39;, &#39;--vm-hang&#39;, &#39;1&#39;]</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8FZaJfwzaI_yE1bD2nOgfQ.png" /></figure><p><strong>Insufficient Resources:</strong> If a pod requests more resources than are available on any node, the pod will be stuck in a Pending state. The Kubernetes scheduler will be unable to place the pod. In the next part of practical a pod requested 1000 GB of memory, which was more than available on the nodes, and so the pod remained in the pending state.</p><pre>apiVersion: v1<br>kind: Pod<br>metadata:<br>  name: memory-demo-3<br>  namespace: mem-example<br>spec:<br>  containers:<br>    - name: mem-demo-ctr-3<br>      image: polinux/stress<br>      resources:<br>        requests:<br>          memory: &#39;1000Gi&#39;<br>        limits:<br>          memory: &#39;1000Gi&#39;<br>      command: [&#39;stress&#39;]<br>      args: [&#39;--vm&#39;, &#39;1&#39;, &#39;--vm-bytes&#39;, &#39;300M&#39;, &#39;--vm-hang&#39;, &#39;1&#39;]</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mYLayrCQ8RmH2Njatahwwg.png" /></figure><p>We can see our pod memory-demo-3 in the pending state.</p><h4>The Role of the Metrics Server</h4><p>The <strong>Metrics Server</strong> is a Kubernetes component that collects and exposes resource usage metrics, like CPU and memory, from the nodes. Kubernetes uses these metrics to make scheduling decisions based on requests and limits and for other processes, such as autoscaling. We can view these metrics using commands like : —</p><pre>kubectl top node <br>kubectl top pod.</pre><p>So lets summerize what we have learnt up until now…………………</p><ul><li><strong>Resource requests</strong> specify the minimum amount of resources a pod requires and uses them to find an appropriate node.</li><li><strong>Resource limits</strong> define the maximum amount of resources a pod can use.</li><li>Using <strong>resource requests and limits is essential</strong> for proper resource management in Kubernetes.</li><li>If a pod goes beyond its memory limit, the pod will be killed with an <strong>OOM error</strong>.</li><li>If there aren’t sufficient resources to meet a pod’s request, the pod remains in a pending state.</li><li>The <strong>Metrics Server</strong> provides the data necessary for scheduling decisions.</li></ul><p>By understanding and implementing resource requests and limits, we can improve our Kubernetes cluster’s stability, efficiency, and overall performance. This information is crucial when setting up and managing your Kubernetes deployments.</p><p>Thank you for coming this far, i hope to meet you all in the next part of this article series where we will dive deeper and understand more of our container orchestration Kubernetes.</p><p>I want to thank MR. PIYUSH SACHDEVA (Youtube: Tech Tutorials with Piyush) for such an amazing explanations of these concepts.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9e45f6635d54" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding Kubernetes Node Affinity (Article 15)]]></title>
            <link>https://medium.com/@amandevbhardwaj/understanding-kubernetes-node-affinity-article-15-06d5991ee7a2?source=rss-6534ba5ab8e2------2</link>
            <guid isPermaLink="false">https://medium.com/p/06d5991ee7a2</guid>
            <category><![CDATA[k8s]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[node-affinity]]></category>
            <category><![CDATA[taints-and-toleration]]></category>
            <category><![CDATA[devops]]></category>
            <dc:creator><![CDATA[Aman Kumar Pandey]]></dc:creator>
            <pubDate>Sun, 09 Feb 2025 06:30:16 GMT</pubDate>
            <atom:updated>2025-02-09T06:30:16.323Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AWTUYX4mICQje-sMY9J6mQ.png" /></figure><p><strong>Disclaimer : </strong><em>This article aims to dive deeper into the world of kubernetes where we discuss about node affnity and its related properties in depth. It is a continuation of the kubernetes series articles.</em></p><p>In Kubernetes, <strong>node affinity</strong> is a scheduling concept that allows you to constrain which nodes your pods are eligible to be scheduled on, based on the labels applied to those nodes. It uses <strong>labels and selectors</strong> to match pods to nodes with specific characteristics. Node affinity is crucial for ensuring that your workloads run on the most suitable hardware.</p><h4><strong>Node Affinity vs. Taints and Tolerations</strong></h4><p>Before diving deeper into node affinity, it’s important to distinguish it from taints and tolerations.</p><p><strong>Taints and Tolerations:</strong> Taints are applied to nodes and are used to repel pods. Tolerations are set on pods to allow them to be scheduled on tainted nodes. While taints and tolerations can restrict pods from being scheduled on certain nodes, they don’t guarantee that a pod will be scheduled on a <em>specific</em> node. They only allow the node to accept or restrict certain types of pods.</p><p><strong>Node Affinity:</strong> Node affinity provides more control over where pods are scheduled. It allows you to specify rules that pods use to select nodes, based on the labels of those nodes, and can be used in conjunction with taints and tolerations.</p><h4><strong>How Node Affinity Works ?</strong></h4><p>Node affinity works by matching the labels on nodes with affinity rules defined in the pod specification. Key components of node affinity include:</p><p><strong>Labels:</strong> Nodes are labeled with key-value pairs, describing their characteristics (e.g., disk=ssd, gpu=true).</p><p><strong>Affinity Rules:</strong> Pods include affinity rules specifying which labels they require or prefer on the nodes they are scheduled to run on. These rules use <strong>operators</strong> to define the matching criteria, such as equal to, not equal to, in, not in, and exists.</p><ul><li><strong>requiredDuringSchedulingIgnoredDuringExecution:</strong> This property ensures that a pod is scheduled only if the node labels match the affinity rules at the time of scheduling. If a matching node cannot be found, the pod will remain in a pending state. If the node labels change after the pod has been scheduled, the running pods are not affected.</li><li><strong>preferredDuringSchedulingIgnoredDuringExecution</strong>: This property indicates that the scheduler should <em>prefer</em> nodes that match the affinity rules. If a matching node is not found or does not have enough resources, the pod will still be scheduled on a node even if its labels do not match. The running pod will not be affected if the node labels change.</li><li><strong>nodeSelectorTerms</strong>: This is an array that contains matchExpressions which define how to match node labels.</li><li><strong>matchExpressions</strong>: This is an array with key, operator, and value fields. The key is the node label, the operator specifies how to match the labels (e.g., ‘In’, ‘Exists’), and the value is the value to compare to the node label.</li><li><strong>weight</strong>: With the preferredDuringSchedulingIgnoredDuringExecution property, you can specify a weight for each matchExpression. Higher weights indicate a stronger preference for a given expression.</li></ul><p>An Example manifest.</p><pre>apiVersion: v1<br>kind: Pod<br>metadata:<br>  name: task-pod<br>  labels:<br>    app: task-pod<br>spec:<br>  affinity:<br>    nodeAffinity:<br>      requiredDuringSchedulingIgnoredDuringExecution:<br>        nodeSelectorTerms:<br>          - matchExpressions:<br>              - key: disk<br>                operator: In<br>                values:<br>                  - hdd<br>  containers:<br>    - name: task-image<br>      image: nginx<br>      ports:<br>        - containerPort: 80</pre><p>The above manifest try to run a pod with an affinity to disk=hdd. But our nodes are not labeled yet, so it will be stuck in pending state.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*S5IMqD7-bDC6HXHXdzb79Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/903/1*cisO755RXjzZ-EzLcYynQQ.png" /></figure><p>Now lets label one of our node as disk=hdd.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/885/1*MJ2whv5jYb0rxYFlMC-l6g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5YSoYxXpl2xYnXvOSwcqQg.png" /></figure><p>Now we can see that once the node is labelled the pod gets scheduled and thus exits pending state for running.</p><p>Now lets understand the rule preferredDuringSchedulingIgnoredDuringExecution.</p><p>This rule allows scheduling of the pod even if the labels do not match but it first checks whether the nodes with matching labels are there or not if not it schedules the pod anyways.</p><p>Un-label the node that was labelled before.</p><pre>kubectl label node &lt;node name&gt; &lt;key of label&gt;-</pre><p>An example manifest for it.</p><pre>apiVersion: v1<br>kind: Pod<br>metadata:<br>  name: task-pod<br>  labels:<br>    app: task-pod<br>spec:<br>  affinity:<br>    nodeAffinity:<br>      preferredDuringSchedulingIgnoredDuringExecution:<br>        - weight: 1<br>          preference:<br>            matchExpressions:<br>              - key: disk<br>                operator: In<br>                values:<br>                  - hdd<br>  containers:<br>    - name: task-image<br>      image: nginx<br>      ports:<br>        - containerPort: 80</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3bKDDdbFg8CRf8JM7O90dA.png" /></figure><p>Here we can see that , how even if the nodes do not have the matching labels the property of preferredDuringSchedulingIgnoredDuringExecution schedules the pod anyway.</p><p><strong>Some more Practical Examples</strong></p><p>Let’s consider a few examples:</p><ol><li><strong>Example 1:</strong> A pod with affinity set to disk not equal to SSD will be scheduled on a node labeled disk=HDD. This is because the operator not equal to will match anything that is not SSD.</li><li><strong>Example 2:</strong> A pod with affinity set to disk in SSD or SSDandHDD can be scheduled on nodes labeled disk=SSD or disk=SSDandHDD. This shows how multiple values can be set for a given operator.</li><li><strong>Example 3:</strong> A pod with affinity set with the operator exists and key as disk type will be scheduled on nodes that have the key label with name of disk type, regardless of its value.</li><li><strong>Example 4:</strong> If a pod has requiredDuringSchedulingIgnoredDuringExecution set with affinity set as disk type in SSD, it will only get scheduled on nodes that have the label disk type with value SSD. If no node has the required label, the pod will not be scheduled and will remain in pending state.</li><li><strong>Example 5:</strong> If a pod has preferredDuringSchedulingIgnoredDuringExecution set with affinity set as disk type in SDD and the nodes do not have the specified label, it will get scheduled on any of the nodes anyway.</li></ol><p><strong>Combining Node Affinity with Taints and Tolerations</strong></p><p>To achieve precise control over pod placement, we can use node affinity alongside taints and tolerations.</p><ul><li>Taints on a node can be used to prevent general workloads from being scheduled on it.</li><li>Tolerations on a pod allow specific pods to run on the tainted node.</li><li>Affinity rules further specify which pods with the necessary toleration should be placed on the node based on node labels.</li></ul><p><strong>Use Cases</strong></p><p>Node affinity is particularly useful in scenarios such as:</p><ul><li><strong>Specialized Hardware:</strong> Scheduling GPU-intensive workloads on nodes with GPUs or high-performance workloads on nodes with SSDs.</li><li><strong>Data Locality:</strong> Ensuring that data-intensive workloads run on nodes where the necessary data is stored.</li><li><strong>Resource Isolation:</strong> Guaranteeing that certain workloads run on specific nodes to achieve isolation and performance.</li></ul><p><strong>Summary</strong></p><p>Node affinity is a powerful tool in Kubernetes that enables you to optimize resource utilization and workload performance by strategically placing pods on the most suitable nodes. By combining node affinity with taints and tolerations, you can create sophisticated scheduling rules that meet the complex requirements of your applications. Understanding the concepts behind node affinity allows you to better manage your Kubernetes deployments and ensure efficient and reliable workload execution.</p><p>Thank you for coming this far, i hope to meet you all in the next part of this article series where we will dive deeper and understand more of our container orchestration Kubernetes.</p><p>I want to thank MR. PIYUSH SACHDEVA (Youtube: Tech Tutorials with Piyush) for such an amazing explanations of these concepts.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=06d5991ee7a2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding Taints, Tolerations, and Node Selectors in Kubernetes (Article 14)]]></title>
            <link>https://medium.com/@amandevbhardwaj/understanding-taints-tolerations-and-node-selectors-in-kubernetes-article-14-8297cc72ff00?source=rss-6534ba5ab8e2------2</link>
            <guid isPermaLink="false">https://medium.com/p/8297cc72ff00</guid>
            <category><![CDATA[nodeselector]]></category>
            <category><![CDATA[taints-and-toleration]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[labels]]></category>
            <category><![CDATA[kubernetes]]></category>
            <dc:creator><![CDATA[Aman Kumar Pandey]]></dc:creator>
            <pubDate>Sat, 08 Feb 2025 19:18:30 GMT</pubDate>
            <atom:updated>2025-02-08T19:18:30.508Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AWTUYX4mICQje-sMY9J6mQ.png" /></figure><p><strong>Disclaimer : </strong><em>This article aims to dive deeper into the world of kubernetes where we discuss about taint , tolerations and node Selectors in depth. It is a continuation of the kubernetes series articles.</em></p><p>Kubernetes offers a range of powerful tools for managing where your applications run. Among these, <strong>Taints and Tolerations</strong>, and <strong>Node Selectors</strong> stand out as crucial mechanisms for controlling pod scheduling. This article will delve into these concepts, explaining their functionality and how they enhance cluster management.</p><h4><strong>Taints and Tolerations: Node-Centric Pod Scheduling</strong></h4><p>Taints and Tolerations work together to ensure that pods are scheduled on appropriate nodes. Think of a <strong>taint</strong> as a label applied to a node, indicating that it has certain properties or that it should only accept certain types of workloads. For example, you might taint a node equipped with GPUs to signify that it is best suited for AI workloads.</p><p><strong>How Taints Work:</strong> A taint is applied to a node using a key-value pair, such as GPU=true. This is an instruction to the node to only accept pods that can “tolerate” the taint.</p><ul><li><strong>Tolerations:</strong> Pods specify tolerations to indicate that they can be scheduled on nodes with matching taints. A toleration must match the taint’s key and value.</li></ul><p><strong>Effects:</strong> Tolerations also have an associated <em>effect</em> that dictates how the toleration will behave with respect to scheduling. There are three effects:</p><ul><li>NoSchedule: This effect ensures that a pod will not be scheduled on a node with the specified taint. It only affects new pods.</li><li>NoExecute: This effect not only prevents new pods from being scheduled on the node but also evicts any existing pods that do not tolerate the taint.</li><li>PreferNoSchedule: This effect tells the scheduler to try not to schedule pods on nodes with this taint, but does not guarantee it will not happen.</li></ul><p>Taints and tolerations are useful when you need to dedicate a node for a certain type of workload. Taints act as a filter, allowing you to control which pods run on each node. This is particularly helpful when you have specialized hardware or want to isolate different workloads. For example, you might want to ensure only control plane components run on control plane nodes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/970/1*-0ZuOBJi0m6TQ40cu7hgBA.png" /></figure><p>Command to taint a node.</p><pre>kubectl taint node &lt;node name&gt; key=value:&lt;policy name&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TskJu1s8Zwp9vU2Co9dGQQ.png" /></figure><p><strong>Node Selectors: Pod-Centric Node Selection</strong></p><p>Node Selectors offer a different approach to pod scheduling. Instead of the node deciding which pods it will accept, with node selectors the pods specify the node to run on. They do this by matching pod labels with node labels.</p><p><strong>Labels on Pods and Nodes:</strong> Node selectors rely on labels. These labels are key-value pairs applied to both pods and nodes.</p><p><strong>Matching:</strong> A pod specifies a node selector, which contains labels that the pod expects to find on a node. The scheduler then looks for a node that has matching labels.</p><p>Node selectors are useful when you want to ensure that certain pods are always scheduled on certain types of nodes. For example, a pod could specify a node selector of disktype=ssd, and only be scheduled on nodes labeled with disktype=ssd.</p><p><strong>Key Differences</strong></p><p>While both taints/tolerations and node selectors help control pod scheduling, their approaches are different:</p><p><strong>Taints and Tolerations are Node-Centric</strong>: The node specifies what pods it will tolerate. This approach acts like a gatekeeper that prevents certain pods from running on a specific node.</p><p><strong>Node Selectors are Pod-Centric</strong>: The pod specifies which node it prefers to run on, based on labels. This allows pods to target certain nodes.</p><p><strong>Practical Example</strong></p><p>Let’s consider an example. First, the speaker taints two worker nodes with GPU=true:NoSchedule. This means only pods with a matching toleration will be able to be scheduled on these nodes. An attempt to run an nginx pod without the toleration results in a pending pod, because it cannot be scheduled on the tainted nodes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xiseMWTcnrA0q2X1L07BPg.png" /></figure><p>We can see the reason of the pod being stuck in pending state. By describing the pod.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iGyNK-nBYNeESFGVz6eKtw.png" /></figure><p>Now if we remove the taint from one of the node we can see the pod getting scheduled and eventually in the running state.</p><pre>kubectl taint node &lt;node name&gt; key=vale:&lt;policy&gt;-<br># Remember not to put space before the hyphen.</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yjuO1IKqC_lAHIlE4bvrzg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/905/1*rtgnvgBUxZkx2HxQOpfAGA.png" /></figure><p>Now re-taint the node and try creating a new redis pod, which includes the required toleration, GPU=true:NoSchedule, in its manifest. This pod is successfully scheduled on one of the tainted nodes.</p><pre>apiVersion: v1<br>kind: Pod<br>metadata:<br>  name: mypod<br>  labels:<br>    app: myapp<br>spec:<br>  containers:<br>    - name: mycontainer<br>      image: redis<br>  tolerations:<br>    - key: gpu<br>      operator: Equal<br>      value: &#39;true&#39;<br>      effect: NoSchedule</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/824/1*LGgRRUGUXy9UQ6fEwsxlpQ.png" /></figure><p>Next, use node selectors. A pod is created with a node selector, GPU=false.</p><pre>apiVersion: v1<br>kind: Pod<br>metadata:<br>  name: task-app<br>  labels:<br>    app: task-app<br>spec:<br>  containers:<br>    - name: redis-conainer<br>      image: redis<br>  nodeSelector:<br>    gpu: &#39;false&#39;</pre><p>Because none of the nodes have the matching label, the pod stays in the pending state.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1017/1*axkrhpIXtGVBwzElI3sqtw.png" /></figure><p>Reason for being in pending state can be seen by describing the pod.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hHzpx36hTRuiORqo79cMxw.png" /></figure><p>Now label one of the node with the label gpu=false.(Do remember to un-taint the node.)</p><pre>kubectl label node &lt;node name&gt; key=value</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7rV7PkqeGh-Ax22lbmvd0w.png" /></figure><p>After adding the label GPU=false to one of the worker nodes, the pod gets scheduled.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/754/1*ED7uFaL2HKjC9zQCvemq-w.png" /></figure><p><strong>Limitations</strong></p><p>Node selectors do have limitations. You cannot use expressions, logical and or or conditions, or add more conditions. For that purpose, Kubernetes offers more advanced features called node affinity and anti-affinity, which will be covered in the future articles.</p><p><strong>Conclusion</strong></p><p>Taints and tolerations, along with node selectors, provide powerful ways to control pod scheduling in Kubernetes. Understanding these concepts allows us to fine-tune your deployments for optimal performance, resource utilization, and isolation. By combining these tools, we can create a Kubernetes environment that is both flexible and resilient.</p><p>Thank you for coming this far, i hope to meet you all in the next part of this article series where we will dive deeper and understand more of our container orchestration Kubernetes.</p><p>I want to thank MR. PIYUSH SACHDEVA (Youtube: Tech Tutorials with Piyush) for such an amazing explanations of these concepts. Gurudev❤️</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8297cc72ff00" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding Kubernetes Scheduling, Static Pods, Manual Scheduling, Labels, and Selectors…]]></title>
            <link>https://medium.com/@amandevbhardwaj/understanding-kubernetes-scheduling-static-pods-manual-scheduling-labels-and-selectors-20038ccef2ee?source=rss-6534ba5ab8e2------2</link>
            <guid isPermaLink="false">https://medium.com/p/20038ccef2ee</guid>
            <category><![CDATA[k8s]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[containers]]></category>
            <category><![CDATA[scheduler]]></category>
            <dc:creator><![CDATA[Aman Kumar Pandey]]></dc:creator>
            <pubDate>Sat, 08 Feb 2025 07:07:51 GMT</pubDate>
            <atom:updated>2025-02-08T07:07:51.541Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>Understanding Kubernetes Scheduling, Static Pods, Manual Scheduling, Labels, and Selectors (Article 13)</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AWTUYX4mICQje-sMY9J6mQ.png" /></figure><p><strong>Disclaimer : </strong><em>This article aims to dive deeper into the world of kubernetes where we discuss about scheduling, manual scheduling and will dive deeper in understanding about static pods. It is a continuation of the kubernetes series articles.</em></p><p>This article explores fundamental Kubernetes concepts, including how pods are scheduled, the nature of static pods, manual scheduling techniques, and the importance of labels and selectors in managing resources.</p><p>It is going to be fun let’s begin ……</p><p><strong>Kubernetes Scheduling: How Pods are Placed</strong></p><p>In a Kubernetes cluster, the scheduler is a crucial component responsible for deciding which node a pod should run on. When a client requests a new pod, the API server creates an entry in the etcd database. The scheduler constantly monitors pods that are yet to run and, using scheduling algorithms, determines the most suitable node for each pod. The scheduler then communicates this decision to the API server, which in turn sends a request to the kubelet on the chosen node. The kubelet then provisions the pod and reports back to the API server.</p><p><strong>Key Role of the Scheduler:</strong> The scheduler’s primary role is to assign pods to nodes, ensuring efficient resource utilization.</p><p>The scheduler itself runs as a pod within the cluster. This raises a “chicken and egg” problem: if the scheduler is a pod, <strong>what schedules the scheduler?</strong> This is where the concept of <strong>static pods</strong> comes into play.</p><h4><strong>Static Pods: Managing Control Plane Components</strong></h4><p><strong>Static pods are control plane components that are not managed by the scheduler</strong>. Instead, the <strong>kubelet</strong> is responsible for running static pods. The kubelet monitors a specific directory for pod manifests, and when it finds a manifest it will spin up the pod.</p><blockquote><strong>Kubelet is not a part of the control plane</strong>. It is a <strong>node-level component</strong> that runs on <strong>every node</strong>, including both <strong>worker nodes</strong> and <strong>control plane nodes</strong>.</blockquote><p><strong>Location of Static Pod Manifests</strong>: The default directory where these manifests are stored is /etc/kubernetes/manifests. Inside this directory, you’ll find YAML files for key control plane components like the etcd, kube-api server, kube-controller-manager, and kube-scheduler. Kubelet constantly moniters this directory.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/918/1*IPq6Z_45eWcKJpNamuHKRQ.png" /></figure><p><strong>Troubleshooting Static Pods:</strong> If a control plane component isn’t working, you can check the corresponding YAML file in this directory to troubleshoot issues.</p><p><strong>Impact of Removing a Static Pod Manifest</strong></p><p>If we remove the YAML file for a static pod, such as the kube-scheduler, the pod will stop running. The control plane won’t shut down, but critical tasks like scheduling new pods will not be performed until the manifest is restored.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/918/1*VQn4nZcGtPzBY5XjiGmSzw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/702/1*-Fgx8fDGF6bqiUvS0Ej-hw.png" /></figure><p>The new pods will stuck in pending forever until unless we bring back the manifest.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/917/1*Xssvs7rDQ9ezc132YQDOJQ.png" /><figcaption>Moving the manifest back</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/834/1*coPylsw0Cly1TyXnUZhzIw.png" /><figcaption>Pod get scheduled and thus starts running.</figcaption></figure><h4><strong>Manual Scheduling: Bypassing the Scheduler</strong></h4><p>While the scheduler typically handles pod placement, Kubernetes also allows for manual scheduling. This is achieved by specifying the nodeName field in the pod’s YAML file.</p><p><strong>How Manual Scheduling Works ?</strong></p><p>When a pod has the nodeName field specified, the scheduler skips this pod. The pod will be scheduled on the specified node by kubelet.</p><p><strong>Use Case</strong>: Manual scheduling can be useful when a user needs to place a pod on a particular node.</p><p><strong>Example</strong>: If a pod’s YAML specifies nodeName: worker-node-1, the pod will be scheduled on the node named ‘worker-node-1’, even if the scheduler is not running.</p><pre>apiVersion: v1<br>kind: Pod<br>metadata:<br>  name: my-pod<br>  labels:<br>    app: my-app<br>spec:<br>  nodeName: aman-cluster-worker<br>  containers:<br>    - name: my-container<br>      image: nginx<br>      ports:<br>        - containerPort: 80</pre><h4><strong>Labels and Selectors: Organizing and Filtering Resources</strong></h4><p><strong>Labels</strong> are key-value pairs attached to Kubernetes resources, such as pods, deployments, and services, to help organize and filter them. <strong>Selectors</strong> are used to filter and select resources based on their labels.</p><p><strong>Labels in Metadata:</strong> Labels are part of the metadata section of a Kubernetes object’s YAML file.</p><p><strong>Purpose of Labels:</strong> Labels can be used to group resources based on any criteria. For example, you might label pods with tier: frontend or tier: backend.</p><p><strong>Selectors to Filter Resources</strong>: Selectors are used to filter resources based on their labels. For example, you could use a selector to retrieve all pods with the label tier: frontend.</p><p><strong>Example</strong>: The command kubectl get pods — selector tier=frontend will return only the pods with the label tier: frontend.</p><p><strong>Use Cases</strong>: Labels and selectors help in managing and querying resources, making it easier to perform operations and generate reports8….</p><p><strong>Annotations: Storing Additional Metadata</strong></p><p><strong>Annotations</strong> are similar to labels but are used to store non-identifying metadata for a resource. Annotations are key-value pairs that store additional information related to the object.</p><p><strong>Purpose of Annotations</strong>: Unlike labels, annotations are not used for selecting or grouping resources. Instead, annotations store metadata, such as last applied configuration or creation time stamp.</p><p><strong>Labels vs. Namespaces</strong></p><p>It’s important to differentiate labels and namespaces. Namespaces provide a logical separation of resources, often used for separating development, testing, and production environments. Labels are simply tags attached to resources for identification and grouping within these namespaces.</p><p><strong>Namespaces for Logical Separation</strong>: Namespaces separate resources into distinct groups.</p><p><strong>Labels for Tagging Resources</strong>: Labels are tags added to resources, enabling selection and filtering within or across namespaces9.</p><p><strong>Analogy</strong>: Labels are like product tags on a shopping website, while namespaces are like different departments in the store.</p><p>This comprehensive overview should provide a solid understanding of how Kubernetes schedules pods, the role of static pods in managing control plane components, how to manually schedule pods, and the importance of labels and selectors in organizing and filtering Kubernetes resources.</p><p>Thank you for coming this far, i hope to meet you all in the next part of this article series where we will dive deeper and understand more of our container orchestration Kubernetes.</p><p>I want to thank MR. PIYUSH SACHDEVA (Youtube: Tech Tutorials with Piyush) for such an amazing explanations of these concepts.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=20038ccef2ee" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Kubernetes Concepts: DaemonSets, Jobs, and CronJobs (Article 12)]]></title>
            <link>https://medium.com/@amandevbhardwaj/kubernetes-concepts-daemonsets-jobs-and-cronjobs-article-12-e5628e8a24b3?source=rss-6534ba5ab8e2------2</link>
            <guid isPermaLink="false">https://medium.com/p/e5628e8a24b3</guid>
            <category><![CDATA[jobs]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[daemonset]]></category>
            <category><![CDATA[cronjob]]></category>
            <category><![CDATA[k8s]]></category>
            <dc:creator><![CDATA[Aman Kumar Pandey]]></dc:creator>
            <pubDate>Fri, 07 Feb 2025 18:20:29 GMT</pubDate>
            <atom:updated>2025-02-07T18:20:29.190Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Pa1UyKDYTooUhjpwhla-tw.png" /></figure><p><strong>Disclaimer : </strong><em>This article aims to dive deeper into the world of kubernetes where we discuss about daemonsets , cronjobs, jobs in the k8s cluster. It is a continuation of the kubernetes series articles.</em></p><p>This article will explore three key Kubernetes concepts: DaemonSets, Jobs, and CronJobs. These concepts are essential for managing different types of workloads within a Kubernetes cluster.</p><p>It will be fun let’s start …..</p><h4>DaemonSets</h4><p><strong>DaemonSets</strong> ensure that a copy of a pod runs on every node in a cluster. This is different from deployments or replica sets, where you specify the number of replicas and the scheduler places them based on resource availability.</p><h4><strong>How DaemonSets work ?</strong></h4><p>Instead of specifying a fixed number of replicas, a DaemonSet creates one pod on each node. If a new node is added to the cluster, the DaemonSet automatically creates a new pod on that node1. Conversely, if a node is removed, the corresponding pod from the DaemonSet is also removed.</p><p><strong>Use cases for DaemonSets :</strong></p><ul><li><strong>Monitoring agents</strong>: These agents need to run on every node to collect metrics.</li><li><strong>Logging agents:</strong> These agents need to run on every node to gather and stream logs.</li><li><strong>Networking components:</strong> Some networking components like kube-proxy, Weave Net, Flannel, and Calico are deployed as DaemonSets.</li><li><strong>Control plane components</strong>: Certain control plane components also need to run on all nodes.</li></ul><p><strong>Key Characteristics:</strong></p><p><strong>One pod per node:</strong> DaemonSets guarantee one instance of a pod on each node.</p><p><strong>Automatic scaling:</strong> Pods are automatically created and deleted as nodes are added or removed1.</p><p><strong>Controller Management:</strong> The DaemonSet controller ensures the correct number of pods are running. If a pod is deleted, the controller recreates it.</p><p><strong>YAML Configuration:</strong> The YAML file for a DaemonSet is similar to that of a deployment, but the replicas field is not needed. The kind is specified as DaemonSet.</p><pre>apiVersion: apps/v1<br>kind: DaemonSet<br>metadata:<br>  name: task-ds<br>  labels:<br>    env: demo<br>spec:<br>  template:<br>    metadata:<br>      name: nginx-pod<br>      labels:<br>        env: demo<br>    spec:<br>      containers:<br>        - name: nginx-pod<br>          image: nginx<br>          ports:<br>            - containerPort: 80<br>  selector:<br>    matchLabels:<br>      env: demo</pre><p>Here the example manifest creates a daemonset of a single pod running an image of nginx. Applying this manifest will create a pod on each available node in the cluster. If in future new nodes get added, then they will automatically run a pod of daemonset.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/925/1*cWg9GzUIzZuceCB3K9k9BQ.png" /></figure><p>There are three nodes running. One of them is control plane node. Control plane node can only host control plane components and thus it cannot host an external workload. If i apply the mainfest i should see two pods of the required template running as there are two nodes for workloads.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qoJIdca8vc9AnGmXFenstg.png" /></figure><p>Our daemonset has been created, now lets see the number of pods running.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/882/1*sHk86CSpcdl1eVXSXJ0N-Q.png" /></figure><pre>kubectl get daemonset</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1018/1*YdRSF5rPoW3xDn1UES96XQ.png" /></figure><h4>Jobs</h4><p><strong>Jobs</strong> are Kubernetes objects that create one or more pods to execute a task to completion. Unlike DaemonSets, Jobs are not designed to run continuously. They execute a specific task and then terminate.</p><p><strong>Use Cases:</strong></p><p><strong>Installation Scripts:</strong> Jobs are suitable for one-time execution of scripts during cluster provisioning.</p><p><strong>Automation Pipelines</strong>: They are often used to perform specific tasks as part of an automated process.</p><p><strong>Key Characteristics:</strong></p><ul><li><strong>One-time execution:</strong> Jobs run a task until it is completed.</li><li><strong>No automatic restart:</strong> Unlike deployments or DaemonSets, when a Job’s task is completed, it does not restart or recreate a pod.</li><li><strong>Part of Automation:</strong> Jobs can be integrated into automation pipelines.</li></ul><pre>apiVersion: batch/v1<br>kind: Job<br>metadata:<br>  name: simple-job<br>spec:<br>  template:<br>    metadata:<br>      labels:<br>        job: hello-job<br>    spec:<br>      restartPolicy: Never <br>      containers:<br>        - name: hello-container<br>          image: busybox <br>          command: [&#39;echo&#39;, &#39;Hello from Kubernetes Job&#39;]</pre><p>It is a simple job that runs only one time and echos Hello from the Kubernetes Job.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iDaRgTHVrL9zrY-TijLyRA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pqHkafUdL-RJaGeNCjiL5g.png" /></figure><h4>CronJobs</h4><p><strong>CronJobs</strong> are Kubernetes objects that create Jobs on a time-based schedule. They are similar to the cron utility in Unix-like systems.</p><p><strong>How CronJobs work:</strong> CronJobs use a cron syntax to define the schedule at which jobs should be created. The cron syntax specifies when the job will run, such as at a particular time or on a specific day.</p><p><strong>Cron Syntax:</strong> The cron syntax has five fields: minutes, hours, day of the month, month, and day of the week.</p><p><strong>Minutes:</strong> 0 to 59</p><p><strong>Hours:</strong> 0 to 23</p><p><strong>Day of Month:</strong> 1 to 31</p><p><strong>Month:</strong> 1 to 12</p><p><strong>Day of Week:</strong> 0 to 6 (Sunday to Saturday)</p><p><strong>Examples of Cron Syntax:</strong></p><p>* * * * 6: Runs every Saturday</p><p>* 23 * * 6: Runs every Saturday at 11:00 PM</p><p>45 23 * * 6: Runs every Saturday at 11:45 PM</p><p>*/5 * * * *: Runs every 5 minutes</p><p><strong>Use cases for CronJobs:</strong></p><ul><li><strong>Generating reports:</strong> They can be used to generate reports daily, weekly, or monthly.</li><li><strong>Cleanup tasks:</strong> CronJobs are suitable for tasks like clearing old logs on a regular schedule.</li><li><strong>YAML Configuration:</strong> A CronJob manifest specifies the schedule and the Job template that it will use to create pods. The manifest includes details such as the image, command to execute, and restart policy.</li></ul><p><strong>Example: —</strong></p><pre>apiVersion: batch/v1<br>kind: CronJob<br>metadata:<br>  name: hello-cronjob<br>spec:<br>  schedule: &#39;*/1 * * * *&#39; <br>  jobTemplate:<br>    spec:<br>      template:<br>        metadata:<br>          labels:<br>            job: hello-cronjob<br>        spec:<br>          restartPolicy: Never <br>          containers:<br>            - name: busybox-container<br>              image: busybox <br>              command:<br>                [<br>                  &#39;/bin/sh&#39;,<br>                  &#39;-c&#39;,<br>                  &#39;echo $(date) - Hello from Kubernetes cluster&#39;,<br>                ]</pre><p>That’s all from this article.</p><p>Thank you for coming this far, i hope to meet you all in the next part of this article series where we will dive deeper and understand more of our container orchestration Kubernetes.</p><p>I want to thank MR. PIYUSH SACHDEVA (Youtube: Tech Tutorials with Piyush) for such an amazing explanations of these concepts. Gurudev❤️</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e5628e8a24b3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Kubernetes Services Explained (Article 09)]]></title>
            <link>https://medium.com/@amandevbhardwaj/kubernetes-services-explained-article-09-9332bce58107?source=rss-6534ba5ab8e2------2</link>
            <guid isPermaLink="false">https://medium.com/p/9332bce58107</guid>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[k8s]]></category>
            <category><![CDATA[services]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[devops]]></category>
            <dc:creator><![CDATA[Aman Kumar Pandey]]></dc:creator>
            <pubDate>Fri, 07 Feb 2025 05:54:54 GMT</pubDate>
            <atom:updated>2025-02-07T05:54:54.304Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AWTUYX4mICQje-sMY9J6mQ.png" /></figure><p><strong>Disclaimer : </strong><em>This article aims to dive deeper into the world of kubernetes where we discuss about how can expose our application for use using NordPort and also how can we use other types of services offered in k8s to make our applications loosely coupled. It is a continuation of the kubernetes series articles.</em></p><p>In last article we discussed about how can we deploy our applications using replication controller, replicasets and deployments in k8s. Today, we will take it one step further and we will understand how we can expose our applications to the world for use. We will also understand how can we make our applications loosely coupled and explore multiple interesting concepts. Services in k8s are the topic of exploration in this article.</p><p>It is going to be fun, lets begin …..</p><p>In Kubernetes, services are essential for enabling communication between different parts of an application, and for making applications accessible to users.</p><p>Before we dive deep let’s first understand an important question.</p><h4><strong>Why Use Kubernetes Services?</strong></h4><p>There are multiple reasons behind the use of services such as : —</p><p>Kubernetes services are needed because pods, which are the basic units of deployment in Kubernetes, have IP addresses that are <strong>not static</strong>. When a pod restarts, its IP address changes. Services provide a stable way for other pods or external users to access an application without needing to know the changing IP addresses of the pods. Services also provide a way to load balance traffic across multiple pods, services also make our applications loosely coupled by providing a medium of communication between different deployments.</p><p>The types of services available in k8s are : —</p><ul><li><strong>ClusterIP</strong></li><li><strong>NodePort</strong></li><li><strong>LoadBalancer</strong></li><li><strong>ExternalName</strong>.</li></ul><p>Let’s deep dive and understand services.</p><h4><strong>NodePort</strong></h4><p>This service exposes an application on a static port on each node in the cluster. It is accessible from outside the cluster using the IP address of any node in the cluster, along with the specified <strong>nodePort</strong>.</p><p>The <strong>nodePort</strong> range is 30,000 to 32,767.</p><p>When a user accesses the application via the <strong>nodePort</strong>, the service directs the traffic to the application’s <strong>targetPort</strong>.</p><p>There is also an internal <strong>port</strong> used for communication within the cluster.</p><p>The <strong>targetPort</strong> is the port on which the application is listening.</p><blockquote>The internal <strong>port</strong> is used by other services within the cluster. If not specified, the <strong>targetPort</strong> will default to the same value as the <strong>port</strong>.</blockquote><p>The service will load balance traffic between multiple pods on a round-robin basis.</p><p><strong>Example:</strong> An external user accesses a web application on port 30,001, which is the <strong>nodePort</strong>. The service then redirects the traffic internally to the pod’s port 80, which is the <strong>targetPort</strong>.</p><p>An example manifest file for creation of a nodePort service.</p><pre>apiVersion: v1<br>kind: Service<br>metadata:<br>  name: svc-1<br>  labels:<br>    env: demo<br>spec:<br>  type: NodePort<br>  selector:<br>    env: demo<br>  ports:<br>    - nodePort: 30001<br>      port: 80<br>      targetPort: 80</pre><p>Applying this manifest will create our nodePort service and looks for the label of “env: demo” in deployments to include as a deployment under its control.</p><h4><strong>ClusterIP</strong></h4><p>This service exposes an application on an internal IP address that is only accessible within the cluster.</p><p>It is typically used to allow communication between different services within the Kubernetes cluster.</p><p>It assigns a static IP to a service that can be referred to by other pods in the cluster. The cluster IP service works on ports such as 80, 443, and other standard HTTP and HTTPS ports.</p><p>A practical demonstration of a <strong>ClusterIP</strong> service is shown using a YAML file which defines the service type as “ClusterIP” and specifies the ports and the selector.</p><p><strong>Example:</strong> A front-end application might use a <strong>ClusterIP</strong> service to access a back-end application.</p><p>An example manifest file for creation of a ClusterIP service.</p><pre>apiVersion: v1<br>kind: Service<br>metadata:<br>  name: cluster-ip-svc<br>  labels:<br>    env: demo<br>spec:<br>  type: ClusterIP<br>  ports:<br>    - targetPort: 80<br>      port: 80<br>  selector:<br>    env: demo</pre><p><strong>LoadBalancer</strong>:</p><p>This service exposes an application using an external load balancer.</p><p>It is generally used in cloud environments with cloud providers such as AWS, Azure, or GCP, where an external load balancer can be provisioned.</p><p>The service type is set to “LoadBalancer,” and Kubernetes will configure the cloud provider’s load balancer to direct traffic to the application pods. Users access the application through the load balancer’s IP or DNS name.</p><p>This type of service makes applications available externally, abstracting away the details of individual pod IP addresses.</p><p>When using a local cluster, like kind, a load balancer is not provisioned by default; therefore the service may act as a <strong>NodePort</strong> until a load balancer is set up.</p><p><strong>Example:</strong> A web application can be exposed using a load balancer to provide a single entry point for user traffic and distribute it across multiple pods.</p><p>An example manifest for a load balancer service in k8s.</p><pre>apiVersion: v1<br>kind: Service<br>metadata:<br>  name: my-app-service<br>  annotations:<br>    service.beta.kubernetes.io/aws-load-balancer-type: &quot;nlb&quot;  # Use &quot;nlb&quot; for Network Load Balancer or &quot;elb&quot; for Classic ELB<br>spec:<br>  type: LoadBalancer<br>  selector:<br>    app: my-app<br>  ports:<br>    - protocol: TCP<br>      port: 80       <br>      targetPort: 8080 </pre><p><strong>ExternalName</strong>: This service maps an internal service name to an external DNS name. It is commonly used to point to external services like databases.</p><p>Instead of selecting pods using labels, this service maps an internal name to an external service, for example, a database. The service type is set to “ExternalName” and a DNS name is provided.</p><p>This allows applications within the cluster to refer to the external service by its internal name.</p><p><strong>Example:</strong> An internal service can access an external database using the external name of the service, rather than the external database’s DNS.</p><p>An example manifest for ExternalName service</p><pre>apiVersion: v1<br>kind: Service<br>metadata:<br>  name: external-service<br>spec:<br>  type: ExternalName<br>  externalName: example.com  # Replace with the actual external hostname</pre><p><strong>Key Concepts to keep in mind.</strong></p><p><strong>Ports</strong>:</p><ul><li><strong>port</strong>: The internal port used by other services in the cluster.</li><li><strong>targetPort</strong>: The port on which the application pod is listening.</li><li><strong>nodePort</strong>: The port on which the service is exposed externally on each node.</li></ul><p><strong>Selectors</strong>: These are labels used to match services to the pods they should serve.</p><p><strong>Endpoints</strong>: These are the IP addresses of the pods that are behind a service.</p><p><strong>YAML</strong>: Kubernetes configurations, including services, are defined in YAML files.</p><p><strong>Imperative Commands</strong>: Kubernetes services can also be created using command line tools without having to create a YAML file.</p><p><strong>Important Considerations</strong></p><ul><li>The <strong>nodePort</strong> service makes applications available externally, but it can be less flexible than a <strong>LoadBalancer</strong>.</li><li>The <strong>ClusterIP</strong> service is ideal for internal communications within the cluster.</li><li>The <strong>LoadBalancer</strong> service is best suited for exposing applications to the outside world in a cloud environment.</li><li>The <strong>ExternalName</strong> service is best for using external services within the cluster.</li><li>When working with kind, an extra step is required to map the container port to the host port to expose the service externally.</li></ul><p>In summary, Kubernetes services provide a critical abstraction layer, enabling stable and scalable communication both within the cluster and with the outside world. By understanding the different types of services, you can effectively deploy and manage applications in a Kubernetes environment.</p><p>Thank you for coming this far, i hope to meet you all in the next part of this article series where we will dive deeper and understand more of our container orchestration Kubernetes.</p><p>I want to thank MR. PIYUSH SACHDEVA (Youtube: Tech Tutorials with Piyush) for such an amazing explanations of these concepts. Gurudev❤️</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9332bce58107" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>