首页 > 解决方案 > 从另一个 pod 连接到 svc 时连接被拒绝

问题描述

我有简单的 python 应用程序

RUN pip install -r requirements.txt
EXPOSE 8000
CMD ["gunicorn", "main:api", "-c", "/app/gunicorn_conf.py" ,"--reload"]

我的gunicorn conf文件在哪里:

import multiprocessing
bind = '0.0.0.0:8000'
workers = multiprocessing.cpu_count() * 2 + 1
timeout = 30
worker_connections = 1000

和我的部署 YAML 文件:

apiVersion: apps/v1 # for versions before 1.9.0 use apps/v1beta2
kind: Deployment
metadata:
  name: test-deployment
spec:
  selector:
    matchLabels:
      app: test-pod
  replicas: 1 
  template:
    metadata:
      labels:
        app: test-pod
    spec:
      containers:
      - name: test-container
        image: localhost:5000/test123:v4
        ports:
        - name: http
          containerPort: 8000


---
apiVersion: v1
kind: Service
metadata:
  name: test-svc
spec:
  ports:
  - protocol: TCP
    port: 5000
    targetPort: http
  selector:
    app: test-pod

当我从 test-pod 尝试 curl 命令时,它的工作文件

curl -X POST localhost:8000/test

但是当我尝试从其他 pod 卷曲时,我收到连接被拒绝错误。(忙箱吊舱)

curl -X POST test-svc:5000/test

我的 kubectl 描述 svc test-svc

Name:              test-svc
Namespace:         default
Labels:            <none>
Annotations:       Selector:  app=test-pod
Type:              ClusterIP
IP:                10.99.11.154
Port:              <unset>  5000/TCP
TargetPort:        http/TCP
Endpoints:         10.1.0.11:8000
Session Affinity:  None
Events:            <none>

nslookup 工作正常

Name:   test-svc.default.svc.cluster.local
Address: 10.99.11.154

标签: kuberneteskubernetes-ingresskubernetes-pod

解决方案


推荐阅读