我有简单的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
但是当我尝试从其他吊舱卷曲时,出现连接拒绝错误。 (busybox 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