Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to initialize library without kube config as im already in the current context via sshlibrary #142

Open
ugandhar84 opened this issue Mar 18, 2024 · 6 comments

Comments

@ugandhar84
Copy link

ugandhar84 commented Mar 18, 2024

I'm already in the K8S cluster with proper context set via SSHLibrary Keywords in interactive shell. I want to avoid login kube config. how can i skip this. Please suggest.

Initializing library 'KubeLibrary' with arguments [ INIT_FOR_LIBDOC_ONLY=1 ] f
ailed: ConfigException: Invalid kube-config file. No configuration found.
Traceback (most recent call last):
File "/home/xx/.local/lib/python3.10/site-packages/KubeLibrary/KubeLibrary.py", line 97, in init
self.reload_config(kube_config=kube_config, context=context, api_url=api_url, bearer_token=bearer_token,
File "/home/xx/.local/lib/python3.10/site-packages/KubeLibrary/KubeLibrary.py", line 270, in reload_config
config.load_kube_config(kube_config, context)
File "/home/user/.local/lib/python3.10/site-packages/kubernetes/config/kube_config.py", line 815, in load_kube_config
loader = _get_kube_config_loader(
File "/home/xx/.local/lib/python3.10/site-packages/kubernetes/config/kube_config.py", line 772, in _get_kube_config_loader
raise ConfigException(
kubernetes.config.config_exception.ConfigException: Invalid kube-config file. No configuration found.

@Nilsty
Copy link
Collaborator

Nilsty commented Mar 18, 2024

Hi @ugandhar84 , you can initialize the KubeLibrary with the paramater incluster=True

Library          KubeLibrary    incluster=True

You can read about it in the keyword documentation here.

@ugandhar84
Copy link
Author

ugandhar84 commented Mar 18, 2024 via email

@Nilsty
Copy link
Collaborator

Nilsty commented Mar 18, 2024

With incluster=True the KubeLibrary calles this function in the python kubernetes client. The error message Service host/port is not set. means that it can not find the environment variables KUBERNETES_SERVICE_HOST and KUBERNETES_SERVICE_PORT and therefore can not make the connection to the kubernetes API of your cluster. Usually those env variables are available in any container running in a k8s cluster.

So you use the SSH library to connect into a container running in a k8s cluster?

@ugandhar84
Copy link
Author

ugandhar84 commented Mar 18, 2024 via email

@Nilsty
Copy link
Collaborator

Nilsty commented Mar 19, 2024

hmm... You somehow need to run the robot test with the KubeLibrary inside the host, you are connecting to via SSH. I have not used the SSH lib myself, but I guess you could use Execute Command robot my-kube-libtests.robot to run the tests in the remote host. Not sure if this works for you.

I'm assuming here that you can not access the KubeAPI directly as the cluster is not exposing the access to its API. Maybe a better solution could be to use a proxy inside the cluster to expose the KubeAPI to your local system. Here is an example for that: https://kubernetes.io/docs/tasks/extend-kubernetes/socks5-proxy-access-api/
Then you would not need the SSH tunnel and could directly access the clusters KubeAPI.

@ugandhar84
Copy link
Author

ugandhar84 commented Mar 19, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants