Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error from server (NotFound): pods "\nmongo-client-79667cc85d-tsg72" not found

I'm trying to make a backup from Mongo / K8S with this script

export POD=$(kubectl get pods -l app=mongo-client -o custom-columns=:metadata.name -n espace-client)
kubectl exec "$POD" sh -c 'mongodump --archive' > ~/backup/mongo/$(date +%F).db.dump

I get this error:

Error from server (NotFound): pods "\nmongo-client-79667cc85d-tsg72" not found

When I check the pods, I can see mongo-client-79667cc85d-tsg72

When I put the name without variable, it works well, so it might be because of initial \n. How can I avoid it ? How can I remove it from name ?

like image 332
Juliatzin Avatar asked Jan 25 '26 03:01

Juliatzin


2 Answers

Your kubectl get pods command is constrained with a namespace selector -n espace-client. Your kubectl exec command also needs the namespace flag.

like image 144
erk Avatar answered Jan 27 '26 18:01

erk


The output of your kubectl get pods command has a newline before the pod name because the first line of the output is the column header (which is empty in your case).

To prevent this and get only the name as output, you can suppress the column headers with the --no-headers flag:

kubectl get pods -l app=mongo-client -o custom-columns=:metadata.name -n espace-client --no-headers
like image 42
weibeld Avatar answered Jan 27 '26 16:01

weibeld



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!