$30 off During Our Annual Pro Sale. View Details »

Kubernetes: A very brief explanation of ports

Kubernetes: A very brief explanation of ports

A quick look at the various uses of "ports" in Kubernetes

Tim Hockin

April 06, 2017
Tweet

More Decks by Tim Hockin

Other Decks in Technology

Transcript

  1. Google Cloud Platform
    Kubernetes: A very brief
    explanation of ports
    Tim Hockin
    Senior Staff Software Engineer
    @thockin

    View Slide

  2. Google Cloud Platform
    cluster
    pod.spec.ports[*].containerPort
    ● declares the existence of a port on a pod
    ● can be assigned a name or hostPort
    ● informational, not required
    node node node
    pod
    3306
    pod
    8080
    pod
    8080
    pod
    80

    View Slide

  3. Google Cloud Platform
    cluster
    pod.spec.ports[*].hostPort
    ● maps a specific port on a single node’s IP to a containerPort
    ● only one per-port per-node
    ● should be your LAST RESORT - if the pod moves, the ip:port changes
    node node node
    pod
    3306
    pod
    8080
    pod
    8080
    pod
    80
    80 80 80

    View Slide

  4. Google Cloud Platform
    cluster
    service.spec.ports[*].port
    ● the virtual port on the service VIP
    ● service clients use this
    ● stable ip:port - does not change when pods move
    node node node
    pod
    3306
    pod
    8080
    pod
    80
    pod
    8080
    pod
    8080
    service
    8080

    View Slide

  5. Google Cloud Platform
    cluster
    service.spec.ports[*].targetPort
    ● maps a service port to backend containerPorts
    node node node
    pod
    3306
    pod
    8080
    pod
    80
    pod
    8080
    pod
    8080
    service
    80

    View Slide

  6. Google Cloud Platform
    cluster
    service.spec.ports[*].targetPort
    ● maps a service port to backend containerPorts
    ● can target a containerPort by number or name
    node node node
    pod
    mysql
    pod
    http
    pod
    http
    pod
    http
    pod
    http
    service
    80

    View Slide

  7. Google Cloud Platform
    service.spec.ports[*].nodePort
    ● maps a port on every node to a service port
    ● ports are allocated, random
    ● useful to interface with load-balancers that only understand nodes
    cluster
    node node node
    pod pod pod
    31234 31234
    3306 8080 8080
    31234
    pod
    3306
    pod
    8080

    View Slide

  8. Google Cloud Platform
    service.spec.ports[*].nodePort (OnlyLocal)
    ● annotation:
    service.beta.kubernetes.io/external-traffic=OnlyLocal
    ● changes how backends are chosen
    cluster
    node node node
    pod pod pod
    31234 31234
    3306 8080 8080
    31234
    pod
    3306
    pod
    8080

    View Slide