-
Notifications
You must be signed in to change notification settings - Fork 37
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
Comments
Hi @ugandhar84 , you can initialize the KubeLibrary with the paramater
You can read about it in the keyword documentation here. |
Thank you for your response. it didn't help.
one more point is I'm running a ROBOT script from a remote SSH session
using SSHLIbrary. How do both Libraries sync to send these commands?
Initializing library 'KubeLibrary' with arguments [ incluster=True ]
failed: C
onfigException: Service host/port is not set.
Traceback (most recent call last):
File
"/home/ugandhar/.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/ugandhar/.local/lib/python3.10/site-packages/KubeLibrary/KubeLibrary.py",
line 256, in reload_config
raise e
File
"/home/ugandhar/.local/lib/python3.10/site-packages/KubeLibrary/KubeLibrary.py",
line 253, in reload_config
config.load_incluster_config()
File
"/home/ugandhar/.local/lib/python3.10/site-packages/kubernetes/config/incluster_config.py",
line 121, in load_incluster_config
try_refresh_token=try_refresh_token).load_and_set(client_configuration)
File
"/home/ugandhar/.local/lib/python3.10/site-packages/kubernetes/config/incluster_config.py",
line 54, in load_and_set
self._load_config()
File
"/home/ugandhar/.local/lib/python3.10/site-packages/kubernetes/config/incluster_config.py",
line 62, in _load_config
raise ConfigException("Service host/port is not set.")
kubernetes.config.config_exception.ConfigException: Service host/port is
not set.
|
With So you use the SSH library to connect into a container running in a k8s cluster? |
Yes, I'm using the ROBOT from my local and SSH library to connect remote
systems and from there exporting the kubeconfig for the cluster. Seems like
the SSH library and KubeLibrary is not working in that way.
Write Get Pods
Write for Interactive Mode SSH and Get Pods from Kube Lib
|
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 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/ |
I appreciate your input and suggestions I’ve multiple jump servers in
between cluster and local 🖥️. I’m just exploring another solution to use
fabric .. fabric is doing okay with ssh tunnel with target host here the
problem is if I set kubeconfig it is not accessible for the next subsequent
command seems every command using different shell session :( would you mind
to help here to make session as interactive or holding same session un till
connection close?..
Local -> jump -> kubectl (remote)
classRemoteShell:
def__init__(self,jump_host,jump_username,jump_password,host,username,
password,jump_port=2212,port=22,timeout=60,interval=1):
self.timeout=timeout
self.interval=interval#Defaultintervalforcheckingoutput
self.timer=None
#CreateaFabricconfigurationforthejumphost
jump_config=Config(overrides={'user':jump_username,'connect_kwargs':{
'password':jump_password}})
try:
#Connecttothejumphost
self.jump_connection=Connection(host=jump_host,user=jump_username,
connect_kwargs={'password':jump_password},port=jump_port)
self.jump_connection.open()
#Findafreeportonlocalhost(127.0.0.1)
local_port=self._find_free_port()
#Establishaconnectiontotheactualremoteserverfromthejumphost
self.remote_connection=Connection(host=host,user=jump_username,port=port,connect_kwargs{'password':jump_password},gateway=self
.jump_connection)
self.remote_connection.open()
except(SSHException,socket.error)as e:
raiseConnectionError(f"Failedtoconnecttoremoteserver:{e}")
#Storetheoutputofthelastcommand
self.last_output=""
def send_command(self,command):
#Startthetimer
self.start_timer()
try:
#Executethecommandinteractively
result=self.remote_connection.run(command,pty=True)
exceptSSHExceptionase:
raiseRuntimeError(f"Errorexecutingcommand:{e}")
finally:
#Stopthetimer
self.stop_timer()
#Storetheoutputofthelastcommand
self
.last_output=result.stdout.strip(),result.stderr.strip(),result.return_code
#ConvertANSIescapesequencestoplaintext
self.last_output=self._ansi_to_text(self.last_output[0]),self._ansi_to_text(
self.last_output[1]),\
self.last_output[2]
#Returntheoutputofthelastcommand
returnself.last_output
defget_last_output(self):
#Returntheoutputofthelastcommand
returnself.last_output
defclose(self):
try:
self.remote_connection.close()
self.jump_connection.close()
exceptSSHExceptionase:
raiseRuntimeError(f"Errorclosingconnection:{e}")
|
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.
The text was updated successfully, but these errors were encountered: