Services

It's common to have many replica services serving applications in production in order to offer a good user experience. However, no matter how many hosts or images are involved in this process, we need to offer a unique entry point for all this functionality: this is what Kubernetes services are intended for.

A Kubernetes service acts as both an endpoint and load balancer for a specific application. Since a service is located in front of a group of replicated pods, it will distribute the traffic across all the available instances.

Remember, pods and Docker containers are ephemeral, and we can't rely on their IP addresses. This is why Kubernetes services are important for continuously providing a service.

Let's look at an example of a configuration file for a Kubernetes service:

apiVersion: v1
kind: Service
metadata:
name: application-xyz-service
spec:
ports:
port:80
targetPort: 80
protocol: TCP
selector:
tier:front-end

The kind configuration entry in line 2 has a new value—in this case, the value is Service. The selector indicates the replica container associated with this service, and the rest of the configuration parameters are self-explanatory. Using this file, you can use the kubectl create command as follows:

kubectl create -f application-xyz-service.yaml

Furthermore, if you don't want to create a file for a service, you can directly expose an existing replica controller using the following command:

kubectl expose rc application-xyz-rc
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.22.216.254