如何解决由于缺少配置,运行 kubectl patch --local 失败
我有一个 GitHub Actions 工作流程,可以替换部署清单中的值。我使用 kubectl patch --local=true
更新图像。直到现在,这曾经完美无缺。今天工作流开始失败,出现 Missing or incomplete configuration info
错误。
我正在使用 kubectl
标志运行 --local
,因此不需要配置。有谁知道 kubectl
突然开始需要配置的原因是什么?我在 Kubernetes GitHub 问题中找不到任何有用的信息,数小时的谷歌搜索也无济于事。
GitHub Actions 工作流程中失败步骤的输出:
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 version
的输出:
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"}
解决方法
作为一种解决方法,我安装了 kind(完成工作确实需要更长的时间,但至少它可以工作,以后可以用于 e2e 测试)。
添加了这一步:
- name: Setup kind
run: kubectl version
uses: engineerd/setup-kind@v0.5.0
还可以使用 --dry-run=client
作为 kubectl 命令的选项。
我确实意识到这不是正确的解决方案。
,您仍然需要设置 config to access kubernetes cluster。即使您在本地修改文件,您仍在执行必须针对集群运行的 kubectl
命令。默认情况下,kubectl 在 $HOME/.kube
目录中查找名为 config 的文件。
error: current-context is not set
表示没有为集群设置当前上下文,并且无法对集群执行 kubectl
。您可以使用 this tutorial 为服务帐户创建上下文。
我最终使用 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
现在就像一个魅力。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。