Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
jacobtomlinson opened this issue Dec 11, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@jacobtomlinson
Copy link
Member

jacobtomlinson commented Dec 11, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant