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