我有nginx pod和其他pod包含gunicorn pod API,我试图通过nginx pod连接。
当我在nginx pod中使用gunicorn pod的POD IP时,我可以连接nginx pod。输出:
root@nginx:/etc/nginx# curl -v http://10.244.1.155:20000/_ems/plant
* Trying 10.244.1.155:20000...
* Connected to 10.244.1.155 (10.244.1.155) port 20000 (#0)
字符串
当我使用服务,而不是POD IP,其失败.错误:
root@nginx:/etc/nginx# curl -v http://ems-service.default.svc.cluster.local:20000/_ems/plant;
* Trying 10.106.43.2:20000...
* connect to 10.106.43.2 port 20000 failed: Connection refused
* Failed to connect to ems-service.default.svc.cluster.local port 20000: Connection refused
* Closing connection 0
curl: (7) Failed to connect to ems-service.default.svc.cluster.local port 20000: Connection refused
型
:
NAME READY STATUS RESTARTS AGE
pod/ems 1/1 Running 0 5m56s
pod/nginx 1/1 Running 0 4h46m
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/ems-service ClusterIP 10.106.43.2 <none> 20000/TCP 103m
[eds@rnd-4 pod-4px]$ kubectl describe service -n default ems-service
Name: ems-service
Namespace: default
Labels: <none>
Annotations: <none>
Selector: name=ems
Type: ClusterIP
IP Family Policy: SingleStack
IP Families: IPv4
IP: 10.106.43.2
IPs: 10.106.43.2
Port: <unset> 20000/TCP
TargetPort: 80/TCP
Endpoints: <none>
Session Affinity: None
Events: <none>
型
Yaml文件:
apiVersion: v1
kind: Pod
metadata:
name: ems
labels:
app: ems
spec:
containers:
- name: ems
image:
command: ["/bin/sh"]
args: ["-c", "chmod +x /root/code/run.sh && /root/code/run.sh"]
env:
- name: LOGS_DIR
value: /root/code/logs
imagePullPolicy: Always
ports:
- containerPort: 20000
----------------------------------
apiVersion: v1
kind: Service
metadata:
name: ems-service
spec:
selector:
name: ems
ports:
- protocol: TCP
port: 20000
targetPort: 80
型
1条答案
按热度按时间ej83mcc01#
如果
kubectl describe service
表示Endpoints: <none>
,这通常是服务的selector:
与Pod的labels:
不匹配的明显迹象。个字符
最有可能的修复方法是在服务中将
name
更改为app
。你通常不应该运行一个裸Pod,因为一些原因超出了这个问题的范围。我建议将Pod更改为Deployment,假设你不需要访问持久存储。在这种情况下,Service需要匹配
spec: { template: { metadata: { labels: } } }
per-Pod标签。