Google Container Engine Expose Service "Site Cannot Be Reached"

5/22/2017

I am looking build a simple web application using Flask, Docker, and Google Container Engine. I have specified the following 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
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"]

Note I am exposing port 8080.

Here is my simple Flask application:

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)

Note host='0.0.0.0' and port=8080.

I run the docker container locally, successfully:

docker run --rm -p 8080:8080 gcr.io/${PROJECT_ID}/hello-node:v1

However, when I deploy the application using the Google Container Engine I am not able to access the application via the external port provided by kubectl get service.

I run the following to deploy a Pod:

kubectl run hello-world --image=gcr.io/${PROJECT_ID}/hello-node:v1 --port 8080

I run the following commands to create a Service to access from the internet:

kubectl expose deployment hello-world --type=LoadBalancer --port 8080

Why am I not able to access the service? It seems I have opened port 8080 within every step 1) Flask application 2) Dockerfile 3) Pod Deployment 4) Service creation.

-- sccrthlt
containers
docker
google-kubernetes-engine
kubernetes
python

1 Answer

5/22/2017

I think you should point out the target port as well when exposing your deployment, like this:

kubectl expose deployment hello-world --type=LoadBalancer --port=8080 --target-port=8080

Hope it helps

-- Jahongir Rahmonov
Source: StackOverflow