Score:0

how to access web app running on Kubernetes from host

tg flag
max

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?

Score:0
tg flag
max

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

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.