CKAD — Named Ports & Multi-Port Services

less than 1 minute read

Named Ports

You can use named ports for clarity:

# In the Pod/Deployment
containers:
- name: app
  ports:
  - name: http
    containerPort: 8080
  - name: metrics
    containerPort: 9090

# In the Service
spec:
  ports:
  - name: http
    port: 80
    targetPort: http     # References the named port
  - name: metrics
    port: 9090
    targetPort: metrics

Named ports make it easier to change port numbers without updating the Service — just update the container port and the name stays the same.

Multi-Port Services

apiVersion: v1
kind: Service
metadata:
  name: app-svc
spec:
  selector:
    app: myapp
  ports:
  - name: http
    port: 80
    targetPort: 8080
  - name: https
    port: 443
    targetPort: 8443

When a Service has multiple ports, each port must have a name.


Next: Kubernetes DNS →

Updated: