pod shows existing but get pod not found error when running port-forward

12/18/2019

when I run kubectl get pods it shows pod existing and ready, but when run kubectl port-forward I get pod not foud error. what's going on here?

(base):~ zwang$ k get pods -n delivery
NAME                                  READY   STATUS    RESTARTS   AGE
screenshot-history-7f76489574-wntkf   1/1     Running   86         7h18m
(base):~ zwang$ k port-forward screenshot-history-7f76489574-wntkf 8000:8000
Error from server (NotFound): pods "screenshot-history-7f76489574-wntkf" not found
-- JamesWang
amazon-eks
kubernetes

3 Answers

12/18/2019

Try these commands

k config set-context --current --namespace=delivery
k port-forward screenshot-history-7f76489574-wntkf 8000:8000 &

OR

k -n delivery port-forward screenshot-history-7f76489574-wntkf 8000:8000 &
-- P Ekambaram
Source: StackOverflow

12/18/2019

You need to specify the namespace on the port-forward command too. kubectl port-forward -n delivery screenshot-history-7f76489574-wntkf 8000:8000

-- coderanger
Source: StackOverflow

12/18/2019

Try putting the namespace while accessing the Pod.

 kubectl port-forward screenshot-history-7f76489574-wntkf 8000:8000 -n delivery

Another option is change the current namespace to your desired one. Then you can directly work without passing any namespace. You can see more info to change the current namespace from this link.

-- nagendra547
Source: StackOverflow