{"record":{"id":"2ef1fa8d13bf6b43","repo":"cilium/cilium","slug":"failed-to-find-port-s-in-container-s-in-pod-s","errorCode":null,"errorMessage":"failed to find port %s in container %s in pod %s","messagePattern":"failed to find port (.+?) in container (.+?) in pod (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cilium-cli/sysdump/sysdump.go","lineNumber":3319,"sourceCode":"\t\treturn fmt.Errorf(\"failed to submit %s task: %w\", filename, err)\n\t}\n\n\treturn nil\n}\n\nfunc getPodMetricsPort(pod *corev1.Pod, containerName, portName string) (int32, error) {\n\tfor _, container := range pod.Spec.Containers {\n\t\tif container.Name != containerName {\n\t\t\tcontinue\n\t\t}\n\t\tfor _, port := range container.Ports {\n\t\t\tif port.Name == portName {\n\t\t\t\treturn port.ContainerPort, nil\n\t\t\t}\n\t\t}\n\t}\n\n\treturn 0, fmt.Errorf(\"failed to find port %s in container %s in pod %s\", portName, containerName, pod.Name)\n}\n\n// podIsRunningAndHasContainer returns whether the given pod is running,\n// and includes the specified container.\nfunc podIsRunningAndHasContainer(pod *corev1.Pod, container string) bool {\n\tif pod.Status.Phase == corev1.PodRunning {\n\t\treturn slices.ContainsFunc(pod.Spec.Containers, func(c corev1.Container) bool {\n\t\t\treturn c.Name == container\n\t\t})\n\t}\n\treturn false\n}\n\nfunc buildNodeNameList(nodes *corev1.NodeList, filter string) []string {\n\tw := strings.Split(strings.TrimSpace(filter), \",\")\n\tr := make([]string, 0)\n\tfor _, node := range nodes.Items {\n\t\tif len(w) == 0 || w[0] == \"\" {","sourceCodeStart":3301,"sourceCodeEnd":3337,"githubUrl":"https://github.com/cilium/cilium/blob/ac7b90affa4baf0642e6685319d56907b3a73a6d/cilium-cli/sysdump/sysdump.go#L3301-L3337","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nport, err := getPodMetricsPort(pod, \"cilium-agent\", \"metrics\")\n// after: fall back to the known default port\nport, err := getPodMetricsPort(pod, \"cilium-agent\", \"metrics\")\nif err != nil {\n    port = 9962 // default Cilium metrics port\n    err = nil\n}","handlingStrategy":"fallback","validationCode":"ports, _ := jsonpath.Get(`{.spec.containers[*].ports[*].name}`, pod)\nnamedPorts := strings.Split(ports, \" \")\nif !slices.Contains(namedPorts, \"metrics\") {\n    // named port absent — plan to use the default numeric port instead\n}","typeGuard":"func hasNamedPort(pod *corev1.Pod, container, portName string) bool {\n    for _, c := range pod.Spec.Containers {\n        if c.Name != container { continue }\n        for _, p := range c.Ports {\n            if p.Name == portName { return true }\n        }\n    }\n    return false\n}","tryCatchPattern":"port, err := getPodMetricsPort(pod, container, portName)\nif err != nil {\n    log.Printf(\"named port %s missing, using default: %v\", portName, err)\n    port = defaultMetricsPort // e.g. 9962 for cilium-agent\n}","preventionTips":["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"],"tags":["kubernetes","cilium","metrics","port-lookup"],"backgroundTag":"named-port-not-found","analyzedSha":"ac7b90affa4baf0642e6685319d56907b3a73a6d","analyzedAt":"2026-08-31T18:27:15.868Z","schemaVersion":2},"datasetVersion":"2026-08-31T22:30:34.772Z"}