<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>fairburg</title>
    <link>https://fairburg.xyz/</link>
    <description></description>
    <pubDate>Thu, 16 Apr 2026 15:35:40 +0000</pubDate>
    <item>
      <title>Port forwarding</title>
      <link>https://fairburg.xyz/port-forwarding?pk_campaign=rss-feed</link>
      <description>&lt;![CDATA[Setting up port-forwards with kubectl can be annoying, either you need use a new terminal window or you try and use your shells background jobs.&#xA;&#xA;Here is a fish function to set up a port-forwards as an auto-restarting systemd unit that runs in the background:&#xA;&#xA;function pf --description &#34;Set up a port-forward with kubectl&#34; --wraps &#34;kubectl port-forward&#34;&#xA;    set -l cmd (string join &#39; &#39; $argv)&#xA;    set -l context (kubectl config current-context)&#xA;    set -l namespace (kubectl config view --minify -o jsonpath=&#39;{..namespace}&#39;)&#xA;    if test -z &#34;$namespace&#34;&#xA;        echo &#34;Namespace not set in current context&#34;   &amp;2&#xA;        return 1&#xA;    end&#xA;    systemd-run --user --collect --unit portforward &#xA;        --description=&#34;port-forward $cmd&#34; &#xA;        --property=Restart=on-failure &#xA;        --property=RestartSec=2 &#xA;        fish -c &#34;kubectl --context $context --namespace $namespace port-forward $cmd&#34;&#xA;end&#xA;&#xA;The —wraps option enables the usual tab completion you’d get from running kubectl directly&#xA;&#xA;To make sure you don’t forget about an active port-forward, I’ve integrated this in my starship prompt:&#xA;&#xA;[custom.portforward]&#xA;command = &#34;systemctl --user show --property=Description portforward.service | sed &#39;s/Description=//&#39;&#34;&#xA;when = &#34;systemctl --user is-active --quiet portforward.service&#34;&#xA;format = &#34;$output &#34;&#xA;&#xA;And then I have two small helpers to avoid having to type systemctl —user to check the port-forward and stop it again:&#xA;&#xA;function pfe --description &#34;Stop the port-forward unit&#34;&#xA;    systemctl --user is-active portforward   /dev/null&#xA;    if test $status -ne 0&#xA;        echo &#34;portforward unit is not active&#34;   &amp;2&#xA;        return 1&#xA;    end&#xA;    systemctl --user stop portforward&#xA;end&#xA;function pfs --description &#34;Show the status of port-forwarding&#34;&#xA;    systemctl --user status portforward&#xA;end&#xA;`]]&gt;</description>
      <content:encoded><![CDATA[<p>Setting up port-forwards with kubectl can be annoying, either you need use a new terminal window or you try and use your shells background jobs.</p>

<p>Here is a fish function to set up a port-forwards as an auto-restarting systemd unit that runs in the background:</p>

<pre><code>function pf --description &#34;Set up a port-forward with kubectl&#34; --wraps &#34;kubectl port-forward&#34;
    set -l cmd (string join &#39; &#39; $argv)
    set -l context (kubectl config current-context)
    set -l namespace (kubectl config view --minify -o jsonpath=&#39;{..namespace}&#39;)
    if test -z &#34;$namespace&#34;
        echo &#34;Namespace not set in current context&#34; &gt;&amp;2
        return 1
    end
    systemd-run --user --collect --unit portforward 
        --description=&#34;port-forward $cmd&#34; 
        --property=Restart=on-failure 
        --property=RestartSec=2 
        fish -c &#34;kubectl --context $context --namespace $namespace port-forward $cmd&#34;
end
</code></pre>

<p>The <code>—wraps</code> option enables the usual tab completion you’d get from running <code>kubectl</code> directly</p>

<p>To make sure you don’t forget about an active port-forward, I’ve integrated this in my starship prompt:</p>

<pre><code>[custom.portforward]
command = &#34;systemctl --user show --property=Description portforward.service | sed &#39;s/Description=//&#39;&#34;
when = &#34;systemctl --user is-active --quiet portforward.service&#34;
format = &#34;[$output](bold green) &#34;
</code></pre>

<p>And then I have two small helpers to avoid having to type <code>systemctl —user</code> to check the port-forward and stop it again:</p>

<pre><code>function pfe --description &#34;Stop the port-forward unit&#34;
    systemctl --user is-active portforward &gt;/dev/null
    if test $status -ne 0
        echo &#34;portforward unit is not active&#34; &gt;&amp;2
        return 1
    end
    systemctl --user stop portforward
end
function pfs --description &#34;Show the status of port-forwarding&#34;
    systemctl --user status portforward
end
</code></pre>
]]></content:encoded>
      <guid>https://fairburg.xyz/port-forwarding</guid>
      <pubDate>Wed, 22 Oct 2025 06:59:13 +0000</pubDate>
    </item>
  </channel>
</rss>