0

I'm using docker desktop on windows. I have a docker image with a python web app. I can run a container and access it on my host as http://localhost:9090

Now I'm trying to run it on a Kubernetes cluster with the deployment yaml below.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: flask
  namespace: dev
  labels:
    app: flask
spec:
  replicas: 3
  selector:
    matchLabels:
      app: flask
  template:
    metadata:
      labels:
        app: flask
    spec:
      containers:
      - name: flask
        image: myubuntu
        imagePullPolicy: Never
        resources:
          requests:
            cpu: "500m"
            memory: "500Mi"
        ports:
        - containerPort: 9090
---
apiVersion: v1
kind: Service
metadata:
  name: flask
  namespace: dev
spec:
  type: NodePort
  selector:
    app: flask
  ports:
    - protocol: TCP
      port: 9090
      targetPort: 9090

then I ran:

kubectl apply -f deployment.yaml
kubectl get service

which gave me:

NAME    TYPE       CLUSTER-IP      EXTERNAL-IP   PORT(S)          AGE
flask   NodePort   10.110.188.94   <none>        9090:30007/TCP   10m

but I cannot access it from host via

curl http://localhost:9090
curl http://localhost:30007
curl http://10.110.188.94:9090
curl http://10.110.188.94:30007

Does anyone know how I can access the web app from the host?

1 Answer 1

1

I figured out. I got rid of NodePort service and instead made a LoadBalancer

kubectl expose deployment flask --type="LoadBalancer" -n dev

now I'm getting access to my app on localhost:9090

1
  • how exactly it works? I tried the same but no success. Commented Oct 3, 2023 at 15:45

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .