Kubernetes: Services

Services are used to access a Pod inside and outside a cluster.

Service has a static IP, DNS, Port and load balances requests to the Pods.

Service uses Label selector to choose Pods.

Service Discovery

Options:

  • DNS based
  • Environment variables

Using the ReplicationController we built here: kubectl: create pod

we’ll make an app visible to the outside world.

Checking it’s not visible currently:

  • kubectl describe rc
  • kubectl describe pod/hello-rc-tp5vf

shows:

and

Expose port with:

then

kubectl describe svc hello-svc

to show the service.

To delete pods, replicationcontroller or service use:

kubectl delete -f pod.yml

kubectl delete -f rc.yml

kubectl delete svc hello-svc

 

Service Types

ClusterIP: Stable internal cluster IP

NodePort: exposes the app outside of the cluster by adding a cluster-wide port on top of ClusterIP

LoadBalancer: integrates NodePort with cloud-based load balancers

Creating the Service above with a yml file looks like:

Note: port is what the app is using inside the container. This then gets mapped to NodePort.

 

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *