<p>I'm using k3d with calico, and trying to use <code>calicoctl</code> to set a network policy. I am able to get this working on Ubuntu, but on Windows it doesn't. To set it up I did the following:</p>
<pre class="lang-sh prettyprint-override"><code># Download Calico YAML
# DOWNLOAD: https://raw.githubusercontent.com/rancher/k3d/main/docs/usage/guides/calico.yaml

# Create k3d cluster
k3d cluster create &quot;dev&quot; --k3s-server-arg '--flannel-backend=none' --volume &quot;$(pwd)/calico.yaml:/var/lib/rancher/k3s/server/manifests/calico.yaml

# Download Windows version
# DOWNLOAD: https://github.com/projectcalico/calicoctl/releases/download/v3.18.2/calicoctl-windows-amd64.exe 
 
# Make an Alias
Set-Alias -Name calicoctl -Value &quot;.\calicoctl-windows-amd64.exe&quot;
</code></pre>
<p>When I then tried running to apply a <code>NetWorkPolicy</code> with <code>calicoctl apply -f my-policy.yaml</code> and I get the error:</p>
<blockquote>
<p>Failed to create Calico API client: invalid configuration: no configuration has been provided, try setting KUBERNETES_MASTER environment variable</p>
</blockquote>
<p>So I tried setting that by using my Kubeconfig's values:</p>
<pre class="lang-sh prettyprint-override"><code># Get the IP/Port from Kubeconfig (Gives https://0.0.0.0:60776)
$kmaster=(kubectl config view -o jsonpath=&quot;{.clusters[?(@.name=='k3d-dev')].cluster.server}&quot;)

# Set the kubernetes master env variable from what's in kube config
[Environment]::SetEnvironmentVariable(“KUBERNETES_MASTER”, $kmaster, “User”)
</code></pre>
<p>That still gives the same error. <em>(Note: the ip from Kubeconfig is &quot;https://0.0.0.0:60776&quot;)</em></p>
<p>So then I tried all the following and none of them work:</p>
<pre class="lang-sh prettyprint-override"><code>set KUBECONFIG=~/.kube/config
SET CALICO_KUBECONFIG=C:\Users\myname\.kube\config
SET KUBE_CONFIG_PATH=C:\Users\myname\.kube\config
$env:KUBERNETES_MASTER=(kubectl config view -o jsonpath=&quot;{.clusters[?(@.name=='k3d-dev')].cluster.server}&quot;)
</code></pre>
<p>How do I get &quot;calicoctl-windows-amd64.exe&quot; to find my Kubernetes cluster?</p>

Don Rhummy
<p>While the official <a href="https://docs.projectcalico.org/getting-started/clis/calicoctl/configure/kdd" rel="nofollow noreferrer">documentation</a> claims:</p>
<ol>
<li>Calico looks for the config in the default user location <code>~/.kube/config</code></li>
<li>It will also look at <code>KUBERNETES_MASTER</code> <em>(the error output states this)</em></li>
<li>It will also look at <code>KUBECONFIG</code></li>
</ol>
<p>It does NOT! None of the above works on Windows. <em>(On Ubuntu, I did not have to do anything special and it found my config)</em></p>
<p>The only solution I found was to do the following:</p>
<ol>
<li>Create a config file</li>
<li>Pass the config file in every <code>calicoctl</code> call</li>
</ol>
<p><strong>calico.cfg.yaml</strong></p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: projectcalico.org/v3
kind: CalicoAPIConfig
metadata:
spec:
  datastoreType: &quot;kubernetes&quot;
  kubeconfig: &quot;C:/users/myusername/.kube/config&quot;
</code></pre>
<p><em>NOTE: If you pass &quot;~/.kube/config&quot; it will fail and say it cannot find that path</em></p>
<p><strong>Calling it now requires:</strong></p>
<pre class="lang-sh prettyprint-override"><code># NOTICE THE &quot;--config=calico.cfg.yaml&quot;
calicoctl apply -f some-policy.yaml --config=calico.cfg.yaml
</code></pre>
<p>I <em>think</em>, judging by the config file working but throwing an error when using <code>&quot;~/.kube/config&quot;</code> as the kubeconfig path, that it <em><strong>is</strong></em> looking in that &quot;default&quot; path but is using a Windows API that does not understand the <code>~</code> alias.</p>
