我正在将 k3d 与 calico 一起使用,并尝试使用它calicoctl
来设置网络策略。我可以在 Ubuntu 上运行它,但在 Windows 上却不行。为了设置它,我做了以下事情:
# Download Calico YAML
# DOWNLOAD: https://raw.githubusercontent.com/rancher/k3d/main/docs/usage/guides/calico.yaml
# Create k3d cluster
k3d cluster create "dev" --k3s-server-arg '--flannel-backend=none' --volume "$(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 ".\calicoctl-windows-amd64.exe"
然后,当我尝试运行以应用NetWorkPolicy
with 时calicoctl apply -f my-policy.yaml
,出现错误:
创建 Calico API 客户端失败:无效配置:未提供配置,尝试设置 KUBERNETES_MASTER 环境变量
所以我尝试使用我的 Kubeconfig 的值来设置它:
# Get the IP/Port from Kubeconfig (Gives https://0.0.0.0:60776)
$kmaster=(kubectl config view -o jsonpath="{.clusters[?(@.name=='k3d-dev')].cluster.server}")
# Set the kubernetes master env variable from what's in kube config
[Environment]::SetEnvironmentVariable(“KUBERNETES_MASTER”, $kmaster, “User”)
这仍然给出了同样的错误。(注意:来自 Kubeconfig 的 ip 是“https://0.0.0.0:60776”)
因此,我尝试了以下所有方法,但均无效:
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="{.clusters[?(@.name=='k3d-dev')].cluster.server}")
如何让“calicoctl-windows-amd64.exe”找到我的 Kubernetes 集群?