我正在尝试在自己的裸机 Kubernetes 基础架构上安装 nextcloud(我有 3 个工作节点),但当 nextcloud 容器尝试连接到 mariadb 容器时遇到了问题。由于我使用 nodePort 服务和 hostNetwork,我可以使用工作节点上的所有 IP 地址访问 mariadb。问题出在两个容器之间的通信上。
我的 nextcloud 配置:
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
我的 mariadb 配置:
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
豆荚:
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>
服务:
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
nextcloud 容器内的 /etc/resolv.conf:
search nextcloud.svc.cluster.local svc.cluster.local cluster.local v.cablecom.net
nameserver 10.96.0.10
options ndots:5
我删除并重新创建了部署(这次没有hostNetwork
在容器配置中设置,现在出现此错误:
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