- Take me to Video Tutorial
In this section we will take a look at services in kuberentes
- Kubernetes Services enables communication between various components within an outside of the application.
- Kubernetes Services helps us connect applications together with other applications or users.
- Services enables frontend applications to be made available to endusers. It helps communications between
backendandfrontendpods and it helps to establish connecivity to anexternal datasource - Thus, services enables loose coupling between microservices in our application.
-
So, we deployed our
PODhaving aweb applicationon it. How do we as anexternal 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)
-
We need something in the middle to help us to map requests to the node (say from our laptop through the node to the pod running the web container). This is where the
kubernetes servicecomes into play. -
This type of service is know as a
Node Portservice, because the service listens to a pod on the node and forward requests to the POD.
-
-
NodePort
- Where the services makes an internal POD accessable on a POD on the NODE.
apiVersion: v1 kind: Service metadata: name: myapp-service spec: types: NodePort ports: - targetPort: 80 port: 80 nodePort: 30008
apiVersion: v1 kind: Service metadata: name: myapp-service spec: types: NodePort ports: - targetPort: 80 port: 80 nodePort: 30008 selector: app: myapp type: front-end$ kubectl create -f service-defination.yaml$ kubectl get services$ curl http://192.168.1.2:30008 - Where the services makes an internal POD accessable on a POD 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 provisions a
loadbalancerfor our application in supported cloud providers.
- Where provisions a
K8s Reference Docs: