<?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: mal</title>
    <description>The latest articles on DEV Community by mal (@malgasm).</description>
    <link>https://dev.to/malgasm</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%2F838335%2F416156e1-83e4-4f54-a70f-d39c9f0c21de.png</url>
      <title>DEV Community: mal</title>
      <link>https://dev.to/malgasm</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/malgasm"/>
    <language>en</language>
    <item>
      <title>Open Source (tsParticles) Helped me Finish a Years-Long Project Idea</title>
      <dc:creator>mal</dc:creator>
      <pubDate>Tue, 28 Jun 2022 18:31:20 +0000</pubDate>
      <link>https://dev.to/malgasm/open-source-tsparticles-helped-me-finish-a-years-long-project-idea-lc0</link>
      <guid>https://dev.to/malgasm/open-source-tsparticles-helped-me-finish-a-years-long-project-idea-lc0</guid>
      <description>&lt;p&gt;I had a simple, silly idea a few years ago: to program a robot with a function to help you feel a bit better. Before you get carried away, I’m not talking about a physical robot here – just a web page. The idea is, you would go to this web page and would ask, “am I good enough today?” The page would answer, “Yes!”&lt;/p&gt;

&lt;p&gt;I had a clear vision for how I wanted the page to work. First, I wanted to display a button that prompted the user to ask if they were good enough today. Once the visitor pressed the button, I wanted them to have a celebratory moment, powered by some on-screen confetti.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--vYNvWPEM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://malgasm.s3.us-west-1.amazonaws.com/aige-button.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--vYNvWPEM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://malgasm.s3.us-west-1.amazonaws.com/aige-button.png" alt="" width="880" height="441"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In 2017, when I first had this idea, the state of confetti libraries was not as comprehensive as it is today. I searched for “javascript confetti” before writing this article, in 2022, and I was able to find several libraries – even some that are devoted exclusively to rendering confetti (tsParticles does more than just confetti). When I had searched years ago in 2017, I only found one library, and it required a rather expensive licensing fee, which I was unwilling to pay at the time. I reasoned that the cost of the confetti library was too high for the project that I had in mind, and I didn’t have the bandwidth at the time to build the effect myself. So I put the project down.&lt;/p&gt;

&lt;p&gt;…Until 2022.&lt;/p&gt;

&lt;p&gt;Throughout 2021 and 2022, while I was using &lt;a href="https://dictate.life"&gt;dictate.life&lt;/a&gt; to catch up on &lt;a href="https://dev.to"&gt;dev.to&lt;/a&gt; articles daily, I came across a library called &lt;em&gt;tsParticles&lt;/em&gt;. After reading a couple of the product updates that the author would post on dev.to, I suddenly realized that I could finally finish the project.&lt;/p&gt;

&lt;p&gt;So, I built it, and streamed it live on Twitch. And I’d like to share it with you:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://amigoodenough.today"&gt;Am I Good Enough Today?&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Thanks for reading! I hope you enjoy the tool and the story, and I hope it inspires you to work on your own projects! And of course, thank you to the creator of tsParticles, Matteo Bruni, and the tsParticles contributors!&lt;/p&gt;

&lt;p&gt;tsParticles: &lt;a href="https://particles.js.org/"&gt;https://particles.js.org/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Live coding this project on Twitch (NSFW): &lt;a href="https://www.twitch.tv/videos/1447226927"&gt;https://www.twitch.tv/videos/1447226927&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>How to Deploy to Kubernetes Using Gitlab CI</title>
      <dc:creator>mal</dc:creator>
      <pubDate>Wed, 11 May 2022 11:21:15 +0000</pubDate>
      <link>https://dev.to/malgasm/how-to-deploy-to-kubernetes-using-gitlab-ci-h1a</link>
      <guid>https://dev.to/malgasm/how-to-deploy-to-kubernetes-using-gitlab-ci-h1a</guid>
      <description>&lt;p&gt;Automatically deploy new revisions of your app to your Kubernetes cluster with the push of a button!&lt;/p&gt;

&lt;p&gt;If you are not familiar with Kubernetes, I hope that this article can give you a deeper understanding of the power of Kubernetes. Regardless of your skill level, I hope that reading this article inspires you iterate on your infrastructure process.&lt;/p&gt;

&lt;p&gt;This article assumes that you already have a Kubernetes cluster with a working Kubeconfig for a user that has permissions to access the cluster. It also assumes that Gitlab’s servers can access your cluster. We will cover these topics, including how to implement Kubernetes Role-Based Access Control in a future article. Let’s get started:&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Prepare and download your Kubeconfig&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;The &lt;a href="https://kubernetes.io/docs/concepts/configuration/organize-cluster-access-kubeconfig/" rel="noopener noreferrer"&gt;Kubeconfig&lt;/a&gt; is a file that grants access to your Kubernetes cluster. The user that the Kubeconfig describes should have permission to &lt;strong&gt;&lt;code&gt;update&lt;/code&gt;&lt;/strong&gt; the &lt;code&gt;deployments&lt;/code&gt; in your cluster.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Upload your Kubeconfig to Gitlab&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;The first step is to provide Gitlab with your Kubeconfig.&lt;/p&gt;

&lt;p&gt;Navigate to your project or group &lt;strong&gt;CI/CD&lt;/strong&gt; Settings:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmalgasm.com%2Fimages%2Farticles%2Fkubeconfig-gitlab%2Fgitlab-settings.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmalgasm.com%2Fimages%2Farticles%2Fkubeconfig-gitlab%2Fgitlab-settings.png" alt="Gitlab CI settings"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Variables can be configured both at the Group and Project levels&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Click &lt;strong&gt;Expand&lt;/strong&gt; on the &lt;strong&gt;Variables&lt;/strong&gt; section:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmalgasm.com%2Fimages%2Farticles%2Fkubeconfig-gitlab%2Fvariables.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmalgasm.com%2Fimages%2Farticles%2Fkubeconfig-gitlab%2Fvariables.png" alt="Gitlab CI variables dialog"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;and then, click the &lt;strong&gt;Add Variable&lt;/strong&gt; button to reveal the following dialog:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmalgasm.com%2Fimages%2Farticles%2Fkubeconfig-gitlab%2Fadd-variable-dialog.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmalgasm.com%2Fimages%2Farticles%2Fkubeconfig-gitlab%2Fadd-variable-dialog.png" alt="Gitlab CI add variables dialog"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;The key MUST be KUBECONFIG&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Make sure that the &lt;strong&gt;Type&lt;/strong&gt; of the variable is set to &lt;strong&gt;File&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Then, copy the contents of your Kubeconfig into the &lt;strong&gt;Value&lt;/strong&gt; input box and finally, click the &lt;strong&gt;Add Variable&lt;/strong&gt; button.&lt;/p&gt;
&lt;h2&gt;
  
  
  &lt;strong&gt;Create the Deploy Step&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Once you’ve added your Kubeconfig as a CI pipeline variable, you’re ready to update your &lt;strong&gt;.gitlab-ci.yml&lt;/strong&gt; with a new &lt;code&gt;deploy&lt;/code&gt; stage. Below is an example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;deploy:
  stage: deploy
  image:
    name: bitnami/kubectl:latest
    entrypoint: [""]
  when: manual
  script:
    - kubectl set image deployment/my-deployment my-deployment=my.registry.com/my-image/$CI_COMMIT_REF_SLUG
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let’s explore a few parts of this pipeline step:&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;image&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;This definition uses &lt;strong&gt;bitnami’s&lt;/strong&gt;  &lt;strong&gt;kubectl&lt;/strong&gt; docker image. I do not want to maintain my own kubectl docker image, and bitnami’s kubectl image is the most reputable one I’ve found in my research. The info page on bitnami’s image is here: &lt;a href="https://bitnami.com/stack/kubectl/containers" rel="noopener noreferrer"&gt;https://bitnami.com/stack/kubectl/containers&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;By default, the image will run &lt;code&gt;kubectl&lt;/code&gt;, which will create unnecessary noise in our pipeline log. Thankfully, gitlab lets us override this behavior by specifying the &lt;strong&gt;entrypoint&lt;/strong&gt; as an empty set &lt;code&gt;[""]&lt;/code&gt;. This way, no command will be run when the image is run.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;when&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;This definition uses &lt;code&gt;when: manual&lt;/code&gt;, which will pause the pipeline when it reaches the deploy step. Normally, the pipeline step would automatically execute, but with the &lt;strong&gt;when&lt;/strong&gt; keyword, Gitlab will show a clickable play button that will start the job:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmalgasm.com%2Fimages%2Farticles%2Fkubeconfig-gitlab%2Fdeploy-button.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmalgasm.com%2Fimages%2Farticles%2Fkubeconfig-gitlab%2Fdeploy-button.png" alt="Gitlab CI deploy button"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;You may want to remove the when: manual declaration when creating a pipeline to deploy to a test or staging server.&lt;/em&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  &lt;strong&gt;script&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;The script section of the pipeline step is where the image switch is performed – we call the &lt;code&gt;kubectl&lt;/code&gt; command and set the image of a deployment named &lt;code&gt;my-deployment&lt;/code&gt; to &lt;code&gt;my.registry.com/my-image/$CI_COMMIT_REF_SLUG&lt;/code&gt;. These values should be changed to reflect your build process.&lt;/p&gt;

&lt;p&gt;The deployment name, specified in &lt;code&gt;deployment/my-deployment&lt;/code&gt;, references the &lt;code&gt;metadata.name&lt;/code&gt; property of your Kubernetes deployment. The image &lt;code&gt;set&lt;/code&gt; command, which also uses the name &lt;code&gt;my-deployment&lt;/code&gt;, references a different value, &lt;code&gt;spec.template.spec.initContainers[].name&lt;/code&gt;, or &lt;code&gt;spec.template.spec.containers[].name&lt;/code&gt;.&lt;/p&gt;
&lt;h2&gt;
  
  
  &lt;strong&gt;Bonus: Change Multiple Images in One Command&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;You may have noticed that the &lt;code&gt;set&lt;/code&gt; command above only contains the name of one image to change, and also that a Kubernetes deployment definition is allowed to have multiple images, specified through &lt;code&gt;containers&lt;/code&gt; or &lt;code&gt;initContainers&lt;/code&gt;. The &lt;code&gt;kubectl&lt;/code&gt; command supports setting multiple images in one command by separating the images to be set by a space. I find this approach to be more clear and efficient than running multiple commands in the pipeline stage:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kubectl set image deployment/my-deployment my-deployment=my.registry.com/my-image/$CI_COMMIT_REF_SLUG my-other-deployment=my.registry.com/my-other-image/$CI_COMMIT_REF_SLUG
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That’s it! Your Gitlab CI Pipelne should now be equipped with a new button that lets you deploy new revisions of your app! 🥳&lt;/p&gt;

&lt;p&gt;Further Reading:&lt;/p&gt;

&lt;p&gt;Kubernetes Deployments &lt;a href="https://kubernetes.io/docs/concepts/workloads/controllers/deployment/" rel="noopener noreferrer"&gt;https://kubernetes.io/docs/concepts/workloads/controllers/deployment/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Using Kubeconfig Files &lt;a href="https://kubernetes.io/docs/concepts/configuration/organize-cluster-access-kubeconfig/" rel="noopener noreferrer"&gt;https://kubernetes.io/docs/concepts/configuration/organize-cluster-access-kubeconfig/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Gitlab .gitlab-ci.yml documentation &lt;a href="https://docs.gitlab.com/ee/ci/yaml/" rel="noopener noreferrer"&gt;https://docs.gitlab.com/ee/ci/yaml/&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Authentication vs Authorization: What’s the Difference?</title>
      <dc:creator>mal</dc:creator>
      <pubDate>Tue, 19 Apr 2022 16:07:11 +0000</pubDate>
      <link>https://dev.to/malgasm/authentication-vs-authorization-whats-the-difference-3o67</link>
      <guid>https://dev.to/malgasm/authentication-vs-authorization-whats-the-difference-3o67</guid>
      <description>&lt;p&gt;&lt;em&gt;They sound similar, but they’re fundamentally different.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;So, what’s the difference between the two? Consider boarding a flight: in order to board the plane, you’ll need to successfully make it through the gauntlet of the airport’s authentication and authorization procedures. It’s worth noting that the processes in an airport often combine both authorization and authentication together, but we’ll do our best to illustrate the difference through two specific examples.&lt;/p&gt;

&lt;p&gt;The first part of the process is to enter a queue for the security line. After entering the correct airport terminal building, you’d locate your gate, walk to it and begin the first of the two steps:&lt;/p&gt;

&lt;h2&gt;
  
  
  Authentication
&lt;/h2&gt;

&lt;p&gt;The very first step that occurs, just before going through security at an airport, is authentication. You furnish your identification and boarding pass and present it to the line attendant. The attendant scans your boarding pass and your identification and ensures that you are who you are.&lt;/p&gt;

&lt;p&gt;At this point, the agent is checking to ensure that your boarding pass is valid and that your form of identification is valid, both of which are are required to &lt;strong&gt;prove that you’re the same person that is on your identification and boarding pass&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--eb6FjBIV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://malgasm.com/images/authentication-article-authentication.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--eb6FjBIV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://malgasm.com/images/authentication-article-authentication.jpg" alt="authentication in an airport setting" width="880" height="348"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The goal of this step is to ensure that you are who you say you are, and the TSA uses multi-factor authentication to perform this task; they inspect your supplied form of identification combined with your boarding pass. At this point, the folks at the airport don’t know whether you’re able to sit in economy class, business class, or first class, or whether you’re able to access the executive lounge – but they know that you are who you are and that you’re able to be in the airport.&lt;/p&gt;

&lt;p&gt;This step is like logging in to an application – submitting your boarding pass and identification is like submitting your username and password – once submitted and verified, the application can know that you are indeed who you say you are. The application doesn’t know what you’re able to do yet – if you’re able to simply make posts or if you can also access an admin area – but it knows that you’re a valid user.&lt;/p&gt;

&lt;p&gt;Once through the authentication step and through security, you walk over to your gate until the airline employees begin to announce over the loudspeaker, “now boarding for flight 123 to Honolulu….”&lt;/p&gt;

&lt;h2&gt;
  
  
  Authorization
&lt;/h2&gt;

&lt;p&gt;At your gate, you listen to the announcer begin to call the passengers by group. “Those in first class can now begin boarding.” This process can be thought of as authorization. For example, if you stand in that line and don’t have a first-class ticket, you’ll be denied entry until it is your turn. You’re authorized for one seat, and that seat does not grant you the ability to enter the line for the plane at that point. The attendant doesn’t need to know who you are at that point – they can simply look at your boarding pass, which also has your seat row and number on it – the required information for this step.&lt;/p&gt;

&lt;p&gt;The seat number indicated on your boarding pass also does not allow you to sit in the front of the plane. If you try to sit in a different seat, especially if you don’t have a first-class ticket and you try to sit in first class, you’ll be asked to leave and to sit in your seat. This can also be thought of as the process of authorization. The flight attendants are ensuring that those with authorization to do so can sit in the upgraded seats.&lt;/p&gt;

&lt;p&gt;Similarly, your application might have the concept of upgraded seats, or perhaps an admin area, which would be akin to an airplane’s cockpit. Only authorized users should be able to access those areas. Furthermore, let’s consider a situation where you have a highly privileged account for Service A and want to use that account to log into Service B. You probably would not want to give Service B permission to perform the highly privileged functions from Service A. You might want to only give Service B access to your email address. That would be authorization’s concern. This would be like a pilot boarding a plane as a civilian – they wouldn’t have access to the cockpit because they wouldn’t be there in a formal capacity and wouldn’t have authorization to enter.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why is Authorization and Authentication Important?
&lt;/h2&gt;

&lt;p&gt;A web application, when faced with a request, needs to answer the question “&lt;strong&gt;what is the true identity of the actor making this request?&lt;/strong&gt;” This question is arguably the most important question that a web application has to answer and drives the authentication process.&lt;/p&gt;

&lt;p&gt;Similarly, &lt;strong&gt;modern web applications demand granular access to resources&lt;/strong&gt;. Our modern culture encourages sharing and sharing demands limits to sensitive resources. for example, if you use facebook to sign into another site, you probably wouldn’t want to authorize that site to read your DMs. The &lt;a href="https://oauth.net/"&gt;OAuth protocol&lt;/a&gt; allows applications to define those permissions in a way that’s clear to everyone involved – the application developers and the users. OAuth is the web’s version of the TSA – but far more effective.&lt;/p&gt;

&lt;p&gt;It’s worth noting that the processes of authentication and authorization in web apps, like the same processes in an airport, are often deeply connected. Authorization often doesn’t make sense without authentication. Authentication is useless without authorization. Both are concepts that must work in concert to deliver a functional application.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;want to learn more&lt;/strong&gt;?&lt;/p&gt;

&lt;p&gt;i stream on twitch &lt;a href="https://www.twitch.tv/malgasm/"&gt;@malgasm&lt;/a&gt; and i tweet at &lt;a href="https://twitter.com/malgasmTV"&gt;@malgasmtv&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;come say hi!&lt;/p&gt;

</description>
      <category>authentication</category>
      <category>authorization</category>
      <category>tutorial</category>
      <category>programming</category>
    </item>
    <item>
      <title>Writing Redirects in Kubernetes' Nginx Ingress</title>
      <dc:creator>mal</dc:creator>
      <pubDate>Mon, 28 Mar 2022 22:39:52 +0000</pubDate>
      <link>https://dev.to/malgasm/writing-redirects-in-kubernetes-nginx-ingress-2e9l</link>
      <guid>https://dev.to/malgasm/writing-redirects-in-kubernetes-nginx-ingress-2e9l</guid>
      <description>&lt;p&gt;&lt;strong&gt;Are you using Kubernetes and want to redirect a www website to its non-www counterpart, or vice versa?&lt;/strong&gt; Hey, me too! 😃&lt;/p&gt;

&lt;p&gt;I recently re-launched the website for dictate.life and in the midst of planning the deployment I realized that there were a couple of simple requirements that I hadn’t been fully aware of at first:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;I want people to be able to access the site via &lt;a href="https://www.dictate.life"&gt;https://www.dictate.life&lt;/a&gt; or &lt;a href="https://dictate.life"&gt;https://dictate.life&lt;/a&gt; (or even &lt;a href="http://dictate.life"&gt;http://dictate.life&lt;/a&gt;, for that matter!)&lt;/li&gt;
&lt;li&gt;While you’re browsing the website, I want the address bar to always show that you’re on the &lt;a href="http://www"&gt;www&lt;/a&gt;. version of the site.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I’m familiar with performing this sort of task using a 301 redirect in a traditional Apache or Nginx environment, but I was unfamiliar with how to do this in a Kubernetes environment. Here’s how I ended up accomplishing it:&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;namespace&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;default&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-nginx-ingress&lt;/span&gt;
  &lt;span class="na"&gt;annotations&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="s"&gt;...other annotations...&lt;/span&gt;
    &lt;span class="s"&gt;kubernetes.io/ingress.class&lt;/span&gt;&lt;span class="err"&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;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;if ($host = 'myhost.com') {&lt;/span&gt;
        &lt;span class="s"&gt;return 301 https://www.myhost.com$request_uri;&lt;/span&gt;
      &lt;span class="s"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The neat thing about this redirect is that it not only redirects requests to the root path, /, but also to any other path. So if someone visits &lt;a href="http://dictate.life/about"&gt;http://dictate.life/about&lt;/a&gt;, they’ll be taken to the correct HTTPS-enabled, www-toting version of the url 🎉&lt;/p&gt;

&lt;p&gt;This isn’t the only way to use the &lt;strong&gt;configuration-snippet&lt;/strong&gt; option of Kubernetes’ nginx ingress. I’ve found that the above snippet best suits my needs, but let’s say that regardless of the URL input by the user, you always wanted to redirect them to the root. This would be a useful situation if you were moving to a new website where the URLs didn’t match. In that case, you’d simply leave off the &lt;strong&gt;$request_uri&lt;/strong&gt; portion, e.g.&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;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;if ($host = 'myhost.com') {&lt;/span&gt;
    &lt;span class="s"&gt;return 301 https://www.myhost.com;&lt;/span&gt;
  &lt;span class="s"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is the best way I’ve found to apply configuration changes to one ingress, assuming that you have only one. Nginx ingress also supports altering the default configuration of multiple ingresses at once, using &lt;strong&gt;ConfigMaps&lt;/strong&gt;. More info on that can be found here: &lt;a href="https://kubernetes.github.io/ingress-nginx/examples/customization/custom-headers/"&gt;https://kubernetes.github.io/ingress-nginx/examples/customization/custom-headers/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Want to learn more? Here's a shameless plug:  come watch me code or ask me a question on my Twitch stream! &lt;a href="https://www.twitch.tv/malgasm/"&gt;https://www.twitch.tv/malgasm/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;original article: &lt;a href="https://malgasm.com/blog/32/write-redirects-in-kubernetes-nginx-ingress-how-to"&gt;https://malgasm.com/blog/32/write-redirects-in-kubernetes-nginx-ingress-how-to&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

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