It can connect fine whenever I try to access it via the worker node's address, but not when I try access via the ingress gateway. I get the following error:
pymongo.errors.ServerSelectionTimeoutError
pymongo.errors.ServerSelectionTimeoutError: mongo:27017: timed out, Timeout: 30s, Topology Description: <TopologyDescription id: 60119598e7c0e0d52f58c52c, topology_type: Single, servers: [<ServerDescription ('mongo', 27017) server_type: Unknown, rtt: None, error=NetworkTimeout('mongo:27017: timed out',)>]>
This is how I connect to MongoDB via python which works fine when not accessing over the ingress url.
mongo = MongoClient("mongodb://mongo:27017/user_data")
This is my ingress.yaml file
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: weasel-ingress
spec:
rules:
- host: {host-address}
http:
paths:
- path: /
pathType: Prefix
backend:
serviceName: weasel
servicePort: 5000
- path: /
pathType: Prefix
backend:
serviceName: mongo
servicePort: 27017
Any idea's on how to get it to connect via ingress? I guess I need to add mongo to the ingress?
Both services are already exposed via external ip's.
kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 172.21.0.1 <none> 443/TCP 19h
mongo LoadBalancer 172.21.218.91 {exposed-ip} 27017:31308/TCP 17h
weasel LoadBalancer 172.21.152.134 {exposed-ip} 5000:32246/TCP 17h
ingress logs:
kubectl describe ingress weasel-ingress
Name: weasel-ingress
Namespace: default
Address:
Default backend: default-http-backend:80 (<error: endpoints "default-http-backend" not found>)
Rules:
Host Path Backends
---- ---- --------
{host-address}
/ weasel:5000 (172.30.27.69:5000)
/ mongo:27017 (<none>)
Annotations: <none>
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal CREATE 27s nginx-ingress-controller Ingress default/weasel-ingress
Normal CREATE 27s nginx-ingress-controller Ingress default/weasel-ingress
Normal CREATE 27s nginx-ingress-controller Ingress default/weasel-ingress
question from:
https://stackoverflow.com/questions/65936076/python-pod-cant-connect-to-mongodb-when-using-ingress 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…