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
What is ingress?
An API object that manages external access to the services in a cluster, typically HTTP. Ingress may provide load balancing, SSL termination and name-based virtual hosting.
What Service Types allow Ingress to be exposed outside the cluster?
- NodePort
- LoadBalancer
What products are available for providing Ingress resources?
An Ingress Controller produces Ingress Resources. Kubernetes does not have an Ingress Controller by default. Third party tools such as GCE (google’s load balancer), nginx, haproxy, istio, and traefik are available.
What is the apiVersion of an Ingress controller?
apps/v1 (it is deployed as a Deployment)
What is the image used for an nginx Ingress controller?
quay.io/kubernetes-ingress-controller/nginx-ingress-controller
In the Ingress Controller definition, what are the args required to start an nginx ingress controller?
spec: template: spec: containers: - args: - /nginx-ingress-controller - --configmap=$(POD_NAMESPACE)/nginx-configuration
In the Ingress Controller definition, what are the environment variables required to be defined?
POD_NAME and POD_NAMESPACEspec: template: spec: containers: - env: - name: POD_NAME valueFrom: fieldRef: fieldPath: metadata.name - name: POD_NAMESPACE valueFrom: fieldRef: fieldPath: metadata.namespace
What other resources are required for the Ingress controller?
- Service
- ConfigMap
- ServiceAccount
- Roles
- ClusterRoles
- RoleBindings
What is the apiVersion of an Ingress resource?
networking.k8s.io/v1beta1
In an Ingress resource definition, how are backend services connected? e.g. a path / on a host foo.org, to a service named svc1, and port 80
spec: rules: - host: foo.org http: paths: - path: / backend: serviceName: svc1 servicePort: 80
By default what restrictions are there on network traffic between Pods/Services in a cluster?
By default Kubernetes is “All Allow”, and all pods and services within a cluster and namespace can reach each other by their IP or Pod/Service FQDN.
What is the purpose of NetworkPolicy resource?
NetworkPolicies allow you to specify how a pod is allowed to communicate with various network entities over the network. It allows you to control traffic flow at the IP address or port level (OSI layer 3 or 4).
What is the apiVersion of NetworkPolicy?
networking.k8s.io/v1
In the NetworkPolicy definition, how is an ingress rule applied? (e.g. TCP traffic on port 3000, from a Pod labelled foo:bar to a Pod labelled role:target
spec: podSelector: matchLabels: role: target policyTypes: - Ingress ingress: - from: - podSelector: matchLabels: foo: bar