origin: using targetPort with a name in service definition doesn't seem to work via route

Using targetPort in the service definition to map to a named port in a pod definition doesn’t seem to work. Everything looks like it works and the web interface even has 80/TCP → apacheport in the display, but I can never establish a connection. If I instead use targetPort : 8080 in openshift it works. Mapping to a name works in kubernetes-1.1.0-0.17.git388061f.fc23.x86_64 so I think I’m not doing something wrong, but I can’t be sure. My target ose environment is 3.1.

Example Pod

{
    "apiVersion": "v1",
    "kind": "Pod",
    "metadata": {
        "labels": {
            "app": "helloapache"
        },
        "name": "helloapache"
    },
    "spec": {
        "containers": [
            {
                "image": "dustymabe/httpd:latest",
                "name": "helloapache",
                "ports": [
                    {
                        "name": "apacheport",
                        "containerPort": 8080,
                        "protocol": "TCP"
                    }
                ]
            }
        ]
    }
}

Example service

{
    "apiVersion": "v1",
    "kind": "Service",
    "metadata": {
        "labels": {
            "name": "apacheservice"
        },
        "name": "apacheservice"
    },
    "spec": {
        "ports": [
            {
                "port": 80,
                "targetPort": "apacheport"
            }
        ],
        "selector": {
            "app": "helloapache"
        },
        "type": "LoadBalancer"
    }
}

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Comments: 30 (24 by maintainers)

Commits related to this issue

Most upvoted comments

Summary:

  • if a route has a numeric targetPort, that matches the containerport number.
  • if a route has a named targetPort, that matches the serviceport name (NOT the containerport name)

My preference would be to switch routes to use the serviceport names, so that changes to the service port mapping get picked up by the route automatically.

@kargakis @spadgett I think we should change oc expose and the UI route creation to set a route’s targetPort to the name of the service port by default.

We could also look into requesting that the service port number be added to the endpoint info, which would give us a chance of letting a routeport numeric targetPort map to a service port number without needing to watch services as well