Kubernetes 运行kubectl修补程序--本地由于缺少配置而失败

Kubernetes 运行kubectl修补程序--本地由于缺少配置而失败,kubernetes,kubectl,github-actions,Kubernetes,Kubectl,Github Actions,我有一个GitHub操作工作流,它替代部署清单中的值。我使用kubectl patch--local=true来更新图像。到目前为止,这项技术一直运作良好。今天,工作流开始失败,出现配置信息缺失或不完整的错误 我使用--local标志运行kubectl,因此不需要配置。有人知道是什么原因导致kubectl突然开始需要配置吗?我在Kubernetes GitHub问题中找不到任何有用的信息,几个小时的谷歌搜索也帮不上忙 GitHub操作工作流中失败步骤的输出: Run: kubectl patch

我有一个GitHub操作工作流,它替代部署清单中的值。我使用
kubectl patch--local=true
来更新图像。到目前为止,这项技术一直运作良好。今天,工作流开始失败,出现
配置信息缺失或不完整的错误

我使用
--local
标志运行
kubectl
,因此不需要配置。有人知道是什么原因导致
kubectl
突然开始需要配置吗?我在Kubernetes GitHub问题中找不到任何有用的信息,几个小时的谷歌搜索也帮不上忙

GitHub操作工作流中失败步骤的输出:

Run: kubectl patch --local=true -f authserver-deployment.yaml -p '{"spec":{"template":{"spec":{"containers":[{"name":"authserver","image":"test.azurecr.io/authserver:20201230-1712-d3a2ae4"}]}}}}' -o yaml > temp.yaml && mv temp.yaml authserver-deployment.yaml

error: Missing or incomplete configuration info.  Please point to an existing, complete config file:


  1. Via the command-line flag --kubeconfig
  2. Via the KUBECONFIG environment variable
  3. In your home directory as ~/.kube/config

To view or setup config directly use the 'config' command.
Error: Process completed with exit code 1.
kubectl版本的输出

Client Version: version.Info{Major:"1", Minor:"19", GitVersion:"v1.19.0", 
GitCommit:"ffd68360997854d442e2ad2f40b099f5198b6471", GitTreeState:"clean", 
BuildDate:"2020-11-18T13:35:49Z", GoVersion:"go1.15.0", Compiler:"gc", 
Platform:"linux/amd64"}
您仍然需要设置默认值。即使您在本地修改文件,您仍然在执行必须针对集群运行的
kubectl
命令。默认情况下,kubectl在
$HOME/.kube
目录中查找名为config的文件


错误:未设置当前上下文
表示没有为群集设置当前上下文,并且无法对群集执行
kubectl
。您可以使用。

创建服务帐户的上下文,作为我安装的一种解决方法(完成作业确实需要更长的时间,但至少它可以工作,并且可以用于以后的e2e测试)

添加此步骤:

- name: Setup kind
        run: kubectl version
        uses: engineerd/setup-kind@v0.5.0
还可以使用
--dry run=client
作为kubectl命令的选项


我确实意识到这不是正确的解决方案。

导出
KUBERNETES\u MASTER
环境变量应该可以做到:

$ export KUBERNETES_MASTER=localhost:8081  # 8081 port, just to ensure it works 

$ kubectl version

Client Version: version.Info{Major:"1", Minor:"18", GitVersion:"v1.18.8", GitCommit:"9f2892aab98fe339f3bd70e3c470144299398ace", GitTreeState:"clean", BuildDate
:"2020-08-13T16:12:48Z", GoVersion:"go1.13.15", Compiler:"gc", Platform:"linux/amd64"}
The connection to the server localhost:8081 was refused - did you specify the right host or port?

# Notice the port 8081 in the error message ^^^^^^
现在,修补程序也应该一如既往地工作:

$ kubectl patch --local=true -f testnode.yaml -p '{"metadata":{"managedFields":[]}}'    # to get the file content use  -o yaml 
node/k8s-w1 patched
或者,您可以将
kubectl
更新到更高版本。(v1.18.8即使没有技巧也可以正常工作)

说明部分:


更改在中恢复,对于以后的18.x版本,请参阅问题了解详细信息

我最终使用sed将字符串替换为图像

  - name: Update manifests with new images
    working-directory: test/cloud
    run: |
      sed -i "s~image:.*$~image: ${{ steps.image_tags.outputs.your_new_tag }}~g" your-deployment.yaml

现在很有魅力。

你的kube背景似乎还没有设置好。检查您从
kubectl config current context
中获得的内容。我得到
错误:未设置当前上下文。我看到的问题是,我想在本地修补文件,因此不需要上下文集。还是我弄错了?