cilium/cilium · error
failed to find port %s in container %s in pod %s
Error message
failed to find port %s in container %s in pod %s
What it means
getPodMetricsPort looks up a named port in a pod's container spec to scrape metrics; when no containerPort with the requested name exists in the specified container, it returns this error. It means the pod spec does not declare the expected named port (e.g. 'metrics') for that container.
Source
Thrown at cilium-cli/sysdump/sysdump.go:3319
return fmt.Errorf("failed to submit %s task: %w", filename, err)
}
return nil
}
func getPodMetricsPort(pod *corev1.Pod, containerName, portName string) (int32, error) {
for _, container := range pod.Spec.Containers {
if container.Name != containerName {
continue
}
for _, port := range container.Ports {
if port.Name == portName {
return port.ContainerPort, nil
}
}
}
return 0, fmt.Errorf("failed to find port %s in container %s in pod %s", portName, containerName, pod.Name)
}
// podIsRunningAndHasContainer returns whether the given pod is running,
// and includes the specified container.
func podIsRunningAndHasContainer(pod *corev1.Pod, container string) bool {
if pod.Status.Phase == corev1.PodRunning {
return slices.ContainsFunc(pod.Spec.Containers, func(c corev1.Container) bool {
return c.Name == container
})
}
return false
}
func buildNodeNameList(nodes *corev1.NodeList, filter string) []string {
w := strings.Split(strings.TrimSpace(filter), ",")
r := make([]string, 0)
for _, node := range nodes.Items {
if len(w) == 0 || w[0] == "" {View on GitHub (pinned to ac7b90affa)
Solutions
- Inspect the pod spec: kubectl get pod POD -o jsonpath='{.spec.containers[*].ports}' and confirm the port name
- Verify the Cilium version supports the expected named metrics port
- Correct the containerName/portName arguments to match the actual pod spec
- If the port is unnamed, patch the deployment/daemonset to declare the named port
Example fix
// before
port, err := getPodMetricsPort(pod, "cilium-agent", "metrics")
// after: fall back to the known default port
port, err := getPodMetricsPort(pod, "cilium-agent", "metrics")
if err != nil {
port = 9962 // default Cilium metrics port
err = nil
} Defensive patterns
Strategy: fallback
Validate before calling
ports, _ := jsonpath.Get(`{.spec.containers[*].ports[*].name}`, pod)
namedPorts := strings.Split(ports, " ")
if !slices.Contains(namedPorts, "metrics") {
// named port absent — plan to use the default numeric port instead
} Type guard
func hasNamedPort(pod *corev1.Pod, container, portName string) bool {
for _, c := range pod.Spec.Containers {
if c.Name != container { continue }
for _, p := range c.Ports {
if p.Name == portName { return true }
}
}
return false
} Try / catch
port, err := getPodMetricsPort(pod, container, portName)
if err != nil {
log.Printf("named port %s missing, using default: %v", portName, err)
port = defaultMetricsPort // e.g. 9962 for cilium-agent
} Prevention
- Verify container port names in the pod spec before metric scraping
- Track Cilium version changes to container/port naming
- Don't rename or strip container ports in Helm value overrides
- Scrape the default documented metrics port as a fallback
When it happens
Trigger: Calling sysdump metric collection that resolves a port by name via getPodMetricsPort(pod, containerName, portName) where the container's Ports list has no entry whose Name == portName.
Common situations: Older or customized Cilium/Hubble images that do not expose the named metrics port; port renamed between Cilium versions; user-supplied Helm overrides that drop container ports; targeting the wrong container in a multi-container pod.
Related errors
- failed to collect the Cilium clustermesh metrics: %w
- CiliumNetworkPolicy rule cannot have NodeSelector, use Ciliu
- pod store outdated
- unable to update some endpoints with new namespace labels
- no link found inside container
AI-assisted analysis of cilium/cilium@ac7b90affa (2026-08-31).
Data as JSON: /api/errors/2ef1fa8d13bf6b43.
Report an issue: GitHub.