Skip to content

Issue with getting /api and /apis inside a pod #2457

@bulatgizyatullin

Description

@bulatgizyatullin

I'm running my python code inside a pod, please see below:

from kubernetes import client, config

config.load_incluster_config()
api_client = client.ApiClient()
core_version = api_client.call_api('/api', 'GET', response_type='object')[0]

or

discovery = client.ApisApi(api_client)
api_versions = discovery.get_api_versions()

And getting the next issue:
"apiVersion":"v1","metadata":{},"status":"Failure","message":"forbidden: User "system:anonymous" cannot get path "/api"","reason":"Forbidden","details":{},"code":403

When I try to do the same but with

config.load_kube_config(config_file=KUBE_CONFIG_FILE) 

instead of

config.load_incluster_config()

everything is working fine.

I've attached service account with full admin permission to the pod. I'm able to see token in file /var/run/secrets/kubernetes.io/serviceaccount/token inside the pod.
Kubernetes lib version is kubernetes==33.1.0.

Could you please assist with the issue ?

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions