0

I have a pod definition file:

apiVersion: v1
kind: Pod
metadata:
  name: redis-master
  namespace: sandbox
  labels:
    app: redis
spec:
  containers:
    - name: master
      image: redis
      command:
      - redis-server
      env:
        - name: MASTER
          value: "true"
      ports:
        - containerPort: 6379

when I convert it to job like it follows:

apiVersion: batch/v1
kind: Job
metadata:
  name: redis-master
  namespace: sandbox
spec:
  parallelism: 1
  ttlSecondsAfterFinished: 10
  template:
    spec:
      containers:
        - name: master
          image: redis
          command:
          - redis-server
          env:
            - name: MASTER
              value: "true"
          ports:
            - containerPort: 6379
      restartPolicy: Never
apiVersion: v1
kind: Service
metadata:
  name: redis
  namespace: sandbox
spec:
  ports:
    - port: 6379
      targetPort: 6379
  selector:
    app: redis

I get an error from script:

Worker with sessionID: c7537dc0-0a7c-4d8e-a845-b863441f6433
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/redis/connection.py", line 614, in connect
    sock = self.retry.call_with_retry(
  File "/usr/local/lib/python3.10/site-packages/redis/retry.py", line 45, in call_with_retry
    return do()
  File "/usr/local/lib/python3.10/site-packages/redis/connection.py", line 615, in <lambda>
    lambda: self._connect(), lambda error: self.disconnect(error)
  File "/usr/local/lib/python3.10/site-packages/redis/connection.py", line 680, in _connect
    raise err
  File "/usr/local/lib/python3.10/site-packages/redis/connection.py", line 668, in _connect
    sock.connect(socket_address)
ConnectionRefusedError: [Errno 111] Connection refused
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "//worker.py", line 16, in <module>
    print("Initial queue state: empty=" + str(q.empty()))
  File "/rediswq.py", line 56, in empty
    return self._main_qsize() == 0 and self._processing_qsize() == 0
  File "/rediswq.py", line 45, in _main_qsize
    return self._db.llen(self._main_q_key)
  File "/usr/local/lib/python3.10/site-packages/redis/commands/core.py", line 2498, in llen
    return self.execute_command("LLEN", name)
  File "/usr/local/lib/python3.10/site-packages/redis/client.py", line 1215, in execute_command
    conn = self.connection or pool.get_connection(command_name, **options)
  File "/usr/local/lib/python3.10/site-packages/redis/connection.py", line 1386, in get_connection
    connection.connect()
  File "/usr/local/lib/python3.10/site-packages/redis/connection.py", line 620, in connect
    raise ConnectionError(self._error_message(e))
redis.exceptions.ConnectionError: Error 111 connecting to 10.104.106.102:6379. Connection refused.

script is:

#!/usr/bin/env python

import time
import rediswq
from datetime import datetime
import os
#import subprocess

#host="redis"
# Uncomment next two lines if you do not have Kube-DNS working.
import os
host = os.getenv("REDIS_SERVICE_HOST")

q = rediswq.RedisWQ(name="dealer_codes", host=host)
print("Worker with sessionID: " +  q.sessionID())
print("Initial queue state: empty=" + str(q.empty()))
while not q.empty():
  item = q.lease(lease_secs=10, block=True, timeout=2)
  if item is not None:
    itemstr = item.decode("utf-8")
    time.sleep(10) # Put your actual work here instead of sleep.
    q.complete(item)
  else:
    print("Waiting for work")
print("Queue empty, exiting")
1
  • There's some missing information here: Where are you running your script? When you submit your Job manifest to Kubernetes, does it run successfully? Is the Pod running when you try to connect to it using your script? Why are you creating what looks like a persistent Redis service using a Job?
    – larsks
    May 8 at 2:17

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.