<?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: meowchinist</title>
    <description>The latest articles on DEV Community by meowchinist (@meowchinist).</description>
    <link>https://dev.to/meowchinist</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%2F1169724%2F578de105-4ec5-4364-b9f2-00e9ccc5863e.jpg</url>
      <title>DEV Community: meowchinist</title>
      <link>https://dev.to/meowchinist</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/meowchinist"/>
    <language>en</language>
    <item>
      <title>The Traffic Police 🚨 - Controlling outgoing traffic with mirrord</title>
      <dc:creator>meowchinist</dc:creator>
      <pubDate>Mon, 26 Feb 2024 15:02:20 +0000</pubDate>
      <link>https://dev.to/meowchinist/the-traffic-police-controlling-outgoing-traffic-with-mirrord-216</link>
      <guid>https://dev.to/meowchinist/the-traffic-police-controlling-outgoing-traffic-with-mirrord-216</guid>
      <description>&lt;p&gt;So, you've been using mirrord to simplify your development process (if you haven’t, go &lt;a href="https://mirrord.dev/"&gt;here!&lt;/a&gt;). Naturally, you want the traffic from the app you're debugging to go through the cluster environment, so your app can communicate with its &lt;em&gt;clustery&lt;/em&gt; pals. There is a problem though: your latest change adds some new columns to the database, and you don’t want to modify the database in the cluster and affect everyone else working on it. You do have a local instance of the database that you can modify, so your app can use that, but you still want it to talk to all the other components in the cluster.  So what now? The new &lt;strong&gt;outgoing traffic filter&lt;/strong&gt; feature is here to solve exactly this type of problem!&lt;/p&gt;

&lt;p&gt;With the new filter, you can specify whether your app’s outgoing traffic should be sent locally or remotely based on its destination. If we take the example above, with the database running in the cluster as a service &lt;code&gt;app-db&lt;/code&gt;, and locally with the same hostname, you can select which database your app will be talking to. Here is a sample &lt;code&gt;config.json&lt;/code&gt; for this use case:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt; 
  &lt;/span&gt;&lt;span class="err"&gt;feature&lt;/span&gt;&lt;span class="s2"&gt;": { 
    "&lt;/span&gt;&lt;span class="err"&gt;network&lt;/span&gt;&lt;span class="s2"&gt;": { 
      "&lt;/span&gt;&lt;span class="err"&gt;outgoing&lt;/span&gt;&lt;span class="s2"&gt;": { "&lt;/span&gt;&lt;span class="err"&gt;filter&lt;/span&gt;&lt;span class="s2"&gt;": { "&lt;/span&gt;&lt;span class="err"&gt;local&lt;/span&gt;&lt;span class="s2"&gt;": ["&lt;/span&gt;&lt;span class="err"&gt;app-db&lt;/span&gt;&lt;span class="s2"&gt;"] } } 
    } 
  } 
}
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this case, when your app tries to resolve the &lt;code&gt;app-db&lt;/code&gt; hostname it’ll do so locally (instead of in-cluster), meaning that traffic which would normally go to the cluster’s &lt;code&gt;app-db&lt;/code&gt; will be sent to your local database, while all other traffic (that doesn’t match the filter) will keep flowing as you expect, in the cluster. Isn’t this neat? Your cluster’s database remains unmodified, and you can keep working with the other services in your cluster. The filter supports multiple options, listed &lt;a href="https://mirrord.dev/docs/reference/configuration/#feature.network.outgoing.filter"&gt;here&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;Let's look at a more detailed example.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Setup 📋
&lt;/h2&gt;

&lt;p&gt;The recipe for our example is as follows:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;🥺 The &lt;code&gt;uwu-service&lt;/code&gt; running in the cluster, which takes normal text and performs &lt;em&gt;uwuification&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;😏 The &lt;code&gt;uwu-app&lt;/code&gt; in-cluster, that sends normal messages to &lt;code&gt;uwu-service&lt;/code&gt;, then writes the returned &lt;em&gt;uwu’d&lt;/em&gt; versions to a database. This is our target pod and the app we’re working on locally&lt;/li&gt;
&lt;li&gt;😀 A &lt;code&gt;messages-db&lt;/code&gt; database in the cluster, which the &lt;code&gt;uwu-app&lt;/code&gt; normally writes to, but in our debugging session, we’re going to be using a local version of this database&lt;/li&gt;
&lt;li&gt;😼 The local &lt;code&gt;uwu-app&lt;/code&gt; we are currently working on&lt;/li&gt;
&lt;li&gt;😺 A local &lt;code&gt;messages-db&lt;/code&gt;, so our schema changes won’t affect devs that rely on the cluster’s &lt;code&gt;message-db&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Diagram with the services and traffic flow&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5crhwgkrmmltsm5qvzmo.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5crhwgkrmmltsm5qvzmo.jpg" alt="mirrord outgoing traffic filter diagram" width="800" height="306"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Our flow here is as follows: &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The &lt;code&gt;uwu-app&lt;/code&gt; pod receives an HTTP request from the outside world;&lt;/li&gt;
&lt;li&gt;mirrord steals this request, forwarding it to the local &lt;code&gt;uwu-app&lt;/code&gt;;&lt;/li&gt;
&lt;li&gt;Next, the local &lt;code&gt;uwu-app&lt;/code&gt; makes a POST HTTP request to the &lt;code&gt;uwu-service&lt;/code&gt; in our cluster;&lt;/li&gt;
&lt;li&gt;This request goes through the agent pod, before reaching the &lt;code&gt;uwu-service&lt;/code&gt;;&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;uwu-service&lt;/code&gt; sends back an HTTP response with the &lt;em&gt;uwu’d&lt;/em&gt; version of the message;&lt;/li&gt;
&lt;li&gt;The response comes through the agent back to our local &lt;code&gt;uwu-app&lt;/code&gt;;&lt;/li&gt;
&lt;li&gt;And finally, we save the new &lt;em&gt;uwu&lt;/em&gt; message to our local &lt;code&gt;messages-db&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Under normal circumstances, the response from &lt;code&gt;uwu-service&lt;/code&gt; would be written to the cluster’s &lt;code&gt;message-db&lt;/code&gt; database, but the cluster database doesn’t comply with our new schema, so the write operation would just fail.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Example 💾
&lt;/h2&gt;

&lt;p&gt;Our main issue is that we want our local app’s outgoing traffic to be sent both locally and remotely, depending on its destination. Let's see how mirrord helps us solve this.&lt;/p&gt;

&lt;p&gt;We start out by running this command, which starts the &lt;code&gt;uwu-app&lt;/code&gt; with mirrord:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;mirrord &lt;span class="nb"&gt;exec&lt;/span&gt; &lt;span class="nt"&gt;-f&lt;/span&gt; config.json ./uwu-app
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Where &lt;code&gt;config.json&lt;/code&gt;&lt;sup id="fnref1"&gt;1&lt;/sup&gt; is just:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"target"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;“pod/uwu-app”&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"feature"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt; 
    &lt;/span&gt;&lt;span class="nl"&gt;"network"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt; 
      &lt;/span&gt;&lt;span class="nl"&gt;"incoming"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"steal"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; 
      &lt;/span&gt;&lt;span class="nl"&gt;"outgoing"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"filter"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"local"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;":8888"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is enough to start mirrord and the &lt;code&gt;uwu-app&lt;/code&gt; that we want to test. You should see something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;⠧ mirrord cli starting...
 ⠧ &lt;span class="nb"&gt;exec&lt;/span&gt;
   ✓ ready to launch process
   ✓ layer extracted
   ✓ no operator detected
   ✓ agent pod created
   ✓ pod is ready
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Our app is ready, and so is mirrord. Now we can make a request to the &lt;code&gt;uwu-app&lt;/code&gt; pod and have it stolen by mirrord (traffic will be stolen from the cluster app to our local app). First let's get the &lt;code&gt;uwu-app&lt;/code&gt; service port:&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="nv"&gt;$ &lt;/span&gt;kubectl describe service uwu-app

Name:                     uwu-app
Port:                     &amp;lt;&lt;span class="nb"&gt;unset&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;  9999/TCP
TargetPort:               9999/TCP
NodePort:                 &amp;lt;&lt;span class="nb"&gt;unset&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;  30032/TCP
Endpoints:                10.244.0.6:9999
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we can make a request using &lt;code&gt;curl&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;&lt;span class="nv"&gt;$ &lt;/span&gt;curl &lt;span class="nt"&gt;-d&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
&lt;span class="s2"&gt;"Hey, are you enjoying mirrord? Why not star us on github? It would be very cool of you."&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
&lt;span class="nt"&gt;-X&lt;/span&gt; POST  http://192.168.49.2:30032/uwu

Added new message
hey, 🥺 awe you enjoying miwwowd? 
why n-nyot staw us on g-github? 
it wouwd b-be vewy coow o-of you.
with &lt;span class="nb"&gt;id &lt;/span&gt;0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And here are the logs from the local &lt;code&gt;messages-db&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;&lt;span class="o"&gt;[&lt;/span&gt;DEBUG messages_db] store&lt;span class="p"&gt;;&lt;/span&gt; 
&lt;span class="nv"&gt;new_message&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"hey, 🥺 awe you enjoying miwwowd? 
             why n-nyot staw us on g-github? 
             it wouwd b-be vewy coow o-of you."&lt;/span&gt;
&lt;span class="o"&gt;[&lt;/span&gt;DEBUG messages_db]
&lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"Added new message hey, 🥺 awe you enjoying miwwowd?
                          why n-nyot staw us on g-github? 
                          it wouwd b-be vewy coow o-of you. 
        with id 0"&lt;/span&gt;
&lt;span class="o"&gt;[&lt;/span&gt;INFO  actix_web::middleware::logger] 127.0.0.1 &lt;span class="s2"&gt;"POST /store/0 HTTP/1.1"&lt;/span&gt; 200 129 &lt;span class="s2"&gt;"-"&lt;/span&gt; &lt;span class="s2"&gt;"-"&lt;/span&gt; 0.000243
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The cluster’s &lt;code&gt;messages-db&lt;/code&gt; doesn’t even know that any of this ever happened! The logs there are so clean you could see your own reflection, meaning that no traffic ever hits the remote &lt;code&gt;messages-db&lt;/code&gt;. &lt;br&gt;
To recap what happened: &lt;br&gt;
We captured incoming traffic from the remote &lt;code&gt;uwu-app&lt;/code&gt; and sent it to our local app instead &lt;br&gt;
Our local &lt;code&gt;uwu-app&lt;/code&gt; sent a request to the cluster’s &lt;code&gt;uwu-service&lt;/code&gt; and got back its uwufied version. &lt;br&gt;
Finally, our local app wrote the uwufied message to a local &lt;code&gt;messages-db&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;Without mirrord, you would either need to run everything locally, including the &lt;code&gt;uwu-service&lt;/code&gt; that turns normal messages into &lt;em&gt;uwu’d&lt;/em&gt; versions, or deploy your &lt;code&gt;uwu-app&lt;/code&gt; changes to the cluster, and potentially mess it up for the other devs.&lt;/p&gt;

&lt;p&gt;With mirrord you don’t have to choose. You can have youw cake and eat it t-too!!&lt;/p&gt;

&lt;h2&gt;
  
  
  The Feature 🔃
&lt;/h2&gt;

&lt;p&gt;With the new outgoing traffic filter feature (say it fast 3 times), you can pick and choose from where outgoing traffic is sent from. Paired with other mirrord features, such as the incoming HTTP traffic filter, you get unprecedented control over how your app communicates with your cluster.&lt;/p&gt;

&lt;p&gt;The example we just saw was really small, but you can imagine if the app we’re working on had to talk with a bunch of services, how painful it would be to set up everything locally, or how messy it could get if everyone had to take turns using the shared environment, just because the code writes to the same database. The outgoing traffic filter makes it easy to test changes on your shared environment without impacting the rest of your team. No more going around asking your colleagues if anyone needs to use the database in the next couple of hours..&lt;/p&gt;

&lt;h2&gt;
  
  
  Get mirrord 🪞
&lt;/h2&gt;

&lt;p&gt;Ready to improve your workflow? Want to start using the outgoing traffic filter? Check out the &lt;a href="https://mirrord.dev/docs/reference/configuration/#feature-network-outgoing"&gt;new configuration&lt;/a&gt; and start using it today!&lt;/p&gt;

&lt;p&gt;What? You're not using mirrord?! You have to deploy every small change, just so you can test it in cloud conditions? Let me stop you right there! Just download and install mirrord, and test your code in the context of your Kubernetes environment, right from the comfort of your own local machine. You can get it from &lt;a href="https://mirrord.dev/"&gt;here&lt;/a&gt;, what are you waiting for?&lt;/p&gt;

&lt;p&gt;Here is a &lt;a href="https://mirrord.dev/docs/overview/quick-start/"&gt;quick start guide&lt;/a&gt; link. Want to talk to an actual human? Then hop in our &lt;a href="https://discord.gg/metalbear"&gt;Discord&lt;/a&gt; (no chatbots here, I promise). Prefer more asynchronous communication? Open up an &lt;a href="https://github.com/metalbear-co/mirrord/issues/new/choose"&gt;issue&lt;/a&gt; or a &lt;a href="https://github.com/metalbear-co/mirrord/discussions/new/choose"&gt;discussion&lt;/a&gt; on &lt;a href="https://github.com/metalbear-co/mirrord"&gt;GitHub&lt;/a&gt;. We love feedback, don’t be shy!&lt;/p&gt;




&lt;ol&gt;

&lt;li id="fn1"&gt;
&lt;p&gt;We're setting &lt;code&gt;incoming&lt;/code&gt; traffic to &lt;code&gt;steal&lt;/code&gt;, but mirrord also supports traffic &lt;code&gt;mirror&lt;/code&gt;ing, and traffic &lt;code&gt;steal&lt;/code&gt;ing with a filter. You can see all the options &lt;a href="https://mirrord.dev/docs/reference/configuration/#feature-network-incoming"&gt;here&lt;/a&gt;. ↩&lt;/p&gt;
&lt;/li&gt;

&lt;/ol&gt;

</description>
      <category>kubernetes</category>
      <category>mirrord</category>
      <category>cloud</category>
      <category>tooling</category>
    </item>
  </channel>
</rss>
