Services

Last updated 5 months ago

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.

Nginx Example

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 nginx chart.

Here is the Deployment and Service definition:

nginx-deployment.yaml
nginx-svc.yaml
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

Now go to the Services section. You'll see the nginx Service with the 3 nginx instances linked to it.

Pod Management > Nginx Service with 3 Ready Pods

‚Äč