Kubernetes Series 3

TABLE OF CONTENT:

  1. What is Kubernetes service ?
  2. What are the types of Kubernetes services?
  3. How to Create service in Kubernetes ?

What is Kubernetes service ?

What is service ? Its basically a layer which runs over PODS i.e. it logically defines set of POD. It will only assign one IP address.

What are the types of Kubernetes services?

  • ClusterIP. Exposes a service which is only accessible from within the cluster.
  • NodePort. Exposes a service via a static port on each node’s IP.
  • LoadBalancer. Exposes the service via the cloud provider’s load balancer.
  • ExternalName. Maps a service to a predefined externalName field by returning a value for the CNAME record.

How to Create service in Kubernetes ?

kind: Service 
apiVersion: v1 
metadata:
  name: hostname-service 
spec:
  # Expose the service on a static port on each node
  # so that we can access the service from outside the cluster 
  type: NodePort

  # When the node receives a request on the static port (30163)
  # "select pods with the label 'app' set to 'echo-hostname'"
  # and forward the request to one of them
  selector:
    app: echo-hostname 

  ports:
    - nodePort:30163  # Your service will listen on this PORT
    - port:8080       # Inside Cluster this PORT is exposed
    - targetPort:80   # Containers are listening on these PORT