Python Google容器引擎公开服务“无法访问站点”
我正在寻找使用Flask、Docker和Google容器引擎构建一个简单的web应用程序。我已指定以下DockerFile:Python Google容器引擎公开服务“无法访问站点”,python,docker,containers,kubernetes,google-kubernetes-engine,Python,Docker,Containers,Kubernetes,Google Kubernetes Engine,我正在寻找使用Flask、Docker和Google容器引擎构建一个简单的web应用程序。我已指定以下DockerFile: # Use an official Python runtime as a base image FROM python:2.7-slim # Set the working directory to /app WORKDIR /app # Copy the current directory contents into the container at /app A
# Use an official Python runtime as a base image
FROM python:2.7-slim
# Set the working directory to /app
WORKDIR /app
# Copy the current directory contents into the container at /app
ADD . /app
# Install any needed packages specified in requirements.txt
RUN pip install -r requirements.txt
# Make port 80 available to the world outside this container
EXPOSE 8080
# Define environment variable
ENV NAME World
# Run app.py when the container launches
CMD ["python", "app.py"]
注意,我正在暴露端口8080
以下是我的简单烧瓶应用程序:
from flask import Flask, jsonify
from flask import make_response
app = Flask(__name__)
tasks = [
{
'type': 'order',
'contents':[1,2,3,4,5,6,7,8,9,10]
}
]
@app.route('/', methods=['GET'])
def get_tasks():
return jsonify({'tasks': tasks})
@app.errorhandler(404)
def not_found(error):
return make_response(jsonify({'error': 'Not found'}), 404)
if __name__ == '__main__':
app.run(host='0.0.0.0', port=8080)
注意主机=0.0.0.0'和端口=8080
我在本地成功运行docker容器:
docker run --rm -p 8080:8080 gcr.io/${PROJECT_ID}/hello-node:v1
但是,当我使用Google容器引擎部署应用程序时,我无法通过kubectl get服务提供的外部端口访问该应用程序
我运行以下命令来部署Pod:
我运行以下命令来创建从internet访问的服务:
kubectl expose deployment hello-world --type=LoadBalancer --port 8080
为什么我无法访问该服务?似乎我已经在每个步骤1 Flask application 2 Dockerfile 3 Pod Deployment 4服务创建中打开了端口8080。我认为在公开部署时,您也应该指出目标端口,如下所示:
kubectl expose deployment hello-world --type=LoadBalancer --port=8080 --target-port=8080
希望对你有所帮助。谢谢你。我已经运行了下面的命令kubectl expose deployment hello world-type=LoadBalancer-port 8080-target port 8080,但仍然无法连接。我不确定这是否有区别,但您没有将=放在-port和8080之间。您可以尝试使用-port=8080-target port=8080吗?curl-I-v http://$kubectl get svc hello world-o jsonpath='{.status.loadBalancer.ingres[0].ip}':8080的输出是什么?
kubectl expose deployment hello-world --type=LoadBalancer --port=8080 --target-port=8080