Unauthorized 401 when trying to access Kubernetes API through curl

240 views Asked by At

I am running a local Kubernetes cluster (v1.28) and running into an issue when trying to access the API with curl.

curl https://192.168.1.100:6443 --cert /path/to/cert --key /path/to/key --cacert /path/to/ca

I receive the following error:

{ "kind": "Status", "apiVersion": "v1", "metadata": {}, "status": "Failure", "message": "Unauthorized", "reason": "Unauthorized", "code": 401 }

Is there a configuration step I'm missing to allow access?

I'm able to interact with kubectl and run commands. I was expecting to see something like this:

{ "paths": [ "/api", "/api/v1", ....

2

There are 2 answers

1
Eisa Qasemi On

Since you have a working kubectl you can use proxy command, proxy command works as a reverse proxy and forwards the requests to the API server.

kubectl proxy --port=8099

then you can browse the API with curl

curl localhost:8099
0
Id2ndR On

2 things has to be done:

  • enable TLS passthrough in the ingress, to allow the client certificate to reach the API and avoid the 401 unauthorized (see this example)
  • add the IP/DNS additional entry in the SANs of the API server (see this for kubeadm based kubernetes cluster).