Services Flashcards
What do Kubernetes Sevices do?
- 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
What is the Kubernetes Service?
- an object, just like pods, replicaSet or deployments
What is a Usecase of a Kubernetes Service?
- 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
What kind of Service Types exist?
- 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 many and which ports are involved in the NodePort service?
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 do we create a Service?
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
What happens, if for a NodePort service, no nodePort is provided in the yaml?
Free port in the valid range is provided
In a NodePort, what port is mandatory?
Only ‘port’, of the service
In a NodePort, what happens if we don’t provide a target port?
Assumed to be the same as the port of service
How many port mappings can be part of a NodePort?
- one to multiple mappings can be provided
How do we specify, to which pod a NodePort service should connect to?
- using labels and selectors
- label of the pod must be used in selector in NodePort
How do we create a service?
‘kubectl creat -f service-definition.yaml’
Once we set up a NodePort, how can we connect to it?
‘curl http://< ip of the node>:< node-port>
What kind of algorithm uses the nodePort service and for what?
- 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
What happends when the pods, connected via one service are spread on multiple nodes?
- 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