A ClusterIP is invisible from outside. The first way to open a door is a NodePort.
Every node opens the same port, in the range 30000-32767, and forwards it to the Service. The Pods can run anywhere.
Make one
learner@shallows:~$ kubectl expose deployment market-web --port=80 --type=NodePort
service/market-web exposed
learner@shallows:~$ kubectl get svc market-web
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
market-web NodePort 10.96.149.168 <none> 80:31860/TCP 1sPORT(S) now has two numbers: the Service port inside the cluster, and the node port outside. Read the node port on its own:
learner@shallows:~$ kubectl get svc market-web -o jsonpath='{.spec.ports[0].nodePort}'
31860Or set it in a manifest, with type: NodePort next to the selector. An existing Service can be changed in place by applying the manifest with the new type.
Reach it
The node's address is in kubectl get nodes -o wide. In this course it is 10.0.0.10, and your terminal sits outside the cluster, so:
learner@shallows:~$ curl -s http://10.0.0.10:31860
<!doctype html>
<html>
<head><title>Monster Market</title></head>When to use it
NodePort is simple and it works everywhere, which is why it is the second rung of the ladder. The port number is awkward and every node must be reachable. The next lesson adds the rung above it.