Skip to content

When using kr8s inside a Pod with no config it does not use the correct namespace #532

@jacobtomlinson

Description

@jacobtomlinson

Which project are you reporting a bug for?

kr8s

What happened?

If I use kubectl inside a Pod without providing a service account or any configuration it defaults to using the same namespace the Pod is running in. But kr8s just uses default.

To reproduce create a new namespace and start an interactive Pod inside it.

Create a new namespace
$ kubectl create namespace foo
namespace "foo" created

Run an interactive Pod in that namespace
$ kubectl run python --image python --namespace foo --rm -it -- bash

Install kubectl and try to list Pods.

Install kubectl
# apt update && apt install curl -y && curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl" && chmod +x kubectl && mv kubectl /usr/local/bin/
...

Try to list Pods
# kubectl get pods
Error from server (Forbidden): pods is forbidden: User "system:serviceaccount:foo:default" cannot list resource "pods" in API group "" in the namespace "foo"

Note the error says cannot list resource "pods" in API group "" in the namespace "foo".

However if I do the same thing with kr8s it uses the default namespace.

Install kr8s
# pip install kr8s
...

Try to list Pods
# python -c 'import kr8s; kr8s.get("pods")'
...
kr8s._exceptions.ServerError: pods is forbidden: User "system:serviceaccount:foo:default" cannot list resource "pods" in API group "" in the namespace "default"

Note the error says cannot list resource "pods" in API group "" in the namespace "default".

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions