Deploying a CouchDB Cluster on Kubernetes

12/5/2021

I am deploying a CouchDB cluster on Kubernetes and I'm getting an error when I configuring this Cluster.

  • Kubernetes Version: 1.22.4
  • Docker Version 20.10.11, build dea9396
  • Ubuntu 20.04

When I run "kubectl exec couchdb-0 -i -t -- bash" and "curl -X POST -H "Content-Type: application/json" http://admin:admin@127.0.0.1:5984/_cluster_setup -d '{"action": "enable_cluster", "bind_address":"0.0.0.0", "username": "admin", "password":"admin", "node_count":"3"}'" to config Cluster...

I am getting this error "curl: (7) Failed to connect to 127.0.0.1 port 5984: Connection refused"

I think CouchDB is still not installed successfully. When i check it with the command "curl http://127.0.0.1:5984/". It show an error "curl: (7) Failed to connect to 127.0.0.1 port 5984: Connection refused"

How can I fix it !?

This is "pv.yaml"

---
    apiVersion: v1
    kind: PersistentVolume
    metadata:
      name: couch-vol-0
      labels:
        volume: couch-volume
    spec:
      capacity:
        storage: 10Gi
      accessModes:
        - ReadWriteOnce
      nfs:
        server: 192.168.1.100
        path: "/var/couchnfs/couchdb-0"
    ---
    apiVersion: v1
    kind: PersistentVolume
    metadata:
      name: couch-vol-1
      labels:
        volume: couch-volume
    spec:
      capacity:
        storage: 10Gi
      accessModes:
        - ReadWriteOnce
      nfs:
        server: 192.168.1.100
        path: "/var/couchnfs/couchdb-1"
    ---
    apiVersion: v1
    kind: PersistentVolume
    metadata:
      name: couch-vol-2
      labels:
        volume: couch-volume
    spec:
      capacity:
        storage: 10Gi
      accessModes:
        - ReadWriteOnce
      nfs:
        server: 192.168.1.100
        path: "/var/couchnfs/couchdb-2"

This is "couchdb-statefulset.yaml"

---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: couchdb
  labels:
    app: couch
spec:
  replicas: 3
  serviceName: "couch-service"
  selector:
    matchLabels:
      app: couch
  template:
    metadata:
      labels:
        app: couch # pod label
    spec:
      containers:
      - name: couchdb
        image: couchdb:2.3.1
        command: [ "/bin/bash", "-ce", "tail -f /dev/null" ]
        env:
        - name: NODE_NETBIOS_NAME
          valueFrom:
            fieldRef:
              fieldPath: metadata.name
        - name: NODENAME
          value: $(NODE_NETBIOS_NAME).couch-service # FQDN in vm.args
        - name: COUCHDB_USER
          value: admin
        - name: COUCHDB_PASSWORD
          value: admin
        - name: COUCHDB_SECRET
          value: couchsecret
        - name: ERL_FLAGS
          value: "-name couchdb@$(NODENAME)"
        - name: ERL_FLAGS
          value: "-setcookie couchsecret" #   the “password” used when nodes connect to each other.
        ports:
        - name: couchdb
          containerPort: 5984
        - name: epmd
          containerPort: 4369
        - containerPort: 9100
        volumeMounts:
          - name: couch-pvc
            mountPath: /opt/couchdb/data
  volumeClaimTemplates:
  - metadata:
      name: couch-pvc
    spec:
      accessModes: ["ReadWriteOnce"]
      resources:
        requests:
          storage: 10Gi
      selector:
        matchLabels:
          volume: couch-volume

This is "service.yaml"

---
apiVersion: v1
kind: Service
metadata:
  name: couch-service
  namespace: default
  labels:
    app: couch
spec:
  type: ClusterIP
  clusterIP: None
  ports:
  - port: 5984
    protocol: TCP
    targetPort: 5984
  selector:
    app: couch         # label selector
---
kind: Service
apiVersion: v1
metadata:
  name: couch-nodep-svc 
  labels:
    app: couch
spec:
  type: NodePort            # NodePort service
  ports:
  - port: 5984
    nodePort: 30984         # external port
    protocol: TCP
  selector:
    app: couch       # label selector
-- cksawd
couchdb
kubernetes
kubernetes-statefulset

0 Answers