【问题标题】:unable to connect to Kubernetes: the server has asked for the client to provide credentials无法连接到 Kubernetes:服务器已要求客户端提供凭据
【发布时间】:2021-11-30 12:02:49
【问题描述】:

支架版本 v1.35.1

在 KindD 集群中使用 local registry:2

kubectl config current-context> 善良-善良。而 kubectl 配置视图,显示kind-kind 到服务器的正确 url:127.0.0.1:57836

预期行为

在 Goland:云代码:Kubernetes - 一个运行示例

skaffold.yaml

# To learn more about the skaffold.yaml schema visit
# https://skaffold.dev/docs/references/yaml/
apiVersion: skaffold/v2beta19
kind: Config
build:
  artifacts:
  - context: .
    image: go-hello-world
deploy:
  kubectl:
    manifests:
    - kubernetes-manifests/**

实际行为

错误:

unable to connect to Kubernetes: the server has asked for the client to provide credentials

请注意,它实际上会运行 - 但时间很短。见:Step 8/14在下面

skaffold dev --default-repo localhost:5000

Listing files to watch...
 - go-hello-world
Generating tags...
 - go-hello-world -> 127.0.0.1:5000/go-hello-world:6b3fc6f-dirty
Checking cache...
 - go-hello-world: Not found. Building
Starting build...
Found [kind-kind] context, using local docker daemon.
Building [go-hello-world]...
Sending build context to Docker daemon  932.9kB
Step 1/14 : FROM golang:1.16 as build
 ---> 5b838b7289de
Step 2/14 : WORKDIR /hello-world
 ---> Using cache
 ---> a8c93bc46b78
Step 3/14 : COPY go.mod go.sum ./
 ---> Using cache
 ---> cba8d38c5d62
Step 4/14 : RUN go mod download
 ---> Using cache
 ---> bfb3c3842a45
Step 5/14 : COPY . ./
 ---> f7f0547858d2
Step 6/14 : ARG SKAFFOLD_GO_GCFLAGS
 ---> Running in 8df9562291c8
 ---> 20aec50f0a84
Step 7/14 : RUN echo "Go gcflags: ${SKAFFOLD_GO_GCFLAGS}"
 ---> Running in f35f8060867a
Go gcflags: 
 ---> cc2532367c46
Step 8/14 : RUN go build -gcflags="${SKAFFOLD_GO_GCFLAGS}" -mod=readonly -v -o /app
 ---> Running in 03fe6cd6a195
hello-world
 ---> d8873c3d1844
Step 9/14 : FROM gcr.io/distroless/base
 ---> 64bbfbb81976
Step 10/14 : ENV GOTRACEBACK=single
 ---> Using cache
 ---> e7db9a53c2fe
Step 11/14 : WORKDIR /hello-world
 ---> Using cache
 ---> cba82d8b0927
Step 12/14 : COPY --from=build /app .
 ---> Using cache
 ---> fdd46a287814
Step 13/14 : COPY template ./template
 ---> Using cache
 ---> 01f1804abfcc
Step 14/14 : ENTRYPOINT ["./app"]
 ---> Using cache
 ---> c57d404bd28f
Successfully built c57d404bd28f
Successfully tagged 127.0.0.1:5000/go-hello-world:6b3fc6f-dirty
Tags used in deployment:
 - go-hello-world -> 127.0.0.1:5000/go-hello-world:c57d404bd28fbee71266d45debb822dd57215b585c2e16f5b1b21b5632ee0904
Starting deploy...
Cleaning up...
unable to connect to Kubernetes: the server has asked for the client to provide credentials

【问题讨论】:

  • 您的 kubeconfig 似乎丢失或无效。 kubectl config current-context 有输出吗?
  • 是的,它显示:kubectl config current-context > kind-kind。和 kubectl 配置视图,显示正确的 url 到服务器:127.0.0.1:57836
  • 谢谢,之前它实际上也运行了很短的时间:无法连接到 Kubernetes:服务器已要求客户端提供凭据
  • 紧随其后:步骤 8/14
  • 您能否在调用 skaffold 时尝试显式定义您的 kubeconfig。像这样:skaffold dev --default-repo localhost:5000 --kubeconfig <path to kubeconfig> 如果这不起作用,可以尝试使用 -v debug 标志执行 skaffold 以提供一些调试输出。

标签: kubernetes goland skaffold


【解决方案1】:

使用 --kubeconfig <path to kubeconfig file> 运行 skaffold 应该会成功。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-04-06
    • 2019-07-08
    • 2017-08-23
    • 2022-10-17
    • 1970-01-01
    • 2012-10-15
    相关资源
    最近更新 更多