How to do it...

As mentioned in the previous section, the Kubernetes Service exposes Pods by selecting them through corresponding labels. However, there is another configuration we have to take care of: the network port. As the following diagram indicates, the Service and Pod have their own key-value pair labels and ports:

Network port mapping between Service and Pod

Therefore, setting the selector of Service and binding the service exposed port to the container port are required to be carried out while creating Services. If either of them fail to be set properly, clients won't get responses or will get connection-refused errors.

We can define and create a new Kubernetes Service through the CLI or a configuration file. Here, we are going to explain how to deploy the Services by command. The subcommands expose and describe are utilized in the following commands for various scenarios. For file-format creation, it is recommended to read the Working with configuration files recipe in Chapter 3, Playing with Containers, for a detailed discussion.

..................Content has been hidden....................

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