Kubernetes Cluster: Exposing Services

While components of your application can communicate with each other by service names using the internal network, external connections require additional configurations.

The most basic way to establish an external connection to a service is to expose it via NodePort directly. As the name implies, this type of service opens a specific port on the nodes, any traffic sent to this port is forwarded to your service. By default, the nodePort for your service is selected randomly from the 30000-32767 range.

Note: This method has several downsides that should be considered when configuring the Kubernetes Cluster (one service per port, restricted range of ports, etc). As a result, the NodePort service type can be used for the demo or other temporary applications. However, the production solutions usually require more permanent external access (e.g. ingresses).

1. Here is an example of the NodePort type service configuration:

kind: Service
apiVersion: v1
metadata:
  name: nginx1
  namespace: test
  labels:
    run: nginx
spec:
  type: NodePort
  selector:
    run: nginx
  ports:
    - port: 80
      targetPort: 80
Note: Be aware, Jelastic PaaS does not support the LocaBalancer service type currently. If applying YAML or Helm charts with such a service object, you need to convert it into NodePort or create ingresses for external access.

2. If needed, a particular nodePort can be selected for your service. For example, the following code can be used to configure a redirect from the 30984 port:

  ports:
    - port: 80
      targetPort: 80
      nodePort: 30984
Note: Manually provided nodePort value should be from the allowed range (30000-32767) and unique (to prevent collision with other services).

3. In case public IP is attached to the Kubernetes worker nodes, no additional actions are required.

Otherwise, the obtained port should be exposed from the Jelastic side. Navigate to the Kubernetes environment Settings > Endpoints and click Add. In the opened frame, provide the following data:
  • Node - choose any worker node from the list
  • Name - set any preferred endpoint name
  • Private Port - provide the nodePort from the previous step
  • Protocol - select the TCP option

endpoint to expose kubernetes service
Click Add to confirm. It may take up to a few minutes for Jelastic to expose a port and redirect requests to the NodePort service.