<?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: Major</title>
    <description>The latest articles on DEV Community by Major (@major1201).</description>
    <link>https://dev.to/major1201</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.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4069977%2F8f9c3acd-812f-47b3-8665-55664ba163b1.png</url>
      <title>DEV Community: Major</title>
      <link>https://dev.to/major1201</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/major1201"/>
    <language>en</language>
    <item>
      <title>I Brought rsync to kubectl</title>
      <dc:creator>Major</dc:creator>
      <pubDate>Sun, 09 Aug 2026 16:34:52 +0000</pubDate>
      <link>https://dev.to/major1201/i-brought-rsync-to-kubectl-2984</link>
      <guid>https://dev.to/major1201/i-brought-rsync-to-kubectl-2984</guid>
      <description>&lt;p&gt;Over the last few months, I've been working with Kubernetes pods in my development environment. One thing I frequently need to do is transfer files from my local machine into a development pod.&lt;/p&gt;

&lt;p&gt;The usual choice is &lt;code&gt;kubectl cp&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 &lt;span class="nb"&gt;cp&lt;/span&gt; ./local-dir my-dev-pod:/tmp/remote-dir
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It works, but I wanted something better for a development workflow.&lt;/p&gt;

&lt;p&gt;When I'm making changes locally and syncing them to a pod repeatedly, I don't want to transfer everything every time. I want &lt;strong&gt;rsync's incremental synchronization&lt;/strong&gt; that is only the files that have changed should be transferred.&lt;/p&gt;

&lt;p&gt;So I started wondering:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Could I make rsync work with kubectl?&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  The rsync &lt;code&gt;-e&lt;/code&gt; option
&lt;/h2&gt;

&lt;p&gt;It turns out that rsync has exactly the mechanism I needed: the &lt;code&gt;-e&lt;/code&gt; option.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;-e&lt;/code&gt; option allows rsync to specify the remote shell command it should use for connecting to the remote machine.&lt;/p&gt;

&lt;p&gt;For example, I created a small &lt;code&gt;rsh.sh&lt;/code&gt; script:&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;#!/bin/bash&lt;/span&gt;

&lt;span class="nv"&gt;POD&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$1&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;span class="nb"&gt;shift

&lt;/span&gt;kubectl &lt;span class="nb"&gt;exec&lt;/span&gt; &lt;span class="nt"&gt;-i&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$POD&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="nt"&gt;--&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$@&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then I could tell rsync to use this script as its remote shell:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;rsync &lt;span class="nt"&gt;-avzP&lt;/span&gt; &lt;span class="nt"&gt;-e&lt;/span&gt; ./rsh.sh &lt;span class="se"&gt;\&lt;/span&gt;
  ~/major1201/local-dir/ &lt;span class="se"&gt;\&lt;/span&gt;
  my-dev-pod:/tmp/remote-dir/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And it worked.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sending incremental file list
./
1.txt
              4 100%    0.00kB/s    0:00:00 (xfr#1, to-chk=2/4)
b/
b/2.txt
              4 100%    3.91kB/s    0:00:00 (xfr#2, to-chk=0/4)

sent 233 bytes  received 65 bytes  198.67 bytes/sec
total size is 8  speedup is 0.03
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The important part wasn't the transfer itself. It was that &lt;strong&gt;rsync was doing the synchronization while &lt;code&gt;kubectl exec&lt;/code&gt; provided the connection to the pod&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The flow looked like this: rsync -&amp;gt; rsh.sh -&amp;gt; kubectl exec -&amp;gt; kubernetes Pod&lt;/p&gt;

&lt;h2&gt;
  
  
  And that's the idea behind kubectl-rsync
&lt;/h2&gt;

&lt;p&gt;Once I had the proof of concept working, I packaged the idea into a &lt;code&gt;kubectl&lt;/code&gt; plugin.&lt;/p&gt;

&lt;p&gt;Now the same operation can be written as:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;kubectl rsync &lt;span class="se"&gt;\&lt;/span&gt;
  ~/major1201/local-dir/ &lt;span class="se"&gt;\&lt;/span&gt;
  my-dev-pod:/tmp/remote-dir/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Under the hood, &lt;code&gt;kubectl-rsync&lt;/code&gt; acts as an rsync transport shim. It connects rsync to the pod through &lt;code&gt;kubectl exec&lt;/code&gt;, allowing rsync to handle the file synchronization.&lt;/p&gt;

&lt;p&gt;This means I can use rsync features such as incremental transfers, compression, progress reporting, and partial transfers while still using my existing Kubernetes authentication and &lt;code&gt;kubectl&lt;/code&gt; workflow.&lt;/p&gt;

&lt;h2&gt;
  
  
  Install it with Krew
&lt;/h2&gt;

&lt;p&gt;If you already have &lt;a href="https://krew.sigs.k8s.io/" rel="noopener noreferrer"&gt;Krew&lt;/a&gt; installed, you can install the plugin 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 krew &lt;span class="nb"&gt;install &lt;/span&gt;rsync
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Try it out
&lt;/h2&gt;

&lt;p&gt;The project is open source:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/major1201/kubectl-rsync" rel="noopener noreferrer"&gt;https://github.com/major1201/kubectl-rsync&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you work with Kubernetes pods and frequently move files between your local machine and development environments, I'd love to hear what you think.&lt;/p&gt;

&lt;p&gt;If you find it useful, consider giving the project a star on GitHub.&lt;/p&gt;

</description>
      <category>kubernetes</category>
      <category>kubectl</category>
      <category>devops</category>
    </item>
  </channel>
</rss>
