0

I have used kind kubernetes to create cluster. I have created 3 services for 3 Pods ( EmberJS, Flask, Postgres ). Pods are created using Deployment.

I have exposed my front-end service to port 84 ( NodePort Service ). My app is now accessible on localhost:84 on my machine's browser.

But the app is not able to connect to the flask API which is exposed as flask-dataapp-service:6003 .

net:: ERR_NAME_NOT_RESOLVED

My flask service is available as flask-dataapp-service:6003. When I do a

curl flask-dataapp-service:6003

inside the bash of the ember pod container. It is being resolved without any issues.

But from the browser the flask-dataapp-service is not being resolved.

Find the config files below.


kind-custom.yaml

> kind: Cluster 
> apiVersion: kind.x-k8s.io/v1alpha4  nodes:
> - role: control-plane   
> extraPortMappings:
>   - containerPort: 30000
>     hostPort: 84
>     listenAddress: "0.0.0.0" # Optional, defaults to "0.0.0.0"
>     protocol: tcp

Emberapp.yaml

apiVersion: v1
kind: Service
metadata:
  name: ember-dataapp-service
spec:
  selector:
    app: ember-dataapp
  ports:
  - protocol: "TCP"
    port: 4200
    nodePort: 30000
  type: NodePort

---

apiVersion: apps/v1
kind: Deployment
metadata:
  name: ember-dataapp
spec:
  selector:
    matchLabels:
      app: ember-dataapp
  replicas: 1
  template:
    metadata:
      labels:
        app: ember-dataapp
    spec:
      containers:
      - name: emberdataapp
        image: emberdataapp
        imagePullPolicy: IfNotPresent
        ports:
        - containerPort: 4200

flaskapp.yaml

apiVersion: v1
kind: Service
metadata:
  name: flask-dataapp-service
spec:
  selector:
    app: flask-dataapp
  ports:
  - protocol: "TCP"
    port: 6003
    targetPort: 1234
  type: ClusterIP

---

apiVersion: apps/v1
kind: Deployment
metadata:
  name: flask-dataapp
spec:
  selector:
    matchLabels:
      app: flask-dataapp
  replicas: 1
  template:
    metadata:
      labels:
        app: flask-dataapp
    spec:
      containers:
      - name: dataapp
        image: dataapp
        imagePullPolicy: IfNotPresent
        ports:
        - containerPort: 1234

1 Answers1

0

my flask service is available as flask-dataapp-service:6003. When I do a

curl flask-dataapp-service:6003

inside the bash of the ember pod container. It is being resolved without any issues.

Kubernetes has an in-cluster DNS which allows names such as this to be resolved directly within the cluster (i.e. DNS requests do not leave the cluster). This is also why this name does not resolve outside the cluster (hence why you cannot see it in your browser)

(Unrelated side note: this is actually a gotcha in the Kubernetes CKA certification)

Since you have used a NodePort service, you should in theory be able to use the NodePort you described (6003) and access the app using "http://localhost:6003"

Alternatively, you can port-forward:

kubectl port-forward svc/flask-dataapp-service 6003:6003

then use the same link

The port-forward option is not really of much use when running a local kubernetes cluster (in fact, the kubectl might fail with "port in use"), it's a good idea to get used to that method since it's the easiest way you can access a service in a remote kubernetes cluster that is using ClusterIP or NodePort without having to have direct access to the nodes.

Blender Fox
  • 4,442
  • 2
  • 17
  • 30