Skip to content

Latest commit

 

History

History
109 lines (78 loc) · 3.48 KB

File metadata and controls

109 lines (78 loc) · 3.48 KB

Kubernetes Services

In this section we will take a look at services in kuberentes

Services

  • 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 backend and frontend pods and it helps to establish connecivity to an external datasource
  • Thus, services enables loose coupling between microservices in our application. srv1

Let's look at some other aspects of networking

External Communication

  • So, we deployed our POD having a web application on it. How do we as an external user access the web page?

    • From the node (Able to reach the application as expected)

      srv2

    • From outside world (This should be our expectation, without something in the middle it will not reach the application)

      srv3

    • 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 service comes into play.

      srv4

    • This type of service is know as a Node Port service, because the service listens to a pod on the node and forward requests to the POD.

Service Types

There are 3 types of service types in kubernetes

srv-types

  1. 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
      

    srvnp

    To connect the service to the pod

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

    srvnp1

    To create the service

    $ kubectl create -f service-defination.yaml
    

    To list the services

    $ kubectl get services
    

    To access the application from CLI instead of web browser

    $ curl http://192.168.1.2:30008
    

    srvnp2

    A service with multiple pods

    srvnp3

    When Pods are distributed across multiple nodes

    srvnp4

  2. ClusterIP

    • In this case the service creates a Virtual IP inside the cluster to enable communication between different services such as a set of frontend servers to a set of backend servers.
  3. LoadBalancer

    • Where provisions a loadbalancer for our application in supported cloud providers.

K8s Reference Docs: