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

11/30/2021

skaffold version v1.35.1

Using local registry:2 in KinD cluster.

kubectl config current-context > kind-kind. And kubectl config view, shows the right url for kind-kind to the server: 127.0.0.1:57836

Expected behavior

In Goland: Cloud Code: Kubernetes - a running example

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/**

Actual behavior

Error:

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

Note in the following, that it actually runs - but only very short time. See: Step 8/14 in the following

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
-- Chris G.
goland
kubernetes
skaffold

1 Answer

11/30/2021

Running skaffold with the --kubeconfig <path to kubeconfig file> should to the trick.

-- Robert Keck
Source: StackOverflow