As we mentioned before Pods are ephemeral and they can be born and die during the day. In order to be able to group together a set of Pods and make them discoverable without having to keep in mind that they may die and be regenerated (e.g. because a node was faulty) we need something more abstract. This is where Services come in.
A Service is basically a group of Pods that consistitute a Service (e.g. a group of Nginx instances). When someone want to access this group of Pods it does it through the service, which will redirect the request to one of those Pods.
For more information about Services checkout the Kubernetes User Guide.
In this Tutorial you'll learn how to run a Set of Nginx instances and expose them under a Service.
In this section we'll deploy an Nginx Chart that will provide 3 nginx instances and one service that connects them.
The Nginx instances are generated by a Deployment and the Service connects those instances. This is the most common way to deploy an stateless application.
Go to the tutorial chart repo and run the
Here is the Deployment and Service definition:
apiVersion: extensions/v1beta1kind: Deploymentmetadata:name: nginxspec:replicas: 3selector:matchLabels:app: nginxtemplate:metadata:labels:app: nginxspec:containers:- name: nginximage: nginx:1.10-alpineports:- containerPort: 80resources:requests:cpu: 100mmemory: 100Mi
Now go to the Services section. You'll see the
nginx Service with the 3 nginx instances linked to it.