Monday 27 May 2019

02 Kubernetes Service Definition

Kubernetes service is an abstraction above the pods, the pods cannot be accessed/exposed outside the cluster. Inorder to expose the pods outside the cluster, we need to define service.


Service Definition yaml


https://raw.githubusercontent.com/venkatesh-mohanram/microservices/master/01-microservices-starter-kit/add-service/k8s-service.yaml

The selector tells which deployment needs to be abstracted. The port specifies the service port and the targetPort specify the port in which the deployment is exposed. 

Use the below command to execute the service definition


$kubectl apply -f k8s-service.yaml


We can use the below command to see the clusterIP in which the service is made available. The default IP is clusterIP, this IP will be accessible within the cluster.


$kubectl get service





In order to test the service, we can run the CURL command with the service IP


$curl http://10.107.33.6/addservice/application.wadl




We can do a roling update of containers inside the pod, any rolling update on the pod will not affect the service IP and we can still use the same IP.

No comments:

Post a Comment