我在谷歌云平台上使用 helm 和 kubernetes。
我的 postgres 部署出现以下错误:
SchedulerPredicates failed due to PersistentVolumeClaim is not bound
看起来它无法连接到持久存储,但我不明白为什么,因为持久存储加载正常。
我已经尝试完全删除 helm 版本,然后在 google-cloud-console > compute-engine > disks 上;我已经删除了所有永久性磁盘。最后尝试从 helm chart 安装,但是 postgres 部署仍然没有连接到 PVC。
我的数据库配置:
{{- $serviceName := "db-service" -}}
{{- $deploymentName := "db-deployment" -}}
{{- $pvcName := "db-disk-claim" -}}
{{- $pvName := "db-disk" -}}
apiVersion: v1
kind: Service
metadata:
name: {{ $serviceName }}
labels:
name: {{ $serviceName }}
env: production
spec:
type: LoadBalancer
ports:
- port: 5432
targetPort: 5432
protocol: TCP
name: http
selector:
name: {{ $deploymentName }}
---
apiVersion: apps/v1beta1
kind: Deployment
metadata:
name: {{ $deploymentName }}
labels:
name: {{ $deploymentName }}
env: production
spec:
replicas: 1
template:
metadata:
labels:
name: {{ $deploymentName }}
env: production
spec:
containers:
- name: postgres-database
image: postgres:alpine
imagePullPolicy: Always
env:
- name: POSTGRES_USER
value: test-user
- name: POSTGRES_PASSWORD
value: test-password
- name: POSTGRES_DB
value: test_db
- name: PGDATA
value: /var/lib/postgresql/data/pgdata
ports:
- containerPort: 5432
volumeMounts:
- mountPath: "/var/lib/postgresql/data/pgdata"
name: {{ $pvcName }}
volumes:
- name: {{ $pvcName }}
persistentVolumeClaim:
claimName: {{ $pvcName }}
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: {{ $pvcName }}
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
selector:
matchLabels:
name: {{ $pvName }}
env: production
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: {{ .Values.gcePersistentDisk }}
labels:
name: {{ $pvName }}
env: production
annotations:
volume.beta.kubernetes.io/mount-options: "discard"
spec:
capacity:
storage: 10Gi
accessModes:
- ReadWriteOnce
gcePersistentDisk:
fsType: "ext4"
pdName: {{ .Values.gcePersistentDisk }}
kubenetes 的这个配置正确吗?我已经阅读了文档,看起来这应该可以。我是 Kubernetes 和掌舵的新手,所以任何建议都值得赞赏。
编辑:
我添加了一个 PersistentVolume 并将其链接到 PersistentVolumeClaim 以查看是否有帮助,但似乎当我这样做时,PersistentVolumeClaim 状态陷入“待处理”(导致与以前相同的问题)。