Closed georgebarbarosie closed 1 year ago
@georgebarbarosie Hi, thanks for reaching out.
I believe that kubectl-relay uses --all-namespaces (when no --namespace flag has been provided) to look up the service to connect to
krelay
never searches all namespaces for the Service, let alone this is inefficient. krelay
reads the target namespace from kubeconfig
(the namespace set in the context) and the --namespace
flag https://github.com/knight42/krelay/blob/2dc5ecaf67961ae89c997f023039649c6382bedc/cmd/client/main.go#L65-L68.
I am not sure why krelay
will connect to a nonexistent service, could you post the output of kubectl relay svc/mysvc 8080 -v=7
?
@knight42 shortly after I opened this bug report I realized the problem is not specific to this kubectl plugin, I'm also using cnpg's plugin and the behaviour is similar. This "bug" (I hesitate to call it that, now that I see what's causing it) manifests for a very particular setup. I spread my cluster configs across many files and set $KUBECONFIG appropriately to include them all;
There was a conflict between two of the files, it went unnoticed until now as kubectl was consistent with the merging. The plugins seem to be applying a different merging order. kubectl picks up the configured namespace from the leftmost file, the plugin picks up the configured namespace from the rightmost file.
I have fixed this by eliminating the duplication of the context definition.
I believe that kubectl-relay uses
--all-namespaces
(when no--namespace
flag has been provided) to look up the service to connect to, instead of looking in the context's configured namespace.I have a service
mysvc
of type ClusterIP, in a namespace calledstaging
. The current namespace (default) doesn't have a service with that name:kubectl get svc -o name mysvc
showsError from server (NotFound): services "mysvc" not found
, whereaskubectl get svc -o name mysvc -n staging
showsservice/mysvc
. However I can executekubectl relay svc/mysvc 8080
and I can connect to the forwarded port.This is annoying because it means there is no guarantee that the relay will connect to the service(s) in the current namespace when there are services with the same name in other namespaces. The workaround is to explicitly specify the
--namespace
, but this is unexpected behaviour. I have bumped into exactly this situation when I discovered this anomaly, where I was expecting krelay to forward to one service but it was forwarding to a service in a different namespace.