Issue
Hello, I want to set up a Nextcloud w/ Postgres as a database instance on my Kubernetes cluster. However, when I define the env variables for Postgres in the Nextcloud deployment file, the Nextcloud pod instance can't connect to the Postgres pod instance based on the service name. If anyone can give me any suggestions on what to do to solve this, please. Thank you in advance.
Error
Here is the result of kubectl logs <pod-name>
command for the Nexcloud pod instance:
Previous: Doctrine\DBAL\Exception: Failed to connect to the database: An exception occurred in the driver: SQLSTATE[08006] [7] could not translate host name "home-drive-db" to address: Temporary failure in name resolution
Trace: #0 /var/www/html/lib/private/Setup/PostgreSQL.php(98): OC\DB\Connection->connect()
#1 /var/www/html/lib/private/Setup.php(351): OC\Setup\PostgreSQL->setupDatabase('rafidini')
#2 /var/www/html/core/Command/Maintenance/Install.php(108): OC\Setup->install(Array)
#3 /var/www/html/3rdparty/symfony/console/Command/Command.php(255): OC\Core\Command\Maintenance\Install->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#4 /var/www/html/3rdparty/symfony/console/Application.php(1009): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#5 /var/www/html/3rdparty/symfony/console/Application.php(273): Symfony\Component\Console\Application->doRunCommand(Object(OC\Core\Command\Maintenance\Install), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#6 /var/www/html/3rdparty/symfony/console/Application.php(149): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#7 /var/www/html/lib/private/Console/Application.php(209): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#8 /var/www/html/console.php(99): OC\Console\Application->run()
#9 /var/www/html/occ(11): require_once('/var/www/html/c...')
#10 {main}
retrying install...
Files
home-drive-db.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: home-drive-app
name: home-drive-db
spec:
replicas: 1
selector:
matchLabels:
pod-label: home-drive-db-pod
app: home-drive-app
template:
metadata:
labels:
pod-label: home-drive-db-pod
app: home-drive-app
spec:
containers:
- name: home-drive-db
image: postgres:alpine
resources:
limits:
memory: 512Mi
cpu: "1"
requests:
memory: 256Mi
cpu: "0.2"
ports:
- containerPort: 5432
env:
- name: POSTGRES_DB
value: nextcloud
- name: POSTGRES_USER
value: rafidini
- name: POSTGRES_PASSWORD
value: password1
volumeMounts:
- name: db-storage
mountPath: /var/lib/postgresl/data
subPath: postgres
volumes:
- name: db-storage
persistentVolumeClaim:
claimName: home-drive-shared-storage
---
apiVersion: v1
kind: Service
metadata:
labels:
app: home-drive-app
name: home-drive-db
spec:
type: ClusterIP
selector:
pod-label: home-drive-db-pod
app: home-drive-app
ports:
- port: 5432
protocol: TCP
targetPort: 5432
home-drive-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
appe: home-drive-app
name: home-drive-server
spec:
replicas: 1
selector:
matchLabels:
pod-label: home-drive-server-pod
app: home-drive-app
template:
metadata:
labels:
pod-label: home-drive-server-pod
app: home-drive-app
spec:
containers:
- image: nextcloud:production
ports:
- containerPort: 5432
env:
- name: POSTGRES_HOST
value: home-drive-db:5432
- name: POSTGRES_DB
value: nextcloud
- name: POSTGRES_USER
value: rafidini
- name: POSTGRES_PASSWORD
value: password1
- name: NEXTCLOUD_ADMIN_USER
value: rafidini
- name: NEXTCLOUD_ADMIN_PASSWORD
value: password1
resources:
limits:
memory: 1Gi
cpu: "1"
requests:
memory: 256Mi
cpu: "1"
name: home-drive-app
volumeMounts:
- name: server-storage
mountPath: /var/www/html
subPath: server-data
volumes:
- name: server-storage
persistentVolumeClaim:
claimName: home-drive-shared-storage
---
apiVersion: v1
kind: Service
metadata:
labels:
app: home-drive-app
name: home-drive-server
spec:
selector:
app: home-drive-app
pod-label: home-drive-server-pod
ports:
- protocol: TCP
port: 80