7. Services & Networking Flashcards

1
Q

What is a service in Kubernetes ?

A

Enables communication between different components

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

ServiceTypes

A
  • NodePort
  • ClusterIP
  • LoadBalancer
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Define a service definition

service-definition.yaml

A
apiVersion: v1
kind: Service
metadata:
  name: myapp-service
spec:
  type: NodePort
  ports:
    - targetPort: 80
      port: 80
      nodePort: 30008
  selector:
    app: myapp
    type: front-end		

pod-definition.yaml

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

Use one service in a Pod

pod-definition.yaml

A
apiVersion: v1
kind: Pod
metadata:
  name: myapp-pod
  labels: 
    app: myapp
    type: front-end
spec:
  containers:
  - name: nginx-container
    image: nginx
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is a ClusterIP

A
  • The ClusterIP provides a load-balanced IP address.
  • One or more pods that match a label selector can forward traffic to the IP address.
  • The ClusterIP service must define one or more ports to listen on with target ports to forward TCP/UDP traffic to containers.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What are the steps to define a service with ClusterIP

A
  1. In the service definition should copy the tags from the pod-definion
    ~~~
    labels:
    app: myapp
    type: back-end
    ~~~
  2. To service definition
  selector: 
    app: myapp
    type: back-end
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Define a service with ClusterIP

A
apiVersion: v1
kind: Service
metadata:
  name: back-end
spec:
  type: ClusterIP      < - Add the type
  ports:
    - targetPort: 80     < - Add the port
      port: 80
  selector: 
    app: myapp
    type: back-end

service-definition.yaml

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

Diference between port and targetPort in a service

A
  • In Kubernetes, when creating a service, you have to set the “port” and “targetPort” properties.
  • A “port” refers to the container port exposed by a pod or deployment, while a “targetPort” refers to the port on the host machine that traffic is directed to.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Implement a Pod with a service

A
apiVersion: v1 
kind: Pod
metadata:
  name: myapp-pod
  labels:
    app: myapp
    type: back-end
spec:
  containers:
  - name: nginx-container
    image: nginx

pod-definition.yaml

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

What is Kubernetes Ingress

A
  • Kubernetes Ingress is an API object that provides routing rules to manage external users’ access to the services in a Kubernetes cluster, typically via HTTPS/HTTP.
  • With Ingress, you can easily set up rules for routing traffic without creating a bunch of Load Balancers or exposing each service on the node

Level 7 loadbalancer

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