kubectl can diff configuration (blog, docs).

On Linux, this works fine (WSL, Ubuntu 18, bash). It gives me sensible output similar to the following.

$ kubectl diff --filename some-resources.yaml
diff -u -N /tmp/LIVE-022965340/apps.v1.Deployment.… /tmp/MERGED-396067851/apps.v1.Deployment.…
--- /tmp/LIVE-022965340/apps.v1.Deployment.…      2020-07-20 17:06:21.444811700 +0200
+++ /tmp/MERGED-396067851/apps.v1.Deployment.…    2020-07-20 17:06:21.470315500 +0200
@@ -6,7 +6,7 @@
     kubectl.kubernetes.io/last-applied-configuration: |
   creationTimestamp: "2020-07-16T15:13:03Z"
-  generation: 1
+  generation: 2
   name: …
   namespace: …
   resourceVersion: "32827467"
@@ -121,7 +121,7 @@
         - chown www-data:www-data /files/ -R;chmod -R 755 /files/; chmod -R g+ws /files/
         - /bin/bash
-        - -c
+        - -cv
         image: …
         imagePullPolicy: IfNotPresent
         name: init-sites-volume

On PowerShell, kubectl diff fails (PowerShell 7, Windows 10).

PS > kubectl diff --filename some-resources.yaml
error: failed to run "diff": executable file not found in %PATH%

It seems that either kubectl can't find an executable named diff, or it trips up over diff being an alias for Compare-Object, which of course has very different syntax than Linux' diff.

Is it possible to get kubectl diff to work on PowerShell? If so, which diff-tool should I install and what should $env:KUBECTL_EXTERNAL_DIFF=… be set to?


This can be done by installing DiffUtils for Windows. The kubectl diff is using the Unix diff program so Windows will need some help with this. Simply:

  • Install the DiffUtils

  • Make sure the bin folder is mapped in your Win10 PATH variable (should be done automatically)

  • Restart the machine

Please let me know if that helped.

  • Yep, that worked. scoop install diffutils fixed it, no changes to PATH or restarts necessary. Thanks! – Grilse Jul 21 '20 at 13:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.