Showing posts from February, 2020

Difference between port and targetPort in Kubernetes

Overview:In the previous post, we deployed a  simple microservice to Kubernetes. In this post, we would take a look at the various port mappings available for an application in Kubernetes and the differences between them.

Port Mappings:Let us take a look at the service yaml file created in previous post. 

You must be wondering that there are so many port mappings available in the yaml file, and what each of those means.
There are two port mappings available, port and targetPort. There is also a third option., when we use Service type as nodePort, we can also provide a specific nodePort which could be used.
Explanation of Ports:NodePort:
When we use nodePort Service type, Kubernetes assigns a static port through which external clients can access the service. In our example, it is 31869.
Port (8086), is the port through which other services in the same node or other nodes within the cluster can access the service. 
TargetPort: TargetPort (8085), is the port through which the actual Pod is…