Kubernetes two pods communication ( One is Beanstalkd and another is worker )

6/11/2021

I am working on kubernetes to create two pods using deployment: 1. First deployment - pods have container and running is beanstalkd. 2. The second one has a worker which is running on php7/nginx and has an application codebase.

I am getting exception:

"user_name":"anonymous","message":"exception 'Pheanstalk_Exception_ConnectionException' with message 'Socket error 0: php_network_getaddresses: getaddrinfo failed: Try again (connecting to test-beanstalkd:11300)' in /var/www/html/vendor/pda/pheanstalk/classes/Pheanstalk/Socket/NativeSocket.php:35\nStack trace:\n#0 "

How to communicate between them:

My beanstalkd.yaml

<!-- begin snippet: js hide: false console: true babel: false --><!-- language: lang-html -->
kind: Deployment
apiVersion: apps/v1
metadata:
  name: test-beanstalkd
  namespace: test
spec:
  replicas: 1
  selector:
    matchLabels:
      app: test-beanstalkd
  template:
    metadata:
      labels:
        app: test-beanstalkd
    spec:
      containers:
        # Our PHP-FPM application
        - image: schickling/beanstalkd
          name: test-beanstalkd
          args:
            - -p
            - "11300"
            - -z
            - "1073741824"
---
apiVersion: v1
kind: Service
metadata:
  name: test-beanstalkd-svc
  namespace: test
  labels:
    run: test-beanstalkd
spec:
  ports:
  - port: 11300
    protocol: TCP
  selector:
    app: test-beanstalkd
  selector:
    app: test-beanstalkd
  type: NodePort
<!-- end snippet -->

the below is our worker.yaml:

<!-- begin snippet: js hide: false console: true babel: false --><!-- language: lang-html -->
kind: Deployment
apiVersion: apps/v1
metadata:
  name: test-worker
  namespace: test
spec:
  replicas: 1
  selector:
    matchLabels:
      app: test-worker
  template:
    metadata:
      labels:
        app: test-worker
    spec:
      volumes:
      # Create the shared files volume to be used in both pods
        - name: shared-files
          emptyDir: {}
		  
      containers:
        # Our PHP-FPM application
        - image: test-worker:master
          name: worker
          env:
           - name: beanstalkd_host
             value: "test-beanstalkd"
          volumeMounts:
           - name: nginx-config-volume
             mountPath: /etc/nginx/nginx.conf
             subPath: nginx.conf
---
apiVersion: v1
kind: Service
metadata:
  name: test-worker-svc
  namespace: test
  labels:
    run: test-worker
spec:
  ports:
  - port: 80
    protocol: TCP
  selector:
    app: worker
  type: NodePort
<!-- end snippet -->
-- Parvez Alam
kubernetes

1 Answer

6/11/2021

the mistake is that in the env of test-worker the beanstalkd_host variable needs to be set to test-beanstalkd-svc because it is the name of the service.

-- danny kaplunski
Source: StackOverflow