Services Flashcards

1
Q

What do Kubernetes Sevices do?

A
  • enable communication between various components within and outside of the application
  • help connect application to other applications or users
  • enable loose coupling between microservices within our application

I.e helps when:
- making frontend available to customers
- connecting backend and frontend
- connecting to external data sources

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the Kubernetes Service?

A
  • an object, just like pods, replicaSet or deployments
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is a Usecase of a Kubernetes Service?

A
  • listen to a port on the node and forward requests on that port to a port on the pod, running the web application
  • known as a Node Port Service
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What kind of Service Types exist?

A
  • NodePort Service: service makes an internal port accessible on a port on the node
  • ClusterIp: service creates a virtual IP inside the cluster to enable communicaiton between different services
  • Load Balancer: provisions a load balancer for our application in supported cloud providers
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How many and which ports are involved in the NodePort service?

A

In total 3:
1. Target port: port on the pod, where service is running: 80
2. Referred to as ‘Port’: Port of the service itself, like a virtual server inside the node, has its own IP address inside the cluster (cluster IP of the service)
3. NodePort: Port on the node itself, which we use to access the web server externally, can only be in a valid range, by default 30000 to 32767

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How do we create a Service?

A

Yaml, same as other objects.

apiVersion: v1
kind: Service
metadata:
  name: myapp-service
	labels:
spec:
  type: NodePort
	ports:
	  - targetPort: 80
	    port: 80
			nodePort: 30008
	selector:
	  app: myapp
		type: frontend
			
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What happens, if for a NodePort service, no nodePort is provided in the yaml?

A

Free port in the valid range is provided

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

In a NodePort, what port is mandatory?

A

Only ‘port’, of the service

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

In a NodePort, what happens if we don’t provide a target port?

A

Assumed to be the same as the port of service

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How many port mappings can be part of a NodePort?

A
  • one to multiple mappings can be provided
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How do we specify, to which pod a NodePort service should connect to?

A
  • using labels and selectors
  • label of the pod must be used in selector in NodePort
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How do we create a service?

A

‘kubectl creat -f service-definition.yaml’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Once we set up a NodePort, how can we connect to it?

A

‘curl http://< ip of the node>:< node-port>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What kind of algorithm uses the nodePort service and for what?

A
  • Random Algorithm
  • to distribute requests to multiple pods, managed by the service
  • acts as a built-in load-balancer to distribute load across different parts
  • has SessionAffinity
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What happends when the pods, connected via one service are spread on multiple nodes?

A
  • when a Service in Kubernetes is created it spans across all the nodes in the cluster and maps the target port to the same NodePort on all nodes in the cluster
  • using any node-ip with the same NodePort for connecting to the pod
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What are shortcuts for the api-resources?

A

pod: pod
replicaset: rs
deployment: deploy
service: svc

17
Q

What can a ClusterIP do?

A
  • provide a single interface for pods to connect to pods in another group
  • groups of pods can be connected so that requests from one group to the other can be forwarded to random instances in the target group
  • each layer can now scale or move as required without impacting communication between various services
  • each services get an IP and a name assigned to it
  • that name should be used by other parts to access the service
18
Q

How is a ClusterIP service created?

A

Yaml as always.

apiVersion: v1
kind: Service
metadata:
  name: backend
spec:
  type: ClusterIP
	ports: 
	  - targetPort: 80
	    port: 80
	selector:
	  app: myapp
		type: backend

ClusterIP is the default Type for service, if not specified explicitly
TargetPort is the port where the backend is exposed.
Port is where the service is exposed

19
Q

Using a NodePort, would the used port still work if used with a node where the exposed pod-application is not running?

A

Yes, by accessing the port, even on a node, where the application is not running, the nodePort service routes the request to a node, where it is running, as it spans all nodes

20
Q

How can we achieve that the end user does not have to use the node-ip with the exposed port ip but a simple name instead?

A

Multiple possibilities. One way:
- cloud providers have native load balancers for their platforms
- Kubernetes has support for integrating with the native load balancers of certain cloud providers

21
Q

How does a load balancer yaml look like?

A
apiVersion: v1
kind: Service
metadata: 
  name: myapp-service
spec: 
  type: LoadBalancer
	ports:
	  - targetPort: 80
	    port: 80
			nodePort: 30008

Only works with supported type platforms: GCP, AWS, Azure
If used elsewhere it work similiar to NodePort, not doing any kind of external load balancing configuration

22
Q

With what command can we create a ClusterIP service for a pod, specifying the port?

A

kubectl expose pod redis –port=6379 –name redis-service –dry-run=client -o yaml

23
Q

When is a Service required?

A
  • only required, when the app/pod has some kind of process/service/database that needs to be exposed
  • i.e. a worker, that only copies values from a in-mem database into a relational database does not need a service
24
Q
A