Kubernetes Services
- Take me to Video Tutorial
In this section we will take a look at services in kubernetes
Services
-
Kubernetes Services enables communication between various components within and outside of the application.
Let’s look at some other aspects of networking
External Communication
-
How do we as an
external useraccess theweb page?-
From the node (Able to reach the application as expected)
-
From outside world (This should be our expectation, without something in the middle it will not reach the application)
-
Service Types
There are 3 types of service types in kubernetes
-
NodePort
- Where the service makes an internal port accessible on a port on the NODE.
apiVersion: v1 kind: Service metadata: name: myapp-service spec: types: NodePort ports: - targetPort: 80 port: 80 nodePort: 30008
To connect the service to the pod
apiVersion: v1 kind: Service metadata: name: myapp-service spec: type: NodePort ports: - targetPort: 80 port: 80 nodePort: 30008 selector: app: myapp type: front-endTo create the service
$ kubectl create -f service-definition.yamlTo list the services
$ kubectl get servicesTo access the application from CLI instead of web browser
$ curl http://192.168.1.2:30008A service with multiple pods
When Pods are distributed across multiple nodes
- Where the service makes an internal port accessible on a port on the NODE.
-
ClusterIP
- In this case the service creates a
Virtual IPinside the cluster to enable communication between different services such as a set of frontend servers to a set of backend servers.
- In this case the service creates a
-
LoadBalancer
- Where the service provisions a
loadbalancerfor our application in supported cloud providers.
- Where the service provisions a
K8s Reference Docs: