Flask Kubernetes NGINX can';找不到uWSGI应用程序服务器,但正在使用docker compose

Flask Kubernetes NGINX can';找不到uWSGI应用程序服务器,但正在使用docker compose,flask,kubernetes,docker-compose,uwsgi,Flask,Kubernetes,Docker Compose,Uwsgi,我有一个带有两个映像的应用程序,一个运行NGINX,另一个运行Flask/uWSGI。它使用docker compose按预期工作。现在我尝试在Kubernetes集群上部署我的应用程序,但我无法在NGINX和我的uWSGI应用服务器之间建立连接 日志是我的nginx部署,比如: 2019/09/13 11:29:53[错误]6#6:*21连接到上游时上游超时(110:连接超时),客户端:10.244.0.1,服务器:,请求:“GET/HTTP/1.1”,上游:uwsgi://10.0.232.

我有一个带有两个映像的应用程序,一个运行NGINX,另一个运行Flask/uWSGI。它使用docker compose按预期工作。现在我尝试在Kubernetes集群上部署我的应用程序,但我无法在NGINX和我的uWSGI应用服务器之间建立连接

日志是我的nginx部署,比如:

2019/09/13 11:29:53[错误]6#6:*21连接到上游时上游超时(110:连接超时),客户端:10.244.0.1,服务器:,请求:“GET/HTTP/1.1”,上游:uwsgi://10.0.232.218:8080,主机:“52.166.xxxxxx”

但是,我的flask服务似乎运行正常

NAMESPACE              NAME                        TYPE           CLUSTER-IP     EXTERNAL-IP     PORT(S)          AGE
default                flask                       NodePort       10.0.232.218   <none>          8080:32043/TCP   23m   
default                kubernetes                  ClusterIP      10.0.0.1       <none>          443/TCP          19h
default                nginx                       LoadBalancer   10.0.162.165   52.166.xxxxx   80:31669/TCP     23m  
烧瓶的Dockerfile

# Dockerfile to build glpk container images
# Based on Ubuntu

# Set the base image to Ubuntu
FROM ubuntu:latest

# Switch to root for install
USER root

# Install wget
RUN apt-get update -y && apt-get install -y \
wget \
build-essential \
python3 \
python3-pip \
python3.6-dev \
--no-install-recommends \
&& rm -rf /var/lib/apt/lists/*

RUN pip3 install setuptools Cython numpy wheel 
RUN pip3 install uwsgi


# Create a user
ENV HOME /home/user
RUN useradd --create-home --home-dir $HOME user \
&& chmod -R u+rwx $HOME \
&& chown -R user:user $HOME


# switch back to user
WORKDIR $HOME
USER user

COPY . /usr/src/app
WORKDIR /usr/src/app
RUN pip3 install -r requirements.txt
RUN pip3 install .

RUN export LC_ALL=C.UTF-8
RUN export LANG=C.UTF-8
RUN export FLASK_APP=server
CMD ["uwsgi", "uwsgi.ini"]
我的nginx Dockerfile

# Use the Nginx image
FROM nginx

# Remove the default nginx.conf
RUN rm /etc/nginx/conf.d/default.conf

# Replace with our own nginx.conf
COPY nginx.conf /etc/nginx/conf.d/
现在,我的Kubernetes配置文件:

flask-deployment.yaml

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  annotations:
    kompose.cmd: kompose convert
    kompose.version: 1.17.0 (a74acad)
  creationTimestamp: null
  labels:
    io.kompose.service: flask
  name: flask
spec:
  replicas: 1
  strategy: {}
  template:
    metadata:
      creationTimestamp: null
      labels:
        io.kompose.service: flask
    spec:
      containers:
      - env:
        - name: APP_NAME
          value: fundamentalmodel
        image: registry.azurecr.io/fundamentalmodel_flask
        name: flask
        resources: {}
        ports:
          - containerPort: 8080
      restartPolicy: Always
status: {}
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  annotations:
    kompose.cmd: kompose.exe convert
    kompose.version: 1.17.0 (a74acad)
  creationTimestamp: null
  labels:
    io.kompose.service: nginx
  name: nginx
spec:
  replicas: 1
  strategy: {}
  template:
    metadata:
      creationTimestamp: null
      labels:
        io.kompose.service: nginx
    spec:
      containers:
      - image: registry.azurecr.io/fundamentalmodel_nginx
        name: nginx
        ports:
        - containerPort: 80
        resources: {}
      restartPolicy: Always
status: {}
flask-service.yaml

apiVersion: v1
kind: Service
metadata:
  labels:
    name: flask
  name: flask
spec:
type: NodePort
  selector:
    app: flask
  ports:
  - name: http
    port: 8080
    targetPort: 8080
apiVersion: v1
kind: Service
metadata:
  annotations:
    kompose.cmd: kompose.exe convert
    kompose.version: 1.17.0 (a74acad)
  creationTimestamp: null
  labels:
    io.kompose.service: nginx
  name: nginx
spec:
  type: LoadBalancer
  ports:
  - name: "80"
    port: 80
    targetPort: 80
  selector:
    io.kompose.service: nginx
status:
  loadBalancer: {}
nginx-deployment.yaml

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  annotations:
    kompose.cmd: kompose convert
    kompose.version: 1.17.0 (a74acad)
  creationTimestamp: null
  labels:
    io.kompose.service: flask
  name: flask
spec:
  replicas: 1
  strategy: {}
  template:
    metadata:
      creationTimestamp: null
      labels:
        io.kompose.service: flask
    spec:
      containers:
      - env:
        - name: APP_NAME
          value: fundamentalmodel
        image: registry.azurecr.io/fundamentalmodel_flask
        name: flask
        resources: {}
        ports:
          - containerPort: 8080
      restartPolicy: Always
status: {}
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  annotations:
    kompose.cmd: kompose.exe convert
    kompose.version: 1.17.0 (a74acad)
  creationTimestamp: null
  labels:
    io.kompose.service: nginx
  name: nginx
spec:
  replicas: 1
  strategy: {}
  template:
    metadata:
      creationTimestamp: null
      labels:
        io.kompose.service: nginx
    spec:
      containers:
      - image: registry.azurecr.io/fundamentalmodel_nginx
        name: nginx
        ports:
        - containerPort: 80
        resources: {}
      restartPolicy: Always
status: {}
nginx-service.yaml

apiVersion: v1
kind: Service
metadata:
  labels:
    name: flask
  name: flask
spec:
type: NodePort
  selector:
    app: flask
  ports:
  - name: http
    port: 8080
    targetPort: 8080
apiVersion: v1
kind: Service
metadata:
  annotations:
    kompose.cmd: kompose.exe convert
    kompose.version: 1.17.0 (a74acad)
  creationTimestamp: null
  labels:
    io.kompose.service: nginx
  name: nginx
spec:
  type: LoadBalancer
  ports:
  - name: "80"
    port: 80
    targetPort: 80
  selector:
    io.kompose.service: nginx
status:
  loadBalancer: {}
nginx.conf

server {

    listen 80;

    location / {
        include uwsgi_params;
        uwsgi_pass flask:8080;
    }

}
uswgi.ini

[uwsgi]
wsgi-file = run.py
callable = app
socket = :8080
processes = 4
threads = 2
master = true
chmod-socket = 660
vacuum = true
die-on-term = true

我认为这里的解决方案是更改两个设置,即您的服务应该使用ClusterIP,因为NodePort服务于不同的用途(请阅读此处的更多内容):

您的UWSGI配置也应该指定0.0.0.0:8080

[uwsgi]
wsgi-file = run.py
callable = app
socket = 0.0.0.0:8080
processes = 4
threads = 2
master = true
chmod-socket = 660
vacuum = true
die-on-term = true

问题可能出在您的
nginx.conf
中。你能分享一下吗(关于flask应用程序的部分)?哦,是的,当然,我忘记发布了。我试图在nginx.conf中更改配置,但错误消息将更改为:[emerg]1#1:host not found in up“NEWVALUE”,位于/etc/nginx/conf.d/nginx.conf:7中。因此,nginx.conf似乎没有问题。只是一个问题,为什么要将服务类型设置为NodePort?