[英]access postgres in kubernetes from an application outside the cluster
Am trying to access postgres db deployed in kube.netes(kubeadm) on centos vms from another application running on another centos vm.我正在尝试从另一个 centos 虚拟机上运行的另一个应用程序访问部署在 centos 虚拟机上的 kube.netes(kubeadm) 中的 postgres 数据库。 I have deployed postgres service as 'NodePort' type.
我已将 postgres 服务部署为“NodePort”类型。 My understanding is we can deploy it as LoadBalancer type only on cloud providers like AWS/Azure and not on baremetal vm.
我的理解是,我们只能将其作为 LoadBalancer 类型部署在 AWS/Azure 等云提供商上,而不能部署在裸机虚拟机上。 So now am trying to configure 'ingress' with NodePort type service.
所以现在我正在尝试使用 NodePort 类型服务配置“入口”。 But am still unable to access my db other than using kubectl exec $Pod-Name on kube.netes master.
但是除了在 kube.netes master 上使用 kubectl exec $Pod-Name 之外,我仍然无法访问我的数据库。
My ingress.yaml is我的 ingress.yaml 是
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: postgres-ingress
spec:
backend:
serviceName: postgres
servicePort: 5432
which does not show up any address as below没有显示任何地址如下
NAME HOSTS ADDRESS PORTS AGE
postgres-ingress * 80 4m19s
am not even able to access it from pgadmin on my local mac.我什至无法从本地 Mac 上的 pgadmin 访问它。 Am I missing something?
我错过了什么吗?
Any help is highly appreciated.非常感谢任何帮助。
Ingress won't work, it's only designed for HTTP traffic, and the Postgres protocol is not HTTP. You want solutions that deal with just raw TCP traffic: Ingress 不会工作,它只为 HTTP 流量设计,而 Postgres 协议不是 HTTP。你想要的解决方案只处理原始 TCP 流量:
kubectl describe
on the service, and then connect your Postgres client to the IP of the node VM (not the pod or service) on that port.kubectl describe
找出端口,然后将您的 Postgres 客户端连接到该端口上的节点 VM(不是 pod 或服务)的 IP。kubectl port-forward pod/your-postgres-pod 5432:5432
, and then connect your Postgres client to localhost:5432
.kubectl port-forward pod/your-postgres-pod 5432:5432
,然后将您的 Postgres 客户端连接到localhost:5432
。 This is my preferred way for accessing the database from your local machine (it's very handy and secure) but I wouldn't use it for production workloads (kubectl must be always running so it's somewhat fragile and you don't get the best performance).
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.