NodePort is the simplest Kubernetes Service type for making a locally deployed microservice reachable from outside the cluster. Without an explicit type, a Service defaults to ClusterIP and remains accessible only inside the cluster. section 6.8.3
Configure and use NodePort by:
- Setting the Service type to NodePort in the deployment configuration. section 6.8.3
- Choosing a port from Kubernetes’ 30000–32767 range, such as 30000, or omitting nodePort to receive an available port. section 6.8.3
- Using kubectl get services to verify the assigned port when access fails. section 6.8.6
Listing 6.1 Deploying our microservice to Kubernetes
apiVersion: apps/v1
kind: Deployment #1
metadata:
name: video-streaming #2
spec:
replicas: 1 #3
selector:
matchLabels:
app: video-streaming #4
template: #5
metadata:
labels:
app: video-streaming #4
spec:
containers:
- name: video-streaming
image: video-streaming:1 #6
imagePullPolicy: Never #7
env: #8
- name: PORT
value: "4000" #9
--- #10
apiVersion: v1
kind: Service #11
metadata:
name: video-streaming #12
spec:
selector:
app: video-streaming #4
type: NodePort #13
ports:
- protocol: TCP
port: 80
targetPort: 4000 #14
nodePort: 30000 #14
The deployment manifest shows a NodePort Service connected to the microservice through matching app labels and selectors. section 6.8.3
Testing a local service
After deploying the video-streaming microservice with nodePort 30000, open http://localhost:30000/video. For a gateway deployment, find the assigned NodePort and open http://localhost:<the-port-number>. section 6.8.6 section 10.8.3
NodePort is convenient for local development, but exposing services on a cloud-hosted cluster requires more care because outside access creates opportunities for attacks and abuse. section 6.8.3





