How to response to request application by using "curl" command in kubernetes cluster nodes?

9/4/2020

I built a k8s cluster(master 1, worker node 5) on ubuntu 18.04. I confirmed join master and worker nodes. I used kubeadm, and network add-on flannel. And I have deploy nginx server.

when I command the curl http://[cluserIP] on the cluster nodes,but there was no response.

Is the k8s network configuration wrong?

-- gyuhyeon lee
curl
kubernetes
networking

1 Answer

9/4/2020

A pod exposed by clusterIP type service is only reachable within the cluster. If you do curl from another pod within the cluster it should work. clusterIP is not reachable from outside the cluster including even from the nodes itself. If you want to access a pod from nodes via curl expose it via a NodePort service.

apiVersion: v1
kind: Service
metadata:
  name: my-service
spec:
  type: NodePort
  selector:
    app: MyApp
  ports:
      # By default and for convenience, the `targetPort` is set to the same value as the `port` field.
    - port: 80
      targetPort: 80
      # Optional field
      # By default and for convenience, the Kubernetes control plane will allocate a port from a range (default: 30000-32767)
      nodePort: 30007 

With above example curl http://NODEIP:30007 should work.

-- Arghya Sadhu
Source: StackOverflow