Kubernetes YAML Cheat Sheet/Expose named container ports

Name ports for Service targeting and probes.

Section: Pods and Containers

Expose named container ports

yaml
yaml
ports:
  - name: http
    containerPort: 8080
  - name: metrics
    containerPort: 9090

Learn the surrounding workflow

Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.

Related commands

Same sheet · prioritizing Pods and Containers
Override container command and args
Set entrypoint-style command in YAML.
OpenIn sheetyamlsame section
Set explicit environment variables
Define environment variables with `env`.
OpenIn sheetyamlsame section
Load env from ConfigMap and Secret
Import environment values into a container.
OpenIn sheetyamlsame section
Use imagePullSecrets
Authenticate to a private registry.
OpenIn sheetyamlsame section
Minimal Pod manifest
Smallest practical Pod YAML shape.
Labels and annotations example
Common metadata block for selectors and tooling.