I've deployed few apps on Google Kubernetes Engine and exposed two controllers based on Flask Python, with Service which contains type: LoadBalancer
.
apiVersion: v1
kind: Service
metadata:
labels:
app: my-app
name: controller
namespace: ns-app
spec:
type: LoadBalancer
ports:
- name: "5001"
port: 5001
targetPort: 5001
selector:
app: my-app
When I send Http Request via Python/Postman/Curl sometimes the Controller response with 200 ok
, But most of the time the request is being rejected immediately, without timeout or anything.
I had few speculation and thought that the load balancer reject the requests. Then I tried to use Ingress for expose the controller... using this tutorial
The example in the tutorial works like charm, but forcing it on my app is not working. I'd change the service type to NodePort
ingress.yaml:
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: controller-ingress
namespace: ns-app
spec:
backend:
serviceName: controller
servicePort: 5001
service.yaml
apiVersion: v1
kind: Service
metadata:
labels:
app: my-app
name: controller
namespace: ns-app
spec:
type: NodePort
ports:
- name: "5001"
port: 5001
targetPort: 5001
selector:
app: my-app
after waiting for ~15 minutes I entered to the Ingress external IP and I get default backend - 404
.
Questions: 1. How can I solve it? 2. There is difference between LoadBalancer
and NodePort+Ingress
?
I need to expose my Flask Controller to have external IP in order to receive Http Requests.
Thank you
By adding a rules
to the spec
, i could overcome this issue.
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: controller-ingress
namespace: ns-app
spec:
backend:
serviceName: controller
servicePort: 5001
rules:
- host: foo.bar.com
http:
paths:
- path: /*
backend:
serviceName: controller
servicePort: 5001