What's the difference between service type: NodePort & LoadBalancer

3/3/2016
apiVersion: v1
kind: Service
metadata:
  name: nginx 
  labels:
    name: nginx
spec:
  ports:
    # the port that this service should serve on
  - port: 80 
    targetPort: 80
    nodePort: 30000 
  selector:
    name: nginx
  type: NodePort

apiVersion: v1
kind: Service
metadata:
  name: nginx 
  labels:
    name: nginx
spec:
  ports:
    # the port that this service should serve on
  - port: 80 
    targetPort: 80
    nodePort: 30000 
  selector:
    name: nginx
  type: LoadBalancer 

Two methods all support loadbalancer. And the port range is between 30000-32000, why? If I want to use port 3000, what should I do?

-- huhuhu
kubernetes

1 Answer

3/3/2016

http://kubernetes.io/v1.0/docs/user-guide/services.html#type-nodeport:

If you set the type field to "NodePort", the Kubernetes master will allocate a port from a flag-configured range (default: 30000-32767).

There is a risk of low ports conflict with real things running on host. That's the reason, why ports are limited. You are still able to configure kube-apiserver - flag --service-node-port-range=

http://kubernetes.io/v1.0/docs/admin/kube-apiserver.html

-- Jan Garaj
Source: StackOverflow