user3629892
user3629892

Reputation: 3046

Simple kubernetes deployment on minikube with helm 3 not working (cant reach app)

I am trying to deploy a simple FLASK app (python web framework) on a Kubernetes cluster. I am using minikube.

Here's my Helm 3 stuff:

Deployment:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: flask-app-deployment
  labels:
    app: flask-app
    some: label
spec:
  replicas: 1
  selector:
    matchLabels:
      app: flask-app-pod
  template:
    metadata:
      labels:
        app: flask-app-pod
    spec:
      containers:
        - name: flask-app-container
          image: flask_app:0.0.1
          imagePullPolicy: Never
          ports:
            - name: app
              containerPort: 5000
              protocol: TCP
          securityContext: # root access for debugging
            allowPrivilegeEscalation: false
            runAsUser: 0

Service:

apiVersion: v1
kind: Service
metadata:
  name: flak-app-service
  labels:
    service: flask-app-services
spec:
  type: NodePort
  ports:
    - port: 5000
      targetPort: 5000
      protocol: TCP
      name: https
  selector:
    app: flask-app-pod

Chart:

apiVersion: v2
name: flask-app
type: application
version: 0.0.1
appVersion: 0.0.1

I deploy this by doing helm install test-chart/ --generate-name.

Sample output of kubectl get all:

NAME                                       READY   STATUS    RESTARTS   AGE
pod/flask-app-deployment-d94b86cc9-jcmxg   1/1     Running   0          8m19s

NAME                       TYPE        CLUSTER-IP     EXTERNAL-IP   PORT(S)          AGE
service/flak-app-service   NodePort    10.98.48.114   <none>        5000:30317/TCP   8m19s
service/kubernetes         ClusterIP   10.96.0.1      <none>        443/TCP          7d2h

NAME                                   READY   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/flask-app-deployment   1/1     1            1           8m19s

NAME                                             DESIRED   CURRENT   READY   AGE
replicaset.apps/flask-app-deployment-d94b86cc9   1         1         1       8m19s

I exec'd into the pod to check if it's listening on the correct port, looks fine (netstat output):

Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 0.0.0.0:5000            0.0.0.0:*               LISTEN      1/python3

My Dockerfile should be fine. I can create a container and call the app then running a "normal" dcker container.

Must be something stupid. What am I not seeing here?

I would expect to be able to go https://localhost:30317 which gets forwarded to the service listening on port 5000 internally, which forwards it into the pod that also listens on port 5000.

Upvotes: 0

Views: 788

Answers (1)

Hiteshwar Sharma
Hiteshwar Sharma

Reputation: 191

To validate traffic you can use following as where it is breaking:

kubectl port-forward pods/flask-app-deployment-d94b86cc9-jcmxg 5000:12345

or

kubectl port-forward deployment/flask-app-deployment 5000:12345

or

kubectl port-forward service/flak-app-service 5000:12345

depending upon where you want to debug.

Also please validate by running netstat -tunlp whether your host is listening on the allotted port or not.

Hope this solves your error, or let me know if it does not.

Upvotes: 1

Related Questions