omrikiei / ktunnel

A cli that exposes your local resources to kubernetes
GNU General Public License v3.0
925 stars 71 forks source link

ktunnel inject deployment not working #71

Closed apkapil closed 1 year ago

apkapil commented 2 years ago

i was trying ktunnel to inject deployment but not working

command used:-ktunnel inject deployment flask-deployment 80

Error

"status": "Failure",
  "message": "pods \"flask-deployment-6c86b6f988-vkfh8\" is forbidden: User \"system:anonymous\" cannot get resource \"pods/portforward\" in API group \"\" in the namespace \"default\"",
  "reason": "Forbidden",
  "details": {
    "name": "flask-deployment-6c86b6f988-vkfh8",
    "kind": "pods"
  },
omrikiei commented 2 years ago

Hi @apkapil, do you have permissions to edit objects in the kubernetes cluster? Which cluster version is it?

apkapil commented 2 years ago

Hi @omrikiei ...yes i am admin and i am able to create deployment

kubernetes :- v1.21.5-eks-9017834

omrikiei commented 2 years ago

and are you using the same KUBE_CONFIG environment as where you're running the cli from?

apkapil commented 2 years ago

@omrikiei i am changing Kubernetes context using docker-desktop

omrikiei commented 2 years ago

got it, is it possible that when you run the command - a different context is set which you do not have admin rights to? when you try to create a simple portforward to a pod in the cluster, does it work?

apkapil commented 2 years ago

Its working but we are getting access issue in that link

https://7CF859F204EDAA2810465B9E23E9D7A5.yl4.ap-south-1.eks.amazonaws.com/api/v1/namespaces/default/pods/tunnel2-64f98469cd-2tjnz/portforward

Error

Screenshot 2022-01-26 at 7 42 42 PM

omrikiei commented 2 years ago

ok this makes sense, you shouldn't access the port forward link from a browser, instead you should try to access the exposed client IP (10.100.68.132 in the case of the example you shared) from within the cluster, if you'd like to access it externally you'll need to set up an ingress or annotate the exposed service to be routed from a load balancer

kapilsingh421 commented 2 years ago

hey @omrikiei can you Please help me in this ,getting issue while using the deployment command.

we have application running on localhost on port 9090 and 9000 , so want Kubernetes to access this application ktunnel inject deployment flask-deployment 9090 9000

/Users/arabhi/Desktop/Screenshot 2022-02-11 at 1.03.27 PM.png

kapilsingh421 commented 2 years ago
INFO[0000] Injecting tunnel sidecar to default/flask-deployment 
INFO[0002] Waiting for deployment to be ready           
INFO[0002] ProgressDeadlineInSeconds is currently 600s. It may take this long to detect a deployment failure. 
INFO[0002] deployment "postgres" successfully rolled out 
INFO[0003] port forwarding to https://7CF859F204EDAA2810465B9E23E9D7A5.yl4.ap-south-1.eks.amazonaws.com/api/v1/namespaces/default/pods/flask-deployment-65dd887888-m2nlp/portforward 
INFO[0003] Waiting for port forward to finish           
INFO[0003] Forwarding from 127.0.0.1:28688 -> 28688
Forwarding from [::1]:28688 -> 28688 
INFO[2022-02-11 13:00:48.039] starting tcp tunnel from source 9090 to target 9090 
INFO[2022-02-11 13:00:48.039] starting tcp tunnel from source 9000 to target 9000 
E0211 13:00:48.123946   32764 portforward.go:400] an error occurred forwarding 28688 -> 28688: error forwarding port 28688 to pod 4805f6f9b6cc95dadc4f1b13f731023e9770512ac3c855d33fd77e805f459649, uid : exit status 1: 2022/02/11 07:30:48 socat[10877] E connect(5, AF=2 127.0.0.1:28688, 16): Connection refused
ERRO[2022-02-11 13:00:48.124] Error sending init tunnel request: rpc error: code = Unavailable desc = connection closed 
ERRO[2022-02-11 13:00:48.124] Error sending init tunnel request: rpc error: code = Unavailable desc = connection closed 
E0211 13:00:49.266917   32764 portforward.go:400] an error occurred forwarding 28688 -> 28688: error forwarding port 28688 to pod 4805f6f9b6cc95dadc4f1b13f731023e9770512ac3c855d33fd77e805f459649, uid : exit status 1: 2022/02/11 07:30:49 socat[11150] E connect(5, AF=2 127.0.0.1:28688, 16): Connection refused
E0211 13:00:50.779800   32764 portforward.go:400] an error occurred forwarding 28688 -> 28688: error forwarding port 28688 to pod 4805f6f9b6cc95dadc4f1b13f731023e9770512ac3c855d33fd77e805f459649, uid : exit status 1: 2022/02/11 07:30:50 socat[11170] E connect(5, AF=2 127.0.0.1:28688, 16): Connection refused
E0211 13:00:53.516499   32764 portforward.go:400] an error occurred forwarding 28688 -> 28688: error forwarding port 28688 to pod 4805f6f9b6cc95dadc4f1b13f731023e9770512ac3c855d33fd77e805f459649, uid : exit status 1: 2022/02/11 07:30:53 socat[11189] E connect(5, AF=2 127.0.0.1:28688, 16): Connection refused
E0211 13:00:57.780331   32764 portforward.go:400] an error occurred forwarding 28688 -> 28688: error forwarding port 28688 to pod 4805f6f9b6cc95dadc4f1b13f731023e9770512ac3c855d33fd77e805f459649, uid : exit status 1: 2022/02/11 07:30:57 socat[11240] E connect(5, AF=2 127.0.0.1:28688, 16): Connection refused
E0211 13:01:04.687295   32764 portforward.go:400] an error occurred forwarding 28688 -> 28688: error forwarding port 28688 to pod 4805f6f9b6cc95dadc4f1b13f731023e9770512ac3c855d33fd77e805f459649, uid : exit status 1: 2022/02/11 07:31:04 socat[11339] E connect(5, AF=2 127.0.0.1:28688, 16): Connection refused
E0211 13:01:17.123184   32764 portforward.go:400] an error occurred forwarding 28688 -> 28688: error forwarding port 28688 to pod 4805f6f9b6cc95dadc4f1b13f731023e9770512ac3c855d33fd77e805f459649, uid : exit status 1: 2022/02/11 07:31:17 socat[11475] E connect(5, AF=2 127.0.0.1:28688, 16): Connection refused
E0211 13:01:32.902946   32764 portforward.go:400] an error occurred forwarding 28688 -> 28688: error forwarding port 28688 to pod 4805f6f9b6cc95dadc4f1b13f731023e9770512ac3c855d33fd77e805f459649, uid : container not running (4805f6f9b6cc95dadc4f1b13f731023e9770512ac3c855d33fd77e805f459649)
E0211 13:02:00.469528   32764 portforward.go:400] an error occurred forwarding 28688 -> 28688: error forwarding port 28688 to pod 4805f6f9b6cc95dadc4f1b13f731023e9770512ac3c855d33fd77e805f459649, uid : container not running (4805f6f9b6cc95dadc4f1b13f731023e9770512ac3c855d33fd77e805f459649)
E0211 13:02:38.790813   32764 portforward.go:400] an error occurred forwarding 28688 -> 28688: error forwarding port 28688 to pod 4805f6f9b6cc95dadc4f1b13f731023e9770512ac3c855d33fd77e805f459649, uid : Error: No such container: 4805f6f9b6cc95dadc4f1b13f731023e9770512ac3c855d33fd77e805f459649
E0211 13:04:26.386046   32764 portforward.go:340] error creating error stream for port 28688 -> 28688: Timeout occured
E0211 13:06:54.472287   32764 portforward.go:362] error creating forwarding stream for port 28688 -> 28688: Timeout occured
E0211 13:09:18.214090   32764 portforward.go:362] error creating forwarding stream for port 28688 -> 28688: Timeout occured
E0211 13:11:40.227586   32764 portforward.go:340] error creating error stream for port 28688 -> 28688: Timeout occured
omrikiei commented 2 years ago

@kapilsingh421 could you please open a new issues as this is unrelated to the current thread and this issue? it looks like a problem during port forwarding, I see you're using an EKS cluster.. Which k8s client and server versions are you using? could you share the pod logs during the errors? (i.e kubectl logs flask-deployment-65dd887888-m2nlp)