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/v1beta1 kind: Deployment metadata: name: nginx spec: replicas: 3 selector: matchLabels: app: nginx template: metadata: labels: app: nginx spec: containers: - name: nginx image: nginx:1.10-alpine ports: - containerPort: 80 resources: requests: cpu: 100m memory: 100Mi -- apiVersion: v1 kind: Service metadata: name: nginx labels: app: nginx spec: ports: - name: web port: 80 selector: app: nginx
Now go to the Services section. You'll see the
nginx Service with the 3 nginx instances linked to it.