'Access denied' error when using kubectl in Lens' terminal

2/22/2022

I downloaded Lens and imported my config file there and everything works great on Lens other than the fact that kubectl commands don't work through the terminal.

I was trying an exec command:

kubectl exec -i -t -n mynamespace mypod -c mycontainer -- sh -c "clear; (bash || ash || sh)"

And I got:

PS C:\Users\<user> kubectl exec -i -t -n mynamespace mypod -c mycontainer -- sh -c "clear; (bash || ash || sh)"
Access denied
line:1 char:1
+ kubectl exec -i -t -n mynamespace mypod -c...
+ ~~~~~~~~~~~~~~~~~
    + CategoryInfo          : OperationStopped: (:) [], UnauthorizedAccessException
    + FullyQualifiedErrorId : System.UnauthorizedAccessException

When I try to run that command through a CMD prompt or PowerShell prompt it works fine.

Anyone's got an idea why am I getting Access denied?

-- teamdever
kubectl
kubernetes

1 Answer

3/1/2022

As OP didn't respond to my comment I'm going to post this as Community Wiki for better visibility.

Lens is a special IDE for Kubernetes. Very similar issue was already posted in the Github thread - Error "Access denied" while using kubectl in lens' terminal.

There is no proper solution for this issue, however user sanarena posted a workaround which could help with this issue.

Turn off "Download kubectl binaries matching the kubernetes cluster version" and download kubectl.exe manually from k8s website and give the path in PATH TO KUBECTL BINARY section. it is now working fine

Full comment with more details can be found under this link.

-- PjoterS
Source: StackOverflow