CODE/2022-09-20

Kubernetes Service Ports: port, targetPort, and nodePort

A Kubernetes Service can expose a set of Pods through a stable endpoint. Its port, targetPort, and nodePort describe different points along the request path.

The three ports

  • port is the Service port, reachable through the Service's ClusterIP from within the cluster.
  • targetPort is the port on the selected backend Pod. It can be a number or a named container port.
  • nodePort is a port exposed on cluster nodes for a Service of type NodePort (or typically as part of a LoadBalancer Service). External reachability depends on network and firewall configuration.

Example

yaml_snippet
YAML · 12 lines|
apiVersion: v1
kind: Service
metadata:
name: web
spec:
type: NodePort
selector:
app: web
ports:
- port: 8080
targetPort: 80
nodePort: 30080
A client inside the cluster can connect to web:8080. A client with network access to a node can connect to <node-ip>:30080; the Service forwards traffic to port 80 on an eligible backend Pod. The Pod application must actually listen on that port. Dockerfile EXPOSE does not itself open a port or configure a Kubernetes Service.
The allowed NodePort range is cluster-configurable; the usual default is 30000–32767. Service traffic may be implemented by kube-proxy or another compatible data plane.
COMPANION ESSAYS / 思想脉络与互照篇目
同卷深读2026-05-22 ·

Installing Python 3 Alongside System Python on CentOS 7

同属「系统工程卷」脉络衍生思考与工程推演推演阅读 →
跨界互照2026-08-22 ·

我的书架:03|金融经管:经济运行、金融体系与企业治理

我的书架:03|金融经管:经济运行、金融体系与企业治理

跨领域对照思辨 · 从「思想随笔」视界互为印证推演阅读 →
RELATED INDEX / 相关阅读索引
柯航hang.ke·© 2014—2026
CC BY-NC 4.0·