Kubernetes networking and services are a complex topic. You need to understand the needs of your application in order to successfully deploy it on Kubernetes. This means understanding the type of service you want to provide, the size and location of your cluster, and what kind of traffic you expect your application to receive.
There are four types of services that Kubernetes supports: ClusterIP, NodePort, LoadBalancer, and Ingress. Each has their own set of requirements to enable them for your application, so you must understand which one you need before deploying.
For example, NodePort allows pods within the same node to communicate with each other without having an IP address assigned. Your Kubernetes cluster must have at least two nodes for this type of network communication to work correctly. Also, NodePort only works when accessed from inside the cluster, as opposed to LoadBalancers or Ingress, which allow external access. Let’s go through each to understand how they work.