0

I am trying to install nextcloud on my own bare-metal Kubernetes infrastructure (I have 3 worker nodes), but i run into an issue when the nextcloud container tries to connect to the mariadb container. I can access mariadb with every IP addresses from my worker nodes as I am using nodePort services and the hostNetwork. The issue is in the communication between the 2 containers.

My nextcloud config :

apiVersion: v1
kind: Service
metadata:
  name: nextcloud
  namespace: nextcloud
spec:
  type: NodePort
  ports:
    - name: http
      port: 80
      targetPort: 80
      nodePort: 30001
      protocol: TCP
  selector:
    app: nextcloud
    tier: frontend
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: nextcloud-pv-claim
  namespace: nextcloud
  labels:
    app: nextcloud
spec:
  storageClassName: rook-ceph-block
  accessModes:
  - ReadWriteOnce
  resources:
    requests:
      storage: 20Gi
---
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: nextcloud
  name: nextcloud
  namespace: nextcloud
spec:
  replicas: 1
  strategy:
    type: Recreate
  selector:
    matchLabels:
      app: nextcloud
      tier: frontend
  template:
    metadata:
      labels:
        app: nextcloud
        tier: frontend
    spec:
      hostNetwork: true
      containers:
      - env:
        - name: NEXTCLOUD_ADMIN_USER
          value: admin
        - name: NEXTCLOUD_ADMIN_PASSWORD
          value: ********
        - name: MYSQL_DATABASE
          value: nextcloud
        - name: MYSQL_HOST
          value: database-nextcloud
        - name: MYSQL_PASSWORD
          value: **********
        - name: MYSQL_USER
          value: nextcloud
        name: nextcloud
        image: nextcloud
        ports:
        - containerPort: 80
          protocol: TCP
        terminationMessagePath: /dev/termination-log
        terminationMessagePolicy: File
        volumeMounts:
        - mountPath: /var/www/html
          name: html
      restartPolicy: Always
      volumes:
        - name: html
          persistentVolumeClaim:
              claimName:  nextcloud-pv-claim

My mariadb config :

apiVersion: v1
kind: Service
metadata:
  name: database-nextcloud
  namespace: nextcloud
spec:
  type: NodePort
  ports:
    - name: mariadb
      port: 3306
      targetPort: 3306
      nodePort: 30002
      protocol: TCP
  selector:
    app: database-nextcloud
    tier: backend
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: database-nextcloud-pv-claim
  namespace: nextcloud
  labels:
    app: database-nextcloud
spec:
  storageClassName: rook-ceph-block
  accessModes:
  - ReadWriteOnce
  resources:
    requests:
      storage: 8Gi
---
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: database-nextcloud
    tier: backend
  name: database-nextcloud
  namespace: nextcloud
spec:
  replicas: 1
  strategy:
    type: Recreate
  selector:
    matchLabels:
      app:  database-nextcloud
      tier: backend
  template:
    metadata:
      labels:
        app: database-nextcloud
        tier: backend
    spec:
      containers:
      - env:
        - name: MYSQL_DATABASE
          value: nextcloud
        - name: MYSQL_PASSWORD
          value: **********
        - name: MYSQL_USER
          value: nextcloud
        - name: MYSQL_ROOT_PASSWORD
          value: ***********
        image: mariadb
        name: database-nextcloud
        volumeMounts:
        - mountPath: /var/lib/mysql
          name: database-nextcloud
        ports:
        - containerPort: 3306
          protocol: TCP
      restartPolicy: Always
      volumes:
      - name: database-nextcloud
        persistentVolumeClaim:
            claimName: database-nextcloud-pv-claim

The pods:

kubectl get pods -o wide -n nextcloud
NAME                                  READY   STATUS    RESTARTS   AGE     IP              NODE   NOMINATED NODE   READINESS GATES
database-nextcloud-7f488f5894-5bmqz   1/1     Running   0          6m22s   192.168.0.101   pwe1   <none>           <none>
nextcloud-67bf849f44-m42nc            1/1     Running   1          13d     192.168.0.101   pwe1   <none>           <none>

The services:

kubectl get service -n nextcloud
NAME                 TYPE       CLUSTER-IP       EXTERNAL-IP   PORT(S)          AGE
database-nextcloud   NodePort   10.106.57.87     <none>        3306:30002/TCP   13d
nextcloud            NodePort   10.106.140.209   <none>        80:30001/TCP     13d

the /etc/resolv.conf inside the nextcloud container:

search nextcloud.svc.cluster.local svc.cluster.local cluster.local v.cablecom.net
nameserver 10.96.0.10
options ndots:5

I deleted and recreated the deployment (this time without setting hostNetwork in the container config and I now get this error :

Error while trying to create admin user: Failed to connect to the database: An exception occurred in driver: SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Temporary failure in name resolution
  • You will have to [edit your question](https://serverfault.com/posts/1023089/edit) and provide the logs from your nextcloud pod that shows what, specifically, the error is you are encountering; we cannot _guess_ what it is – mdaniel Jun 28 '20 at 02:01
  • @mdaniel I don't have anything wrong in the pods logs, I was thinking the issue might be with the way I have the database and nextcloud setup (both on NodePort) or that I was missing something on my baremetal install of kubernetes – Alexandre Philibert Jul 04 '20 at 12:54
  • @AlexandrePhilibert Like mentioned by mdaniel, without any kind of log or error we are not able to help you. – Wytrzymały Wiktor Jul 07 '20 at 07:42
  • @OhHiMark Okay so I've made some progress, I removed the "hostNetwork: true" form the deployment config. I think that the Nextcloud pod could not access the database as it had no access the the kubernetes DNS. Now that this seems fixed, how can I access my nextcloud pod from the outside ? – Alexandre Philibert Jul 12 '20 at 09:47
  • @AlexandrePhilibert It would be better if you describe your solution as an answer and than write a separate question for your second topic. That way it will be way clearer for the rest of the community and much more likely to get a meaningful answer. – Wytrzymały Wiktor Jul 13 '20 at 07:29

0 Answers0