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

569f10721398d92f5033097ac6d9132c?s=128

Tim Hockin

April 06, 2017
Tweet

Transcript

  1. Google Cloud Platform Kubernetes: A very brief explanation of ports

    Tim Hockin <thockin@google.com> Senior Staff Software Engineer @thockin
  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
  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
  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
  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
  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
  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
  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