Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kubernetes Ingress Flask Application

I have a simple demo Flask application that is deployed to kubernetes using minikube. I am able to access the app using the Services. But I am not able to connect using ingress.

Services.yaml

apiVersion: v1
kind: Service
metadata:
  name: services-app-service
spec:
  selector:
    app: services-app
  type: ClusterIP             
  ports:
    - protocol: TCP
      port: 5000              # External connection
      targetPort: 5000        # Internal connection

D:Path>kubectl get svc
NAME                   TYPE        CLUSTER-IP    EXTERNAL-IP   PORT(S)    AGE
db                     ClusterIP   None          <none>        3306/TCP   120m
kubernetes             ClusterIP   10.20.30.1    <none>        443/TCP    3h38m
services-app-service   ClusterIP   10.20.30.40   <none>        5000/TCP   18m

I am able to access the app using minikube.

D:Path>minikube service services-app-service --url
* service default/services-app-service has no node port
* Starting tunnel for service services-app-service.
|-----------|----------------------|-------------|------------------------|
| NAMESPACE |         NAME         | TARGET PORT |          URL           |
|-----------|----------------------|-------------|------------------------|
| default   | services-app-service |             | http://127.0.0.1:50759 |
|-----------|----------------------|-------------|------------------------|
http://127.0.0.1:50759
! Because you are using a Docker driver on windows, the terminal needs to be open to run it.

Ingress.yaml

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: services-ingress
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /
spec:
  rules:
    - host: mydemo.info
      http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: services-app-service
                port:
                  number: 5000

D:Path>kubectl get ing
NAME               CLASS    HOSTS         ADDRESS        PORTS   AGE
services-ingress   <none>   mydemo.info   192.168.40.1   80      15m

Are there any additional configuration required to access the app via ingress?

like image 912
Rakesh Avatar asked Sep 20 '25 20:09

Rakesh


1 Answers

The issue is that you need to access it with a Host head of mydemo.info for that Ingress spec to work. You also need to confirm you have an Ingress Controller installed, usually ingress-nginx for new users but there are many options. Then you would look for the Ingress Controllers NodePort or LoadBalancer service and access through that.

like image 103
coderanger Avatar answered Sep 22 '25 22:09

coderanger