What do Kubernetes Sevices do?
I.e helps when:
- making frontend available to customers
- connecting backend and frontend
- connecting to external data sources
What is the Kubernetes Service?
What is a Usecase of a Kubernetes Service?
What kind of Service Types exist?
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?
How do we specify, to which pod a NodePort service should connect to?
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?
What happends when the pods, connected via one service are spread on multiple nodes?
What are shortcuts for the api-resources?
pod: pod
replicaset: rs
deployment: deploy
service: svc
What can a ClusterIP do?
How is a ClusterIP service created?
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
Using a NodePort, would the used port still work if used with a node where the exposed pod-application is not running?
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
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?
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
How does a load balancer yaml look like?
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
With what command can we create a ClusterIP service for a pod, specifying the port?
kubectl expose pod redis –port=6379 –name redis-service –dry-run=client -o yaml
When is a Service required?