Search code examples
dockerkubernetescluster-computingkubernetes-helm

Expose a Kubernetes pod on a bare metal cluster


I'm trying to expose a Kubernetes pod on a single node bare metal cluster without a domain. In my understanding I've the these options:

  1. Expose using NodePort
  2. Expose using an Ingress controller
  3. Expose using ClusterIP and manually set an external IP

As I mentioned already, I only have a single node cluster. This means that the master is master and node at the same time directlly running on a fedora host system.

The simplest solution is to use a NodePort. But the limitation here is (if I'm right), that the service port will be automatically selected from a given port range.

The next better solution is to use an ingress controller. But for this I need a public domain which I haven't. So the ingress controller also doesn't fit to me.

What for other options do I have? I just want to expose my service directly on port 9090.


Solution

  • You can set a custom port range for NodePort by adding this option to your apiserver settings (/etc/kubernetes/manifests/kube-apiserver.yaml):

    --service-node-port-range portRange
    Default: 30000-32767
    A port range to reserve for services with NodePort visibility. Example: '30000-32767'.
    Inclusive at both ends of the range.

    This is the part from Kubernetes documentation related to Services:

    If you want a specific port number, you can specify a value in the nodePort field, and the system will allocate you that port or else the API transaction will fail (i.e. you need to take care about possible port collisions yourself). The value you specify must be in the configured range for node ports.

    Example for this answer was taken from the article Hosting Your Own Kubernetes NodePort Load Balancer:

    apiVersion: v1
    kind: Service
    metadata:
      name: nginx
      labels:
        name: nginx
    spec:
      type: NodePort
      ports:
        - port: 80
          nodePort: 30080
          name: http
        - port: 443
          nodePort: 30443
          name: https
      selector:
        name: nginx