Services & Networking Flashcards
What is the purpose of a service?
An abstract way to expose an application running on a set of Pods as a network service. Allows other applications or users to connect to an application running on Kubernetes.
What are the types of service?
- NodePort
- ClusterIP
- LoadBalancer
- ExternalName
What is a NodePort service type?
Exposes the Service on each Node’s IP at a static port (the NodePort). A ClusterIP Service, to which the NodePort Service routes, is automatically created.
How is a NodePort service accessed?
nodeIP:nodePort
What is a ClusterIP service type?
Exposes the Service on a cluster-internal IP. Choosing this value makes the Service only reachable from within the cluster. This is the default ServiceType.
What is a LoadBalancer service type?
Exposes the Service externally using a cloud provider’s load balancer. NodePort and ClusterIP Services, to which the external load balancer routes, are automatically created.
What is the default node port range?
30000 to 32767
What is the Service definition spec for a NodePort. e.g. node port 30000, exposing a Pod labelled foo=bar on port 80
spec:
type: NodePort
ports:
- targetPort: 80
port: 80
nodePort: 30000
selector: foo:bar
For a NodePort, how does the port field differ from targetPort field?
targetPort is the port on the Pod which is being exposed. port is the corresponding port in the service which connects to the exposed targetPort. port is the only mandatory field.
What happens in a NodePort spec if the targetPort is not explicitly specified?
targetPort defaults to the value of port
What happens in a NodePort spec if the nodePort is not explicitly specified?
A free port number in the valid range (30000 to 32767) is automatically allocated.
What is the imperative command for listing all Services in the default namespace?
kubectl get svc
How does a NodePort deal with multiple pods in a Node which match the selector?
The Service selects all the matching pods. The Service then balances load across the matching pods, using a random balancing algorithm.
How does a NodePort behave when there are multiple nodes in the cluster?
The port is exposed on all of the nodes, and the service can be accessed via the IP for any of the nodes. The service selects matching pods across the entire cluster, and automatically load balances between them.
What is the Service definition spec for ClusterIP? (e.g. for a Service reachable on port 8080 which exposes port 80 on Pods with label foo=bar)
spec: ports: - targetPort: 80 port: 8080 selector: foo: bar