Kubernetes, expose all ports

Viewed 3216

I’d like to use Kubernetes, as I’m reading everywhere : “Kubernetes is, without a doubt, the leading container orchestrator available today.“

My issue here is with the networking. I need to expose external IP to each of the pods. I need that my pods are seen as if they were traditional VM or HW servers. Meaning that I need all the ports to be exposed.

What I see so far, is I can expose only a limited list of ports.

Am I correct ? Or do I miss something ?

Cheers, Raoul

2 Answers

In Kubernetes, you will need service to communicate with pods. To expose the pods outside the Kubernetes cluster, you can use k8s service of NodePort type.

apiVersion: v1
kind: Service
metadata:
  name: my-service
spec:
  selector:
    app: MyApp
  type: NodePort
  ports:
    - 
      port: 8080
      nodePort: 30000
      name: my-port-8080
    -
      port: 8081
      nodePort: 30001
      name: my-port-8081
    -
      port: 8082
      nodePort: 30002
      name: my-port-8081

Then you will be able to reach your pods at, https://<node-ip>:nodePort. For in-cluster communication, you can use service's dns: <service-name>.<namespace>.svc:PORT

Update:

Take a look at this guide: Using a Service to Expose Your App

You are correct.
Pods are not "real" servers, their are rather application-instances with open ports.

Because of the docker- and kubernetes-network-implementation it's not possible to build what you want.

I don't know your use-case, but maybe you are not looking for kubernetes.

Related