I'm managing a Kubernetes cluster and want Pod1 to make API calls to Pod2 and Pod3 (but Pod1 - Pod3 fails!):
- Pod1: A Jupyter Notebook environment to test connections.
- Pod2: An Express.js app running on port 8000, exposed on port 80 via the
express-backend-service
. - Pod3: A python scrapy application with ScrapyRT listening on port 14805, exposed on port 80 via
getcookie-14805-service
.
Pod2 Service and Deployment (express-backend-service):
express-deployment.yaml:
apiVersion: apps/v1kind: Deploymentmetadata: name: express-app-deploymentspec: #... containers: - name: express-app image: privaterepo/myproject-backend:latest ports: - containerPort: 8000 #...
express-service.yaml:
apiVersion: v1kind: Servicemetadata: name: express-backend-servicespec: selector: app: express-app ports: - protocol: TCP port: 80 targetPort: 8000 type: ClusterIP
Pod3 Service and Deployment (getcookie-14805-service):
getcookie-14805-deployment.yaml:
apiVersion: apps/v1kind: Deploymentmetadata: name: getcookie-14805-deploymentspec: #... containers: - name: getcookie-14805 image: privaterepo/myproject-scrapy:latest ports: - containerPort: 14805 #...
getcookie-14805-service.yaml:
apiVersion: v1kind: Servicemetadata: name: getcookie-14805-servicespec: selector: app: getcookie-14805 ports: - protocol: TCP port: 80 targetPort: 14805 type: ClusterIP
Issue:
I can successfully send requests from Pod1 to Pod2 using the service name http://express-backend-service/api. However, when attempting to connect to Pod3 using a similar approach, I get a connection error.
Here's the Python code snippet used in Pod1 to connect to Pod3:
def getCookie(userId): endpoint = 'http://getcookie-14805-service.default/crawl.json?spider_name=getCookie&url=http://images.google.com/' post = {"request": {"url": "http://images.google.com/","meta": {'userId': userId},"callback": "parse","dont_filter": "True" },"spider_name": "getCookie" } try: response = requests.post(endpoint, json=post).json() return response['items'][0]['finalItems'] except Exception as e: print('getCookie error:', e) return Noneuser = '6010dga53294c92c981ef3y576'getCookie(user)
Error received:
ConnectionError: HTTPConnectionPool(host='getcookie-14805-service.default', port=80): Max retries exceeded with url: /crawl.json?spider_name=getCookie&url=http://images.google.com/ (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7fde7a6cc7f0>: Failed to establish a new connection: [Errno 111] Connection refused'))
Why can I successfully make calls from Pod1 to Pod2 but not from Pod1 to Pod3?
I expected the Kubernetes services to facilitate inter-pod communication. Do I need additional configuration?