How Do You Troubleshoot The Message “Error from server (NotFound): the server could not find the requested resource”?

Updated 9/20/19

Problem scenario
You run the kubectl command. You receive "Error from server (NotFound): the server could not find the requested resource." How do you resolve this?

1.a. Run this command: kubectl version | grep Version

Look at the GitVersion values for the client and server. They should match or nearly match. (You do not necessarily want the latest version for the client. It is easier to upgrade the client version than the server version.)

1.b. This is an optional step if you are not sure if the kubectl client version is a very different version from the server version. If the output looks too busy you can try either or both of these commands:

kubectl version | grep Version | awk '{print $5}' 
kubectl version | grep Version | awk '{print $4}'

The minor versions (the one in between the decimal points like the "15" in 1.15.4), should be within one number of each other. The kubectl command can work if the difference is more than one, but when the value is six or more (or even two or more), you may get this "Error from server (NotFound): the server could not find the requested resource" message. (For clarity, "very different" means that the minor versions differ by two or more. Some variances greater than this can be tolerated, but do not expect it to work when the difference is more than two.) The error message that you received is likely due to the minor versions of the client and server being too far apart. (If they are the same or within one of each other, this solution will not help you.) The rest of this solution is about downloading a kubectl client binary file that is a version that is closer to the server's version and using it.

2. Make a copy of the kubectl file (e.g., to your home directory). This way you can rollback to it if you have to back out of this change. Download the kubectl that is consistent with the server version. Replace X.Y.Z with the server's version (as seen in the output of the command shown in 1.a. above) in the following commands:

cd /tmp/
curl -LO

# An example of the above URL may be # where 1.15.5 is the version associated with the "kubectl version" output for Server Version.

3. Place this kubectl file where the original kubectl file was (e.g., use sudo mv -i /tmp/kubectl /usr/bin/).

4. Run this command: sudo chmod 777 /usr/bin/kubectl

To read more about the implications of doing this (as it it could allow other users on the server to run kubectl), see this posting.

5. You are done. Now run the kubectl commands (e.g., kubectl get pods, kubectl get svc).

Leave a comment

Your email address will not be published. Required fields are marked *