我试图调试与minikube一起部署的PostgreSQL的连接问题。我尝试postgres-service使用这两种类型创建NodePort,LoadBalancer但我似乎无法从我的localhost连接psql。
我已经复制了所有的配置(道歉),因为我确信在某个地方可能只是一个愚蠢的错误!
apiVersion: v1
kind: Secret
metadata:
name: postgres-credentials
type: Opaque
data:
user: YWRtaW4=
password: YWRtaW4=
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: postgres-pvc
labels:
type: local
spec:
accessModes:
- ReadWriteMany
resources:
requests:
storage: 2Gi
apiVersion: v1
kind: PersistentVolume
metadata:
name: postgres-pv
labels:
type: local
spec:
capacity:
storage: 2Gi
storageClassName: standard
accessModes:
- ReadWriteMany
hostPath:
path: /data/postgres-pv-local
apiVersion: apps/v1
kind: Deployment
metadata:
name: postgres
spec:
replicas: 1
selector:
matchLabels:
name: postgres-container
template:
metadata:
labels:
name: postgres-container
tier: backend
spec:
containers:
- name: postgres-container
image: mdillon/postgis:10
ports:
- containerPort: 5432
env:
- name: POSTGRES_USER
valueFrom:
secretKeyRef:
name: postgres-credentials
key: user
- name: POSTGRES_PASSWORD
valueFrom:
secretKeyRef:
name: postgres-credentials
key: password
- name: POSTGRES_DB
valueFrom:
secretKeyRef:
name: postgres-credentials
key: database
volumeMounts:
- name: postgres-volume-mount
mountPath: /var/lib/postgresql/data
volumes:
- name: postgres-volume-mount
persistentVolumeClaim:
claimName: postgres-pvc
apiVersion: v1
kind: Service
metadata:
name: postgres-service
spec:
type: NodePort
selector:
app: postgres-container
ports:
- protocol: TCP
port: 5432
targetPort: 5432
尝试连接我的localhost:
$ kubectl get services
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 443/TCP 30h
postgres-service NodePort 10.105.42.187 5432:32252/TCP 7m32s
$ export PGPASSWORD=admin
$ psql -h localhost -U admin -p 32252 admin
psql: could not connect to server: Connection refused
我也尝试在集群中创建一个Ubuntu部署,使用kubectl run -i --tty --attach --image=ubuntu -- bash,安装psql并连接5432/32252,localhost / postgres-service等......但这也不起作用。
Minikube在VM中运行。在这里,psql -h localhost -U admin -p 32252 admin您正在尝试连接到公开的postgres localhost。但它没有曝光localhost。由于您定义了NodePort类型服务,因此可以使用Node ip访问它。所以,不要使用localhost,请尝试使用Minikube ip。
$ minikube ip
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。