我想在k8s中部署一个服务和一个postgres数据库。部署在一台计算机上运行正常,但在另一台计算机上失败。pod数据库日志没问题。这是我在尝试连接到数据库的服务中得到的消息:
...
raise exception
File "/usr/local/lib/python3.8/site-packages/sqlalchemy/pool/base.py", line 656, in __connect
connection = pool._invoke_creator(self)
File "/usr/local/lib/python3.8/site-packages/sqlalchemy/engine/strategies.py", line 114, in connect
return dialect.connect(*cargs, **cparams)
File "/usr/local/lib/python3.8/site-packages/sqlalchemy/engine/default.py", line 490, in connect
return self.dbapi.connect(*cargs, **cparams)
File "/usr/local/lib/python3.8/site-packages/psycopg2/__init__.py", line 122, in connect
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
sqlalchemy.exc.OperationalError: (psycopg2.OperationalError) could not translate host name "sbdb-0.sbdb" to address: Temporary failure in name resolution
字符串
检查pod显示以下内容:
lev@gpusrv01:~$ sudo kubectl describe pod sb-6d5677f566-4qmmf
Name: sb-6d5677f566-4qmmf
Namespace: default
Priority: 0
Node: gpusrv01/10.200.3.64
Start Time: Sat, 04 Mar 2023 10:58:33 +0100
Labels: app=servicebroker-app
db=sbdb
name=sb-pod
pod-template-hash=6d5677f566
Annotations: sidecar.istio.io/rewriteAppHTTPProbers: true
Status: Running
IP: 10.42.0.193
IPs:
IP: 10.42.0.193
Controlled By: ReplicaSet/sb-6d5677f566
Containers:
sb:
Container ID: containerd://d713eb355a0dafd9dcf9b7da6bdd5b6b1cca55147846af9f68a94e595614df4b
Image: sb
Image ID: sha256:3dc49d5c108e81948af187d2ad00f85d6b1831b8061ca79f1f3ca44a29955054
Ports: 5000/TCP, 5000/TCP
Host Ports: 0/TCP, 0/TCP
Command:
flask
run
--host=0.0.0.0
--port=5000
State: Running
Started: Sat, 04 Mar 2023 10:58:33 +0100
Ready: False
Restart Count: 0
Readiness: http-get http://:5000/heliports delay=0s timeout=1s period=10s #success=1 #failure=3
Environment Variables from:
sb-env-list ConfigMap Optional: false
Environment:
FLASK_APP: app.py
DB_USER: <set to the key 'DB_USER' in secret 'servicebroker-secrets'> Optional: false
DB_PASSWORD: <set to the key 'DB_PASSWORD' in secret 'servicebroker-secrets'> Optional: false
Mounts: <none>
Conditions:
Type Status
Initialized True
Ready False
ContainersReady False
PodScheduled True
Volumes: <none>
QoS Class: BestEffort
Node-Selectors: <none>
Tolerations: node.kubernetes.io/not-ready:NoExecute op=Exists for 300s
node.kubernetes.io/unreachable:NoExecute op=Exists for 300s
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Warning Unhealthy 3m19s (x18830 over 46h) kubelet Readiness probe failed: Get "http://10.42.0.193:5000/heliports": context deadline exceeded (Client.Timeout exceeded while awaiting headers)
型
检查服务sb显示以下内容:
lev@gpusrv01:~$ sudo kubectl describe svc sb
Name: sb
Namespace: default
Labels: app=servicebroker-app
name=sb
Annotations: <none>
Selector: app=servicebroker-app,db=sbdb,name=sb-pod
Type: NodePort
IP Family Policy: SingleStack
IP Families: IPv4
IP: 10.43.176.221
IPs: 10.43.176.221
Port: http 5000/TCP
TargetPort: 5000/TCP
NodePort: http 30050/TCP
Endpoints:
Session Affinity: None
External Traffic Policy: Cluster
Events: <none>
型
我使用以下配置连接到数据库:
apiVersion: v1
kind: ConfigMap
metadata:
name: sb-env-list
data:
DEMO_MODE: 'False'
DB_HOST: sbdb-0.sbdb
DB_NAME: servicebroker
DB_PORT: "5432"
LOG_LEVEL: "info"
KAFKA_ADDRESS: kk-cluster-kafka-bootstrap.kk.svc.cluster.local:9092
MRM_ADDRESS: "http://mrm:5001"
型
DNS配置是否已损坏?
1条答案
按热度按时间jvlzgdj91#
它看起来像你的
DB_HOST: sbdb-0.sbdb
是错误的,因为你的svc的name: sb
,所以它应该是DB_HOST: sb
,如果在相同的命名空间和DB_HOST: sb.default.svc.cluster.local