k8s.github.io

Kubernetes Services

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

Services

Let’s look at some other aspects of networking

External Communication

## Service Types

#### There are 3 types of service types in kubernetes

srv-types

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

      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-end
      

    srvnp1

    #### To create the service

      $ kubectl create -f service-definition.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 the service provisions a loadbalancer for our application in supported cloud providers.

K8s Reference Docs: