<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Nadim Tuhin</title>
    <description>The latest articles on DEV Community by Nadim Tuhin (@nadimtuhin).</description>
    <link>https://dev.to/nadimtuhin</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F322643%2Fb13df80c-f12f-43d7-a1ba-761c828a45c6.jpeg</url>
      <title>DEV Community: Nadim Tuhin</title>
      <link>https://dev.to/nadimtuhin</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/nadimtuhin"/>
    <language>en</language>
    <item>
      <title>Setting Up Liveness and Readiness Probes in a Kubernetes Deployment</title>
      <dc:creator>Nadim Tuhin</dc:creator>
      <pubDate>Thu, 12 Oct 2023 23:17:07 +0000</pubDate>
      <link>https://dev.to/nadimtuhin/setting-up-liveness-and-readiness-probes-in-a-kubernetes-deployment-48pp</link>
      <guid>https://dev.to/nadimtuhin/setting-up-liveness-and-readiness-probes-in-a-kubernetes-deployment-48pp</guid>
      <description>&lt;p&gt;Ensuring that your application is running smoothly and is ready to handle requests is a crucial aspect of deploying services in a Kubernetes cluster. This is where liveness and readiness probes come in. These probes allow Kubernetes to determine the health of your pods and take action if something isn't right. Let's delve into how to set up these probes in a Kubernetes deployment.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;1. Why are Probes Important?&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Liveness Probe:&lt;/strong&gt; Checks if the container in which it is configured is still running. If the liveness probe fails, the kubelet kills the container, and the container is subjected to its restart policy.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Readiness Probe:&lt;/strong&gt; Determines if a container is ready to accept requests. If a container fails its readiness probe, it is removed from service load balancers. Once it passes, it can start accepting traffic.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;2. Configuring Liveness Probes&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Here's a simple example of setting up a liveness probe for a deployment:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;apiVersion&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;v1&lt;/span&gt;
&lt;span class="na"&gt;kind&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Pod&lt;/span&gt;
&lt;span class="na"&gt;metadata&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;liveness-pod&lt;/span&gt;
&lt;span class="na"&gt;spec&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;containers&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;my-container&lt;/span&gt;
    &lt;span class="na"&gt;image&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;my-image&lt;/span&gt;
    &lt;span class="na"&gt;livenessProbe&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;httpGet&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
        &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;/healthz&lt;/span&gt;
        &lt;span class="na"&gt;port&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="m"&gt;8080&lt;/span&gt;
      &lt;span class="na"&gt;initialDelaySeconds&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="m"&gt;3&lt;/span&gt;
      &lt;span class="na"&gt;periodSeconds&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="m"&gt;3&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;strong&gt;3. Configuring Readiness Probes&lt;/strong&gt;
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;apiVersion&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;v1&lt;/span&gt;
&lt;span class="na"&gt;kind&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Pod&lt;/span&gt;
&lt;span class="na"&gt;metadata&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;readiness-pod&lt;/span&gt;
&lt;span class="na"&gt;spec&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;containers&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;my-container&lt;/span&gt;
    &lt;span class="na"&gt;image&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;my-image&lt;/span&gt;
    &lt;span class="na"&gt;readinessProbe&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;httpGet&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
        &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;/readiness&lt;/span&gt;
        &lt;span class="na"&gt;port&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="m"&gt;8080&lt;/span&gt;
      &lt;span class="na"&gt;initialDelaySeconds&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="m"&gt;5&lt;/span&gt;
      &lt;span class="na"&gt;periodSeconds&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="m"&gt;5&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;strong&gt;4. Types of Probes&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;HTTP Checks:&lt;/strong&gt; Uses the &lt;code&gt;httpGet&lt;/code&gt; field.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;TCP Checks:&lt;/strong&gt; Utilizes the &lt;code&gt;tcpSocket&lt;/code&gt; field.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Exec Checks:&lt;/strong&gt; Executes a command inside the container using the &lt;code&gt;exec&lt;/code&gt; field.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;5. Fine-tuning Your Probes&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;initialDelaySeconds&lt;/code&gt;:&lt;/strong&gt; This gives your container some time to start.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;periodSeconds&lt;/code&gt;:&lt;/strong&gt; Defines how often to run the probe.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;timeoutSeconds&lt;/code&gt;:&lt;/strong&gt; Number of seconds after which the probe times out.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;successThreshold&lt;/code&gt;:&lt;/strong&gt; Minimum consecutive successes for the probe to be considered successful.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;failureThreshold&lt;/code&gt;:&lt;/strong&gt; When a probe fails, Kubernetes will try &lt;code&gt;failureThreshold&lt;/code&gt; times before giving up.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;6. Best Practices:&lt;/strong&gt;
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Understand Your Application:&lt;/strong&gt; Ensure you understand your application's startup and normal behaviors.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Avoid Long Delays:&lt;/strong&gt; If your liveness probe takes too long to become healthy, consider making your application start faster.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Be Careful with Liveness Probes:&lt;/strong&gt; A misconfigured liveness probe can lead to frequent restarts.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Feedback Loop:&lt;/strong&gt; Use readiness probes to help Kubernetes make informed decisions on routing traffic.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Network Dependencies:&lt;/strong&gt; Avoid using a URL of another service in your liveness probe.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;7. Common Pitfalls:&lt;/strong&gt;
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Over-relying on Liveness Probes:&lt;/strong&gt; A frequently firing liveness probe can result in constant pod restarts, leading to application instability.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Not Giving Enough Start Time:&lt;/strong&gt; Setting an initial delay that's too short can falsely report a pod as unhealthy during its normal startup sequence.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Ignoring Application State:&lt;/strong&gt; If the application needs some time to process data before it can be considered "ready", but the readiness probe doesn't account for this, it can lead to issues.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Complex Commands in Exec Probes:&lt;/strong&gt; Running complex commands in &lt;code&gt;exec&lt;/code&gt; probes can inadvertently introduce issues. Keep these checks simple and predictable.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Using Liveness Probe Instead of Readiness:&lt;/strong&gt; A liveness probe restarts the pod when it fails, while a readiness probe simply marks it as 'unready'. Misusing them can lead to unwanted pod restarts.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Ignoring Probe Failures:&lt;/strong&gt; Not monitoring or alerting on frequent probe failures can leave you in the dark about potential issues.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Setting Tight Timelines:&lt;/strong&gt; Having a short &lt;code&gt;timeoutSeconds&lt;/code&gt; or a low &lt;code&gt;failureThreshold&lt;/code&gt; can lead to premature pod terminations or removal from service.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In conclusion, liveness and readiness probes are essential tools in Kubernetes for ensuring application health and availability. Properly understanding, implementing, and avoiding common pitfalls with these probes will significantly enhance the robustness of your deployments.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>How to Fix a Pod in `CrashLoopBackOff` State: A Practical Guide</title>
      <dc:creator>Nadim Tuhin</dc:creator>
      <pubDate>Thu, 12 Oct 2023 23:10:05 +0000</pubDate>
      <link>https://dev.to/nadimtuhin/how-to-fix-a-pod-in-crashloopbackoff-state-a-practical-guide-1433</link>
      <guid>https://dev.to/nadimtuhin/how-to-fix-a-pod-in-crashloopbackoff-state-a-practical-guide-1433</guid>
      <description>&lt;p&gt;One of the common issues you may encounter when working with Kubernetes is seeing a pod stuck in the &lt;code&gt;CrashLoopBackOff&lt;/code&gt; state. This state indicates that one or more of the containers within the pod are repeatedly crashing after being restarted by Kubernetes. Let's delve into the steps you can take to diagnose and resolve this issue.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;1. Understand the CrashLoopBackOff State&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;A &lt;code&gt;CrashLoopBackOff&lt;/code&gt; state means that a container in the pod is repeatedly failing to start and is therefore being restarted by Kubernetes. After multiple failures, Kubernetes applies an increasing back-off delay before trying to restart the container again.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;2. Check the Pod Logs&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;The first step in troubleshooting should be to check the logs of the crashing container:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;kubectl logs &amp;lt;pod-name&amp;gt; &lt;span class="nt"&gt;-c&lt;/span&gt; &amp;lt;container-name&amp;gt; &lt;span class="nt"&gt;--previous&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command displays logs from the previously crashed instance of the container, which should give you insights into why the container terminated unexpectedly.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;3. Describe the Pod&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Describing the pod can provide additional details, including events and configuration:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;kubectl describe pod &amp;lt;pod-name&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Look for any events or messages that might indicate what's wrong, such as out-of-memory errors, mounting issues, or image pull errors.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;4. Verify Your Pod's Configuration&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Configuration errors can often be the culprit. Here are a few areas to check:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Command and Arguments:&lt;/strong&gt; Ensure that the command and arguments (if specified) in your pod's spec are correct.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Environment Variables:&lt;/strong&gt; Incorrect environment variable values or missing environment variables required by the application can cause crashes.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Resource Limits:&lt;/strong&gt; Ensure that the CPU and memory limits are appropriately set. A pod may crash if it consumes all its allocated memory.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;5. Check for Persistent Volume Issues&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;If your pod mounts a persistent volume, ensure:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The volume can be correctly mounted and is accessible.&lt;/li&gt;
&lt;li&gt;Permissions are set correctly for any data or directories the container accesses.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;6. Review Application Configuration&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Configuration issues within the application itself can also lead to crashes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Ensure that application configuration files are correct and available.&lt;/li&gt;
&lt;li&gt;Check for missing required data or misconfigurations.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;7. Inspect Application Dependencies&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Ensure that all external services or databases the application relies on are available and operational. Connectivity issues can sometimes be the reason for crashes.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;8. Verify the Image&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Ensure you are using the correct image and tag.&lt;/li&gt;
&lt;li&gt;Check if the image might be corrupt. Consider pulling it locally and running it outside Kubernetes to see if it behaves as expected.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;9. Update or Rollback&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;If you've recently made changes, consider rolling back to a previous, known-working state. If that's not possible, try updating to a newer version if available.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;10. External Tools and Monitoring&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Integrate with tools like &lt;a href="https://prometheus.io/"&gt;Prometheus&lt;/a&gt; for monitoring and &lt;a href="https://grafana.com/oss/loki/"&gt;Loki&lt;/a&gt; for centralized logging. These tools can offer deeper insights into pod behavior and help pinpoint issues.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Best Practices:&lt;/strong&gt;
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Regularly Monitor Logs:&lt;/strong&gt; Even when things are operating normally, regularly checking logs can help identify issues before they become critical.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Health Checks:&lt;/strong&gt; Implement and use liveness and readiness probes. They can help detect and resolve issues before they escalate to crashes.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Automated Testing:&lt;/strong&gt; Ensure that your container images are tested automatically for basic functionality before they're deployed.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Resource Monitoring:&lt;/strong&gt; Monitor the resource usage of your pods and adjust limits and requests as needed to prevent out-of-resource crashes.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In conclusion, a &lt;code&gt;CrashLoopBackOff&lt;/code&gt; state often requires a mix of Kubernetes and application-specific troubleshooting. By systematically working through the potential causes and utilizing the rich set of tools Kubernetes provides, you can resolve the issues and ensure the smooth operation of your applications.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>How to Check Logs of a Kubernetes Pod: A Comprehensive Guide</title>
      <dc:creator>Nadim Tuhin</dc:creator>
      <pubDate>Thu, 12 Oct 2023 23:06:18 +0000</pubDate>
      <link>https://dev.to/nadimtuhin/how-to-check-logs-of-a-kubernetes-pod-a-comprehensive-guide-5c8e</link>
      <guid>https://dev.to/nadimtuhin/how-to-check-logs-of-a-kubernetes-pod-a-comprehensive-guide-5c8e</guid>
      <description>&lt;p&gt;When running applications within a Kubernetes cluster, having access to and understanding logs is crucial for both troubleshooting and monitoring the health of your applications. In Kubernetes, each pod's logs provide a window into the behavior and activity of the applications running within that pod. Here's a comprehensive guide on how to check the logs of a Kubernetes pod.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;1. Basics of Accessing Pod Logs&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;To view the logs for a pod:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;kubectl logs &amp;lt;pod-name&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will display the logs of the default container within the specified pod.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;2. Accessing Logs from Specific Containers&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;If a pod has multiple containers, specify which container's logs you want to access:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;kubectl logs &amp;lt;pod-name&amp;gt; &lt;span class="nt"&gt;-c&lt;/span&gt; &amp;lt;container-name&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;strong&gt;3. Streaming Pod Logs&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;To stream logs in real-time:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;kubectl logs &lt;span class="nt"&gt;-f&lt;/span&gt; &amp;lt;pod-name&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;-f&lt;/code&gt; or &lt;code&gt;--follow&lt;/code&gt; flag allows you to view new log messages as they appear.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;4. Viewing Previous Logs of a Pod&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;If a container has crashed and restarted, you might want to view the logs from the previous instance of the container:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;kubectl logs &amp;lt;pod-name&amp;gt; &lt;span class="nt"&gt;-c&lt;/span&gt; &amp;lt;container-name&amp;gt; &lt;span class="nt"&gt;--previous&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;strong&gt;5. Accessing Logs from Pods in a Specific Namespace&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;By default, &lt;code&gt;kubectl logs&lt;/code&gt; searches for pods in the &lt;code&gt;default&lt;/code&gt; namespace. To access logs from a pod in a different namespace:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;kubectl logs &amp;lt;pod-name&amp;gt; &lt;span class="nt"&gt;-n&lt;/span&gt; &amp;lt;namespace-name&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;strong&gt;6. Using Labels to Filter Pods&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;If you've labeled your pods, you can use label selectors to filter which pod logs you want to view. For example, if you have a label &lt;code&gt;app=myApp&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;kubectl logs &lt;span class="nt"&gt;-l&lt;/span&gt; &lt;span class="nv"&gt;app&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;myApp
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will show logs from the default container of all pods with the label &lt;code&gt;app=myApp&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;7. Accessing Logs from Completed Pods (Jobs and CronJobs)&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;For pods that run to completion (like Jobs), you can still access their logs even after they've completed:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;kubectl logs &amp;lt;job-pod-name&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;strong&gt;8. Using Stern for Advanced Log Tailoring&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://github.com/stern/stern"&gt;Stern&lt;/a&gt; is a tool that allows for tailing Kubernetes logs from multiple pods and containers with added features like color coding and pattern matching. Once installed, you can tail logs like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;stern &lt;span class="nt"&gt;-n&lt;/span&gt; &amp;lt;namespace-name&amp;gt; &amp;lt;pod-name-pattern&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;strong&gt;9. Storing and Accessing Logs Outside of Kubernetes&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;For long-term log storage, analysis, and more advanced querying, consider integrating Kubernetes with a centralized logging solution like ELK Stack (Elasticsearch, Logstash, Kibana), Loki, or Fluentd.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Best Practices:&lt;/strong&gt;
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Centralized Logging:&lt;/strong&gt; Always consider having a centralized logging solution in place. It aids in long-term storage, querying, and analysis.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Log Rotation:&lt;/strong&gt; Ensure that your applications and nodes handle log rotation to prevent them from consuming all available storage.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Structured Logging:&lt;/strong&gt; Whenever possible, write logs in a structured format like JSON. It makes parsing and querying logs much easier in centralized logging systems.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Logging Levels:&lt;/strong&gt; Make use of logging levels (INFO, WARN, ERROR, etc.) to categorize the importance and severity of log messages.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In conclusion, logs are an indispensable tool in the toolkit of anyone managing or debugging applications in Kubernetes. Whether you're diagnosing a tricky issue or monitoring routine operations, understanding how to access and interpret pod logs is essential.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Debugging Kubernetes Pods: A Step-by-Step Guide</title>
      <dc:creator>Nadim Tuhin</dc:creator>
      <pubDate>Thu, 12 Oct 2023 23:03:09 +0000</pubDate>
      <link>https://dev.to/nadimtuhin/debugging-kubernetes-pods-a-step-by-step-guide-133l</link>
      <guid>https://dev.to/nadimtuhin/debugging-kubernetes-pods-a-step-by-step-guide-133l</guid>
      <description>&lt;p&gt;Kubernetes pods are fundamental to applications deployed on the platform. But when things go wrong, debugging can be a challenge, especially in a system as complex as Kubernetes. This article provides a structured approach to troubleshoot and debug common issues with Kubernetes pods.&lt;/p&gt;

&lt;h3&gt;
  
  
  1. &lt;strong&gt;Understanding Pod Status&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;First, understand the current status of the pod:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;kubectl get pods &lt;span class="nt"&gt;-n&lt;/span&gt; &amp;lt;namespace&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You might encounter states like &lt;code&gt;Pending&lt;/code&gt;, &lt;code&gt;Running&lt;/code&gt;, &lt;code&gt;CrashLoopBackOff&lt;/code&gt;, &lt;code&gt;ImagePullBackOff&lt;/code&gt;, among others. Each status provides a clue about the underlying issue.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. &lt;strong&gt;Describing the Pod&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;describe&lt;/code&gt; command gives a detailed view of the pod, including events and configuration:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;kubectl describe pod &amp;lt;pod-name&amp;gt; &lt;span class="nt"&gt;-n&lt;/span&gt; &amp;lt;namespace&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Inspect the events at the bottom of the output; they often provide insights into what's wrong.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. &lt;strong&gt;Inspecting Pod Logs&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Logs provide crucial insights into application behavior:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;kubectl logs &amp;lt;pod-name&amp;gt; &lt;span class="nt"&gt;-n&lt;/span&gt; &amp;lt;namespace&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For pods with multiple containers:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;kubectl logs &amp;lt;pod-name&amp;gt; &lt;span class="nt"&gt;-c&lt;/span&gt; &amp;lt;container-name&amp;gt; &lt;span class="nt"&gt;-n&lt;/span&gt; &amp;lt;namespace&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  4. &lt;strong&gt;Exec into the Pod&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;You can access the pod's shell, provided the container has one:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;kubectl &lt;span class="nb"&gt;exec&lt;/span&gt; &lt;span class="nt"&gt;-it&lt;/span&gt; &amp;lt;pod-name&amp;gt; &lt;span class="nt"&gt;-n&lt;/span&gt; &amp;lt;namespace&amp;gt; &lt;span class="nt"&gt;--&lt;/span&gt; /bin/sh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This gives a direct look inside the container and allows you to run diagnostic commands.&lt;/p&gt;

&lt;h3&gt;
  
  
  5. &lt;strong&gt;Checking Resource Quotas&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Ensure that the pod isn't exceeding its resource quotas:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;kubectl describe ns &amp;lt;namespace&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Look for sections like &lt;code&gt;Resource Quotas&lt;/code&gt; and &lt;code&gt;Resource Limits&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  6. &lt;strong&gt;Liveness and Readiness Probes&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Misconfigured probes can cause pods to restart frequently. Ensure that liveness and readiness probes are set up correctly and are pointing to the right endpoints with appropriate timeouts.&lt;/p&gt;

&lt;h3&gt;
  
  
  7. &lt;strong&gt;Image Issues&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Ensure that:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The image name and tag are correct.&lt;/li&gt;
&lt;li&gt;The image is accessible, and credentials are set up if it's in a private registry.&lt;/li&gt;
&lt;li&gt;The node has enough disk space to pull the image.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  8. &lt;strong&gt;Network Troubleshooting&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;If your pod isn't reachable:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Check network policies.&lt;/li&gt;
&lt;li&gt;Ensure services and ingress controllers are correctly set up.&lt;/li&gt;
&lt;li&gt;Use tools like &lt;code&gt;nslookup&lt;/code&gt; and &lt;code&gt;curl&lt;/code&gt; inside the pod to check connectivity.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  9. &lt;strong&gt;Using Debug Containers&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Introduced as an alpha feature in Kubernetes 1.18, debug containers provide a temporary container for debugging in a running pod:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;kubectl alpha debug &lt;span class="nt"&gt;-it&lt;/span&gt; &amp;lt;pod-name&amp;gt; &lt;span class="nt"&gt;--image&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&amp;lt;debug-image&amp;gt; &lt;span class="nt"&gt;--&lt;/span&gt; &amp;lt;&lt;span class="nb"&gt;command&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Best Practices:
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Always Monitor:&lt;/strong&gt; Tools like Prometheus and Grafana can offer insights before issues become critical.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Limit Privileges:&lt;/strong&gt; Run containers with the least privilege necessary; this reduces the potential impact of issues.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Use Linting Tools:&lt;/strong&gt; Tools like &lt;a href="https://kubeval.instrumenta.dev/"&gt;kubeval&lt;/a&gt; or &lt;a href="https://kube-score.com/"&gt;kube-score&lt;/a&gt; can validate configurations, highlighting potential issues before deployment.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In conclusion, debugging Kubernetes pods requires a combination of understanding Kubernetes constructs, monitoring, and hands-on troubleshooting techniques. With methodical investigation and the right tools, you can diagnose and resolve most pod-related issues efficiently.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Debugging NGINX Ingress Controller: A Comprehensive Guide</title>
      <dc:creator>Nadim Tuhin</dc:creator>
      <pubDate>Thu, 12 Oct 2023 23:00:12 +0000</pubDate>
      <link>https://dev.to/nadimtuhin/debugging-nginx-ingress-controller-a-comprehensive-guide-4m26</link>
      <guid>https://dev.to/nadimtuhin/debugging-nginx-ingress-controller-a-comprehensive-guide-4m26</guid>
      <description>&lt;p&gt;The NGINX Ingress Controller is a vital tool for managing access to services within a Kubernetes cluster. But as with all complex systems, things might not always work as expected. Debugging can be challenging, especially when you're not sure where to start. This article offers a systematic approach to troubleshooting common issues with the NGINX Ingress Controller.&lt;/p&gt;

&lt;h3&gt;
  
  
  1. &lt;strong&gt;Check the Basics&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Ensure the Ingress Controller is running: &lt;code&gt;kubectl get pods -n &amp;lt;namespace-of-ingress-controller&amp;gt;&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Check the status of the Ingress resources: &lt;code&gt;kubectl get ingress -n &amp;lt;namespace-of-the-app&amp;gt;&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Verify that services referenced in your Ingress are up and running.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  2. &lt;strong&gt;NGINX Ingress Logs&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Logs are invaluable for debugging. There are two types of logs to consider:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;a. Controller Logs:&lt;/strong&gt; Show how the Ingress rules are being transformed into NGINX configurations.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;kubectl logs &amp;lt;nginx-controller-pod-name&amp;gt; &lt;span class="nt"&gt;-n&lt;/span&gt; &amp;lt;namespace-of-ingress-controller&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;b. Access Logs:&lt;/strong&gt; Display all the HTTP requests that the Ingress Controller processes.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;kubectl logs &lt;span class="nt"&gt;-f&lt;/span&gt; &amp;lt;nginx-controller-pod-name&amp;gt; &lt;span class="nt"&gt;-n&lt;/span&gt; &amp;lt;namespace-of-ingress-controller&amp;gt; | &lt;span class="nb"&gt;grep&lt;/span&gt; &lt;span class="s1"&gt;'upstreamAddress'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  3. &lt;strong&gt;Describing Resources&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Using the &lt;code&gt;describe&lt;/code&gt; command can provide insights into potential misconfigurations:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;kubectl describe ingress &amp;lt;ingress-name&amp;gt; &lt;span class="nt"&gt;-n&lt;/span&gt; &amp;lt;namespace&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command might provide warnings or events that highlight issues with the Ingress configuration.&lt;/p&gt;

&lt;h3&gt;
  
  
  4. &lt;strong&gt;Using &lt;code&gt;nginx-ingress-controller&lt;/code&gt; Debug Mode&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Increasing the verbosity of the Ingress Controller logs can give more detailed information:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Edit the deployment of the NGINX Ingress Controller.&lt;/li&gt;
&lt;li&gt;Add &lt;code&gt;--v=5&lt;/code&gt; to the args section (the number represents the level of log verbosity).&lt;/li&gt;
&lt;li&gt;Save and exit.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  5. &lt;strong&gt;Examine the Generated NGINX Configuration&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;You can inspect the actual NGINX configuration generated by the Ingress Controller:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;kubectl &lt;span class="nb"&gt;exec&lt;/span&gt; &lt;span class="nt"&gt;-it&lt;/span&gt; &amp;lt;nginx-controller-pod-name&amp;gt; &lt;span class="nt"&gt;-n&lt;/span&gt; &amp;lt;namespace-of-ingress-controller&amp;gt; &lt;span class="nt"&gt;--&lt;/span&gt; &lt;span class="nb"&gt;cat&lt;/span&gt; /etc/nginx/nginx.conf
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  6. &lt;strong&gt;Check for Annotation Errors&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Misconfigured or unsupported annotations can cause unexpected behavior. Cross-check with the &lt;a href="https://kubernetes.github.io/ingress-nginx/user-guide/nginx-configuration/annotations/"&gt;official documentation&lt;/a&gt; to ensure correctness.&lt;/p&gt;

&lt;h3&gt;
  
  
  7. &lt;strong&gt;External Tools and Plugins&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Using tools like &lt;a href="https://kubeval.instrumenta.dev/"&gt;kubeval&lt;/a&gt; can validate your Kubernetes configuration files against the relevant schema, ensuring structural correctness.&lt;/p&gt;

&lt;h3&gt;
  
  
  8. &lt;strong&gt;Network Policies and Firewalls&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Sometimes the problem isn't with the Ingress Controller but with network policies or cloud-provider firewalls blocking traffic. Ensure that the necessary ports are open and that network policies allow traffic between the Ingress Controller and backend services.&lt;/p&gt;

&lt;h3&gt;
  
  
  Best Practices:
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Keep Documentation Handy:&lt;/strong&gt; Always have the &lt;a href="https://kubernetes.github.io/ingress-nginx/"&gt;official NGINX Ingress documentation&lt;/a&gt; accessible.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Stay Updated:&lt;/strong&gt; Ensure you're using a recent version of the NGINX Ingress Controller. Updates often contain bug fixes and performance improvements.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Isolation:&lt;/strong&gt; When introducing new changes, do so incrementally. This way, if an issue arises, it's easier to pinpoint the cause.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In conclusion, debugging the NGINX Ingress Controller requires a systematic approach, from examining logs to verifying configurations and checking external systems. With patience and practice, you'll become adept at quickly identifying and resolving issues.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Setting Up URL Whitelisting and Custom Configurations in NGINX Ingress Controller</title>
      <dc:creator>Nadim Tuhin</dc:creator>
      <pubDate>Thu, 12 Oct 2023 22:56:37 +0000</pubDate>
      <link>https://dev.to/nadimtuhin/setting-up-url-whitelisting-and-custom-configurations-in-nginx-ingress-controller-31gi</link>
      <guid>https://dev.to/nadimtuhin/setting-up-url-whitelisting-and-custom-configurations-in-nginx-ingress-controller-31gi</guid>
      <description>&lt;p&gt;The NGINX Ingress Controller for Kubernetes provides a powerful way to manage external access to services within a Kubernetes cluster. This article delves into how you can set up URL whitelisting, and customize configurations using annotations and the &lt;code&gt;configuration-snippet&lt;/code&gt; in the NGINX Ingress Controller. We will also touch on some best practices to ensure smooth operation.&lt;/p&gt;

&lt;h3&gt;
  
  
  1. &lt;strong&gt;URL Whitelisting Using Ingress Annotations&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;What is URL Whitelisting?&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
URL whitelisting is a security mechanism to ensure that only specific, allowed IP addresses can access certain parts or all of your applications.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How to Set Up URL Whitelisting:&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
To restrict access to services based on the source IP, use the &lt;code&gt;nginx.ingress.kubernetes.io/whitelist-source-range&lt;/code&gt; annotation:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;apiVersion&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;networking.k8s.io/v1&lt;/span&gt;
&lt;span class="na"&gt;kind&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Ingress&lt;/span&gt;
&lt;span class="na"&gt;metadata&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;annotations&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;nginx.ingress.kubernetes.io/whitelist-source-range&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;&amp;lt;allowed-ips&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Replace &lt;code&gt;&amp;lt;allowed-ips&amp;gt;&lt;/code&gt; with a comma-separated list of the IP addresses you wish to whitelist.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. &lt;strong&gt;Update Configuration Using Annotations&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Annotations in the Ingress resource allow for custom behavior of traffic routing. For instance, you can increase the client body size limit, enabling the upload of larger files through a POST request:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;metadata&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;annotations&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;nginx.ingress.kubernetes.io/proxy-body-size&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;8m"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  3. &lt;strong&gt;Update Configuration Using &lt;code&gt;configuration-snippet&lt;/code&gt;&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;configuration-snippet&lt;/code&gt; annotation is particularly powerful. It allows you to add custom NGINX configuration directives to be applied to the location block of the Ingress resource:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;metadata&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;annotations&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;nginx.ingress.kubernetes.io/configuration-snippet&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;|&lt;/span&gt;
      &lt;span class="s"&gt;proxy_set_header Host $host;&lt;/span&gt;
      &lt;span class="s"&gt;proxy_pass_header Server;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The above snippet ensures that the original 'Host' header is passed to the proxied service and also retains the 'Server' header from the backend service in the response.&lt;/p&gt;

&lt;h3&gt;
  
  
  4. &lt;strong&gt;Best Practices&lt;/strong&gt;
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Validation&lt;/strong&gt;: Before applying any custom configurations, ensure you validate your configurations locally using an NGINX configuration tester.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Staging&lt;/strong&gt;: Always deploy configuration changes first to a staging environment. This helps in identifying potential issues without affecting the production environment.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Monitoring and Logging&lt;/strong&gt;: Monitor the Ingress controller logs for any configuration errors or warnings. Tools like Prometheus can be integrated with the NGINX Ingress Controller to monitor its metrics.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Documentation&lt;/strong&gt;: Always document changes made to the Ingress configurations. This ensures any team member can understand and follow the reasoning behind configurations, and also makes rollbacks easier in case of issues.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Limit the use of &lt;code&gt;configuration-snippet&lt;/code&gt;&lt;/strong&gt;: While powerful, the &lt;code&gt;configuration-snippet&lt;/code&gt; annotation should be used judiciously. Overuse can lead to cluttered and complex configurations that are hard to manage and debug.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Centralized Configurations&lt;/strong&gt;: Consider using a central ConfigMap for frequently used configurations, which can then be referenced in multiple Ingress resources.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Debugging&lt;/strong&gt;: Always check the Ingress controller's logs if something doesn't seem right. This can provide clues to misconfigurations or other issues.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Test Before Applying: If possible, test new configurations in a staging environment before applying them to production.&lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;The NGINX Ingress Controller provides a flexible and feature-rich method to control the ingress traffic in a Kubernetes cluster. Using URL whitelisting, annotations, and the &lt;code&gt;configuration-snippet&lt;/code&gt;, you can fine-tune your traffic management needs. Following best practices ensures a seamless and error-free experience. Remember, with great power comes great responsibility, so use these features wisely!&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Understanding and Debugging NGINX Ingress Controller in Kubernetes</title>
      <dc:creator>Nadim Tuhin</dc:creator>
      <pubDate>Thu, 12 Oct 2023 22:40:45 +0000</pubDate>
      <link>https://dev.to/nadimtuhin/understanding-and-debugging-nginx-ingress-controller-in-kubernetes-c4j</link>
      <guid>https://dev.to/nadimtuhin/understanding-and-debugging-nginx-ingress-controller-in-kubernetes-c4j</guid>
      <description>&lt;p&gt;If you're familiar with NGINX, you know it's a powerful web server, reverse proxy, and load balancer. Within a Kubernetes cluster, the NGINX Ingress controller plays a similar role but with additional Kubernetes-specific features. This article will bridge your knowledge from standalone NGINX to the Kubernetes NGINX Ingress controller.&lt;/p&gt;

&lt;h3&gt;
  
  
  1. &lt;strong&gt;What is an Ingress Controller?&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;In Kubernetes, an Ingress controller is responsible for fulfilling the Ingress resources' rules, usually by managing a load balancer or a reverse proxy. The NGINX Ingress controller uses NGINX as a reverse proxy and load balancer.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. &lt;strong&gt;How NGINX Ingress Controller Works&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;When you deploy the NGINX Ingress controller, it creates a Pod that runs the NGINX web server. This controller actively watches for Ingress resources and translates them into an NGINX configuration, automatically reloading NGINX when changes occur.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. &lt;strong&gt;Key Differences Between Standalone NGINX and NGINX Ingress Controller&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Configuration Management&lt;/strong&gt;: Instead of editing &lt;code&gt;nginx.conf&lt;/code&gt; directly, configurations are managed via Kubernetes Ingress resources and annotations.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Auto-reloading&lt;/strong&gt;: The controller auto-reloads NGINX when Ingress resources or relevant ConfigMaps change.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Enhanced Metrics&lt;/strong&gt;: The controller can be integrated with Prometheus for rich metrics and monitoring.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  4. &lt;strong&gt;Managing Configurations&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Annotations&lt;/strong&gt;: Enhance the behavior of your Ingress resources using annotations, like redirecting, rewriting, or setting up authentication.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;ConfigMaps&lt;/strong&gt;: For global configurations, use a ConfigMap that the NGINX Ingress controller watches.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  5. &lt;strong&gt;Debugging &amp;amp; Troubleshooting&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;a. Check NGINX Configuration&lt;/strong&gt;&lt;br&gt;
After applying your Ingress rules or annotations, you might want to see the actual NGINX configuration:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;kubectl &lt;span class="nb"&gt;exec&lt;/span&gt; &lt;span class="nt"&gt;-it&lt;/span&gt; &amp;lt;NGINX-Ingress-Pod-Name&amp;gt; &lt;span class="nt"&gt;-n&lt;/span&gt; &amp;lt;Namespace&amp;gt; &lt;span class="nt"&gt;--&lt;/span&gt; &lt;span class="nb"&gt;cat&lt;/span&gt; /etc/nginx/nginx.conf
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;b. Check Controller Logs&lt;/strong&gt;&lt;br&gt;
Logs are invaluable when troubleshooting. You can view them with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;kubectl logs &amp;lt;NGINX-Ingress-Pod-Name&amp;gt; &lt;span class="nt"&gt;-n&lt;/span&gt; &amp;lt;Namespace&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;c. Test Configuration Changes&lt;/strong&gt;&lt;br&gt;
Before applying changes cluster-wide, you can dry-run and check the configuration:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;kubectl ingress-nginx &lt;span class="nt"&gt;--namespace&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&amp;lt;Namespace&amp;gt; &lt;span class="nt"&gt;--dry-run&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;client &lt;span class="nt"&gt;-o&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;json path/to/your-ingress.yaml
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;d. Use Debug Mode&lt;/strong&gt;&lt;br&gt;
If you're facing complex issues, consider turning on the debug mode:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;kubectl &lt;span class="nb"&gt;set env &lt;/span&gt;deployment/&amp;lt;NGINX-Ingress-Controller-Name&amp;gt; &lt;span class="nt"&gt;-n&lt;/span&gt; &amp;lt;Namespace&amp;gt; &lt;span class="nv"&gt;POD_DEBUG&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nb"&gt;true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  6. &lt;strong&gt;Best Practices&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Keep Resources Organized&lt;/strong&gt;: Place Ingress resources in the same namespace as the services they route to.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Use Specific Annotations&lt;/strong&gt;: Instead of bloating with too many annotations, create multiple Ingress resources.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Monitor &amp;amp; Alert&lt;/strong&gt;: Integrate with monitoring solutions like Prometheus and Grafana.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  7. &lt;strong&gt;Conclusion&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Transitioning from standalone NGINX to the NGINX Ingress controller is straightforward when understanding the Kubernetes layer added on top. With the combination of Ingress resources, annotations, and ConfigMaps, you have powerful tools at your disposal to manage traffic routing in your Kubernetes clusters. Regularly checking configurations and logs will ensure smooth operations.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Setting Up NGINX Ingress Controller and SSL in Kubernetes</title>
      <dc:creator>Nadim Tuhin</dc:creator>
      <pubDate>Wed, 11 Oct 2023 21:28:07 +0000</pubDate>
      <link>https://dev.to/nadimtuhin/setting-up-nginx-ingress-controller-and-ssl-in-kubernetes-5e5h</link>
      <guid>https://dev.to/nadimtuhin/setting-up-nginx-ingress-controller-and-ssl-in-kubernetes-5e5h</guid>
      <description>&lt;h3&gt;
  
  
  Setting Up NGINX Ingress Controller and SSL in Kubernetes
&lt;/h3&gt;

&lt;p&gt;Setting up an ingress controller and SSL in Kubernetes can greatly enhance your application's security and accessibility. This article walks you through setting up the NGINX ingress controller and securing your services using SSL certificates from Let's Encrypt.&lt;/p&gt;

&lt;h4&gt;
  
  
  Prerequisites:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;A Kubernetes cluster&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;kubectl&lt;/code&gt; CLI tool installed and configured&lt;/li&gt;
&lt;li&gt;A domain (for this tutorial, we'll use &lt;code&gt;example.com&lt;/code&gt;)&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  1. Install NGINX Ingress Controller:
&lt;/h4&gt;

&lt;p&gt;To start with, we need to set up the NGINX ingress controller. This will manage our inbound traffic to the cluster.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Create a namespace for the ingress controller&lt;/span&gt;
kubectl create namespace nginx

&lt;span class="c"&gt;# Install the ingress controller using Helm&lt;/span&gt;
helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx
helm &lt;span class="nb"&gt;install &lt;/span&gt;nginx ingress-nginx/ingress-nginx &lt;span class="nt"&gt;--namespace&lt;/span&gt; nginx
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  2. Deploy Your Next.js App:
&lt;/h4&gt;

&lt;p&gt;For this tutorial, we assume you have a simple Next.js application containerized and ready to be deployed. Here's a quick setup:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;apiVersion&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;v1&lt;/span&gt;
&lt;span class="na"&gt;kind&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Service&lt;/span&gt;
&lt;span class="na"&gt;metadata&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;nextjs-service&lt;/span&gt;
  &lt;span class="na"&gt;namespace&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;example&lt;/span&gt;
&lt;span class="na"&gt;spec&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;ports&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;port&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="m"&gt;80&lt;/span&gt;
      &lt;span class="na"&gt;targetPort&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="m"&gt;3000&lt;/span&gt;
  &lt;span class="na"&gt;selector&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;app&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;nextjs&lt;/span&gt;

&lt;span class="nn"&gt;---&lt;/span&gt;
&lt;span class="na"&gt;apiVersion&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;apps/v1&lt;/span&gt;
&lt;span class="na"&gt;kind&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Deployment&lt;/span&gt;
&lt;span class="na"&gt;metadata&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;nextjs-deployment&lt;/span&gt;
  &lt;span class="na"&gt;namespace&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;example&lt;/span&gt;
&lt;span class="na"&gt;spec&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;replicas&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="m"&gt;2&lt;/span&gt;
  &lt;span class="na"&gt;selector&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;matchLabels&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;app&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;nextjs&lt;/span&gt;
  &lt;span class="na"&gt;template&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;metadata&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;labels&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
        &lt;span class="na"&gt;app&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;nextjs&lt;/span&gt;
    &lt;span class="na"&gt;spec&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;containers&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;nextjs&lt;/span&gt;
        &lt;span class="na"&gt;image&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;YOUR_NEXTJS_IMAGE&lt;/span&gt;
        &lt;span class="na"&gt;ports&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
        &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;containerPort&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="m"&gt;3000&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Deploy using:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;kubectl apply &lt;span class="nt"&gt;-f&lt;/span&gt; nextjs-app.yaml
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  3. Setup Ingress:
&lt;/h4&gt;

&lt;p&gt;Now, to expose your Next.js app to the internet using your domain (&lt;code&gt;example.com&lt;/code&gt;), set up an Ingress:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;apiVersion&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;networking.k8s.io/v1&lt;/span&gt;
&lt;span class="na"&gt;kind&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Ingress&lt;/span&gt;
&lt;span class="na"&gt;metadata&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;nextjs-ingress&lt;/span&gt;
  &lt;span class="na"&gt;namespace&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;example&lt;/span&gt;
  &lt;span class="na"&gt;annotations&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;kubernetes.io/ingress.class&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;nginx"&lt;/span&gt;
&lt;span class="na"&gt;spec&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;rules&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;host&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;example.com&lt;/span&gt;
    &lt;span class="na"&gt;http&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;paths&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;/&lt;/span&gt;
        &lt;span class="na"&gt;pathType&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Prefix&lt;/span&gt;
        &lt;span class="na"&gt;backend&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
          &lt;span class="na"&gt;service&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
            &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;nextjs-service&lt;/span&gt;
            &lt;span class="na"&gt;port&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
              &lt;span class="na"&gt;number&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="m"&gt;80&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Apply the ingress:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;kubectl apply &lt;span class="nt"&gt;-f&lt;/span&gt; nextjs-ingress.yaml
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  4. Point A Record to Load Balancer IP:
&lt;/h4&gt;

&lt;p&gt;Once the ingress is applied, you should obtain an external IP address for the NGINX load balancer. Fetch this IP using:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;kubectl get services &lt;span class="nt"&gt;-n&lt;/span&gt; nginx
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Locate the &lt;code&gt;EXTERNAL-IP&lt;/code&gt; of the ingress-nginx service.&lt;/p&gt;

&lt;p&gt;Now, update your DNS settings by adding an A record pointing &lt;code&gt;example.com&lt;/code&gt; to the &lt;code&gt;EXTERNAL-IP&lt;/code&gt;.&lt;/p&gt;

&lt;h4&gt;
  
  
  5. Setting Up SSL with Cert-Manager:
&lt;/h4&gt;

&lt;p&gt;To secure our application with SSL, we'll utilize cert-manager:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Add the Jetstack Helm repository&lt;/span&gt;
helm repo add jetstack https://charts.jetstack.io

&lt;span class="c"&gt;# Install cert-manager&lt;/span&gt;
helm &lt;span class="nb"&gt;install &lt;/span&gt;cert-manager jetstack/cert-manager &lt;span class="nt"&gt;--namespace&lt;/span&gt; cert-manager &lt;span class="nt"&gt;--create-namespace&lt;/span&gt; &lt;span class="nt"&gt;--version&lt;/span&gt; v1.6.0 &lt;span class="nt"&gt;--set&lt;/span&gt; &lt;span class="nv"&gt;installCRDs&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nb"&gt;true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next, configure the Issuer and Certificate:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="c1"&gt;# Issuer Configuration&lt;/span&gt;
&lt;span class="na"&gt;apiVersion&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;cert-manager.io/v1&lt;/span&gt;
&lt;span class="na"&gt;kind&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Issuer&lt;/span&gt;
&lt;span class="na"&gt;metadata&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;letsencrypt-prod&lt;/span&gt;
  &lt;span class="na"&gt;namespace&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;example&lt;/span&gt;
&lt;span class="na"&gt;spec&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;acme&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;server&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;https://acme-v02.api.letsencrypt.org/directory&lt;/span&gt;
    &lt;span class="na"&gt;email&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;YOUR_EMAIL&lt;/span&gt;
    &lt;span class="na"&gt;privateKeySecretRef&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;letsencrypt-prod&lt;/span&gt;
    &lt;span class="na"&gt;solvers&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;http01&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
        &lt;span class="na"&gt;ingress&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
          &lt;span class="na"&gt;class&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;nginx&lt;/span&gt;

&lt;span class="c1"&gt;# Certificate Configuration&lt;/span&gt;
&lt;span class="na"&gt;apiVersion&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;cert-manager.io/v1&lt;/span&gt;
&lt;span class="na"&gt;kind&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Certificate&lt;/span&gt;
&lt;span class="na"&gt;metadata&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;example-tls&lt;/span&gt;
  &lt;span class="na"&gt;namespace&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;example&lt;/span&gt;
&lt;span class="na"&gt;spec&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;secretName&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;example-tls-secret&lt;/span&gt;
  &lt;span class="na"&gt;issuerRef&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;letsencrypt-prod&lt;/span&gt;
    &lt;span class="na"&gt;kind&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Issuer&lt;/span&gt;
  &lt;span class="na"&gt;commonName&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;example.com&lt;/span&gt;
  &lt;span class="na"&gt;dnsNames&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;example.com&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Replace &lt;code&gt;YOUR_EMAIL&lt;/code&gt; with your actual email and deploy:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;kubectl apply &lt;span class="nt"&gt;-f&lt;/span&gt; ssl-config.yaml
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Cert-manager will now request a certificate for your domain from Let's Encrypt and store it in a Kubernetes Secret (&lt;code&gt;example-tls-secret&lt;/code&gt;). Your ingress will automatically use this secret for SSL termination.&lt;/p&gt;

&lt;h4&gt;
  
  
  Conclusion:
&lt;/h4&gt;

&lt;p&gt;You've successfully set up the NGINX ingress controller, deployed a Next.js application, and secured it with SSL in your Kubernetes cluster. Ensure to monitor your applications and regularly update your configurations for security and performance improvements.&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
