Skip to content
Advertisement

URL for IBM Cloud Kubernetes deployment

This is a bit of a beginner’s question. I’m attempting to get a simple Hello World Python flask application deployed in a kubernetes cluster on IBM Cloud. The application (main.py):

import os
from flask import Flask

app = Flask(__name__)

@app.route('/')
def welcomeToMyapp():
    return 'Ciao'

port = os.getenv('PORT', '5000')
if __name__ == "__main__":
    app.run(host='0.0.0.0', port=int(port))

I build my Docker image with docker build --rm -t kube-hw . and Dockerfile:

FROM ubuntu:latest

WORKDIR /app
ADD requirements.txt /app
RUN apt-get -y update
RUN apt-get -y install python3-pip
RUN pip3 install --upgrade pip
RUN pip3 install -r requirements.txt

ADD main.py /app

EXPOSE 80

CMD ["python3", "main.py"]

I run it locally with docker run --rm -p 5000:5000 kube-hw. That works fine. I can browse http://0.0.0.0:5000/.

However, when I run the same image on k8s on IBM Cloud I can’t seem to access the URL endpoint. My deployment steps are (from the article mentioned in the answer below):

docker tag kube-hw registry.ng.bluemix.net/sudoku/kube-hw:latest
docker push registry.ng.bluemix.net/sudoku/kube-hw:latest
kubectl run kube-hw --image=registry.ng.bluemix.net/sudoku/kube-hw:latest --port=80
kubectl expose deployment kube-hw --port=80 --target-port=5000 --type=NodePort

I then use kubectl describe pod kube-hw to get the external IP address 10.77.223.141:

Name:           kube-hw-3409617459-5bczp
Namespace:      default
Node:           10.77.223.141/10.77.223.141
Start Time:     Sat, 23 Dec 2017 14:52:39 -0500

Status:         Running
IP:             172.30.205.113

And kubectl describe service kube-hw to get the port 30930:

Name:                     kube-hw
Namespace:                default
Labels:                   run=kube-hw
Annotations:              <none>
Selector:                 run=kube-hw
Type:                     NodePort
IP:                       172.21.250.32
Port:                     <unset>  80/TCP
TargetPort:               5000/TCP
NodePort:                 <unset>  30930/TCP
Endpoints:                172.30.205.116:5000
Session Affinity:         None
External Traffic Policy:  Cluster
Events:                   <none>

The URL http:\10.77.223.141:30930 doesn’t resolve. I can look at the log and see the app running, but no requests are getting to it. The article uses --target-port=8888. But since I’ve used port 5000 in the container I changed to --target-port=5000. I’m wondering if I have a misalignment of port numbers somewhere.

Advertisement

Answer

The IP address that you need is the external IP address of a worker node in your cluster. The IP address that you have identified is an internal address.

To get an external IP address, run bx cs workers <cluster_name>

Then form the URL as follows: http://<external_node_ip>:<NodePort>

Here’s a doc with more information on using NodePort: https://console.bluemix.net/docs/containers/cs_apps.html#cs_apps_public_nodeport

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement