Connection refused error when deploying couchbase in kubernetes {failed to connect to 127.0.0.1 port 8091: Connection refused}

5/2/2020

I used the following yaml files to deploy couchbase in kubernetes.

Master:

apiVersion: v1  
kind: ReplicationController  
metadata:  
  name: couchbase-master-rc
spec:  
  replicas: 1  
  selector:  
    app: master-pod  
  template:  
    metadata:  
      labels:  
        app: master-pod  
    spec:  
      containers:  
      - name: couchbase-master  
        image: arungupta/couchbase:k8s 
        env:  
          - name: TYPE  
            value: MASTER  
        ports:  
        - containerPort: 8091 
---
apiVersion: v1  
kind: Service  
metadata:   
  name: couchbase-master-service  
  labels:   
    app: couchbase-master-service  
spec:   
  ports:  
    - port: 8091  
  selector:   
    app: master-pod  
  type: LoadBalancer

Worker:

apiVersion: v1  
kind: ReplicationController  
metadata:  
  name: couchbase-worker-rc  
spec:  
  replicas: 1  
  selector:  
    app: couchbase-worker-pod  
  template:  
    metadata:  
      labels:  
        app: couchbase-worker-pod  
    spec:  
      containers:  
      - name: couchbase-worker  
        image: arungupta/couchbase:k8s  
        env:  
          - name: TYPE  
            value: "WORKER"  
          - name: COUCHBASE_MASTER  
            value: "couchbase-master-service"  
          - name: AUTO_REBALANCE  
            value: "false"  
        ports:  
        - containerPort: 8091

Ingress:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: couchbase
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /
spec:
  rules:
  - host: xxx.com
    http:
      paths:
      - path: /
        backend:
          serviceName: couchbase-master-service
          servicePort: 8091

The pods started running and nothing seems to have an issue at first glance. But when I tried to hit the HostUrl it gives me bad gateway. And when I look into the logs of master's pod it shows me connection refused at 127.0.0.1:8091. I tried to exec into the pod and apply the curl statements from entrypoint.sh manually, but it also gave me the error "failed to connect to 127.0.0.1 port 8091: Connection refused". enter image description here

-- Gill Varghese Sajan
connection
couchbase
deployment
docker
kubernetes

1 Answer

5/4/2020

I have found that master image is using this entrypoint script

I ran this container image and it looks like the curl is failing because 15s sleep is not enough time for couchbase-server to start and open 8091 port.

The easiest thing you could do is to set this sleep to higher value, but sleep is usually not the best option. (Actually this whole image is full of bad practises).

Better approach would be to replace sleep with following lines that wait until port 8091 is open:

while ! nc -z localhost 8091; do   
  sleep 1
done
-- HelloWorld
Source: StackOverflow