Kubernetes replica set make internal endpoints external?

4/23/2018

I'm in the process of converting a docker-compose file to k8s. I used the k8s kompose program to automatically generate the service.

On the original docker setup port 80 and 443 are exposed.

I can see the ports referenced in my k8s object for the service:

"containers": [
  {
    "name": "router",
    "image": "myApp/router:latest",
    "ports": [
      {
        "containerPort": 80,
        "protocol": "TCP"
      },
      {
        "containerPort": 443,
        "protocol": "TCP"
      }
    ],

When I look from the UI I can see that the ports are correct for the pods but the service replica set shows this:

enter image description here

How do I open the ports externally for the replica set?

-- Philip Kirkbride
kubernetes

1 Answer

4/23/2018

In Kubernetes, you have several ways how to expose your service:

  1. Expose ports of the Pod directly.
  2. Use Service with NodePort or LoadBalancer type. That is a recommended way and it works on L4.

    For LoadBalancer, you need an external provider of load balancer itself, so it works only in a cloud and some other environments. If you have an on-premise installation on your own hardware, you should use NodePorttype .

  3. Use Ingress. That is also a recommended way, but it works on L7.

You can use the option you prefer, depending on your application.

Now your app is exposed only inside a cluster, because by default, Pods are available only for other Pods (it is like in docker-compose without Expose option).

Here are articles about how to define a Service, what is Ingress and how to use Service to expose your app.

-- Anton Kostenko
Source: StackOverflow