apiVersion: v1
kind: Service
metadata:
name: my-service
spec:
type: NodePort
selector:
app: myapp
ports:
- port: 80 # service's port
targetPort: 80 # the pod's port, by default and for convenience, it is set to the same value as the port field
nodePort: 30080 # optional field - by default and for convenience, the Kubernetes control plane will allocate a free port from a range (default: 30000-32767)