Communicating using Pyro5 in kubernetes

37 views Asked by At

I'm trying to deploy a couple of Pyro5 objects to be able to have other services communicate with them on a kubernetes cluster. Moving from a docker-compose setup it was working fine and well by just specifying the host as the name like this myObject = Pyro5.server.Daemon(host="python2", port=9091) and services would easily resolve the pyro server by the name python2.

Now after moving to a k8s-based environment when I released it with a ClusterIP service with the same name so I could replicate the action, I get this error from the pod.

    d = Pyro5.server.Daemon(host="python2", port=9091)
  File "/code/venv/lib/python3.7/site-packages/Pyro5/server.py", line 232, in __init__
    self.transportServer.init(self, host, port, unixsocket)
  File "/code/venv/lib/python3.7/site-packages/Pyro5/svr_threads.py", line 129, in init
    sslContext=sslContext)
  File "/code/venv/lib/python3.7/site-packages/Pyro5/socketutil.py", line 278, in create_socket
    sock.bind(bind)
OSError: [Errno 99] Cannot assign requested address

Anything I'm missing here?

1

There are 1 answers

1
Dion V On BEST ANSWER

The error may be an indication that the Pyro5 server is unable to bind to the requested address.

It seems that the issue is related to the Kubernetes environment. When the host as the name of the ClusterIP service was specified, Pyro5 server is unable to bind to the address because it is not available. This is because the ClusterIP service is not a real IP address, but a rather a virtual IP address that is only accessible within the Kubernetes cluster.

You can set your Pyro5 server to bind to the IP address of the Kubernetes pod instead of the ClusterIP service. You can try to query the Kubernetes API to obtain the IP address of the pod and then bind it with the Pyro5 server. Here's an example

import requests
import socket
import Pyro5.server

# Get the pod IP address
pod_ip = requests.get("http://169.254.169.254/latest/meta-data/local-ipv4").text

# Bind the Pyro5 server to the pod IP address
d = Pyro5.server.Daemon(host=pod_ip, port=9091)