Learning Library

← Back to Library

Kubernetes Service Types Explained Quickly

Key Points

  • A Kubernetes Service groups pods (e.g., three replicas) and provides load‑balancing among them, with its definition specified in a `service.yaml`.
  • The default `ClusterIP` type assigns an internal IP that is reachable only within the cluster network, not from the external internet.
  • `NodePort` exposes the same port (e.g., 31000) on every node’s external IP, allowing outside traffic to reach the service, but each service can use only one port and IP changes when nodes are added or removed, making it unreliable for public exposure.
  • The `LoadBalancer` type lets the cloud provider provision a Network Load Balancer (NLB) that receives a stable external IP and forwards traffic directly to the service, offering a more robust public entry point than NodePort.

Full Transcript

# Kubernetes Service Types Explained Quickly **Source:** [https://www.youtube.com/watch?v=NPFbYpb0I7w](https://www.youtube.com/watch?v=NPFbYpb0I7w) **Duration:** 00:05:37 ## Summary - A Kubernetes Service groups pods (e.g., three replicas) and provides load‑balancing among them, with its definition specified in a `service.yaml`. - The default `ClusterIP` type assigns an internal IP that is reachable only within the cluster network, not from the external internet. - `NodePort` exposes the same port (e.g., 31000) on every node’s external IP, allowing outside traffic to reach the service, but each service can use only one port and IP changes when nodes are added or removed, making it unreliable for public exposure. - The `LoadBalancer` type lets the cloud provider provision a Network Load Balancer (NLB) that receives a stable external IP and forwards traffic directly to the service, offering a more robust public entry point than NodePort. ## Sections - [00:00:00](https://www.youtube.com/watch?v=NPFbYpb0I7w&t=0s) **Kubernetes Ingress Overview in 5 Minutes** - The speaker briefly explains scaling pods, creating a Service with label selectors, and the differences between ClusterIP and NodePort service types as a foundation for understanding Kubernetes Ingress. - [00:03:08](https://www.youtube.com/watch?v=NPFbYpb0I7w&t=188s) **Ingress Resource for Multi‑Service Routing** - The speaker critiques one‑load‑balancer‑per‑service as inefficient at scale and introduces Kubernetes Ingress—a declarative ingress.yaml that creates a single external load balancer and uses host/path rules, like an Nginx reverse proxy, to route traffic to multiple services. ## Full Transcript
0:00Hi, everyone. 0:01My name is Sai Vennam, 0:02and today we're going to be talking about Kubernetes Ingress in 5 minutes. 0:05Now, I'm going to assume you already have the fundamental understandings of Kubernetes, 0:08but if you don't, be sure to check out my video, "Kubernetes Explained". 0:12Let's go ahead and get started. 0:15Let's assume that we've got a pod 0:17scaled out three times within my Kubernetes cluster, 0:20and I've got three nodes in my Kubernetes cluster, 0:23and this pod is scaled up to three. 0:26Now, these pods together - 0:28let's say I've created a grouping with the label selector 0:31to create what's called a "service". 0:35Now, a service 0:37basically enables me to load balance requests to one of these pods, 0:41and that's going to be our first start here. 0:44Let's say we've got a "service.yaml" that defines that service. 0:47One of the core things you can define in that is going to be a type, 0:51and we're going to start with the basic one, "Cluster IP". 0:56Now, basically every service that gets created in Kubernetes has a cluster IP. 1:01It enables access to that service from within the Kubernetes network, 1:05not the external network. 1:07So, let's assume our service has a Cluster IP and move forward 1:10to the next, more interesting, option here. 1:13I could also specify that type as a Node port. 1:19Now, a Node port is actually a lot like the name kind of makes it sound. 1:24Now, we've got three nodes in our cluster, 1:26and each one of those nodes has a publicly accessible IP. 1:30Now, let's say that that publicly accessible IP looks something like 169.0.0.1, 1:37169.0.0.2, and so on for the third one. 1:44Now, this is a publicly accessible IP address, 1:48but what a Note Port will do is assign the same Node port, 1:52so the same port, let's say it's 31,000, to all three of those nodes. 1:58So, for external access from outside, 2:02from the Internet that's coming in, 2:05and that hits that port on any one of these IP addresses that's externally accessible. 2:11It's going to route directly to service that's defined in that service.yaml. 2:17So, that's an interesting approach and there's a couple of limitations. 2:21So, basically any service can only have one port. 2:25But more importantly, 2:26if a node were to go down, say you're working with a cloud service provider 2:30and you scale your nodes up and down a lot, 2:32well, you're going to have to maintain that updated IP address that's going to change 2:36when a new node comes up. 2:38So, although it works, it's not the best approach 2:42to exposing your applications on the public Internet. 2:45Let's talk about a third type here. 2:47It's going to be type "load balancer". 2:50Now a load balancer, when you define it, 2:53so, it's really dependent on how a cloud provider is providing their Kubernetes service. 2:57But essentially the way it works, 3:00the cloud provider is going to spin up something called an NLB, 3:03or a "Network Load Balancer", 3:06for every service that you expose this way. 3:08And so, for users that are coming in and accessing that NLB, 3:12that IP address, it's going to route directly to that service. 3:17But although this is good, again, it's only one kind of service, 3:22one load balancer IP address per service. 3:25And, in addition, load balancers are a commodity at the end of the day. 3:31If you need to expose a lot of services, that's a lot of load balancers 3:34which can be inefficient when going to scale. 3:38Now, the last one I want to talk about here is actually not even a service type; 3:42it's a new thing called an "Ingress Resource" 3:45which maybe we can define with an ingress.yaml file, 3:48and this is going to be, you know, you're going to define a "kind: ingress". 3:55Now an ingress is a little different. 3:57The way ingress is going to work, when you create this, 4:00it's going to create basically a set of rules within your cluster, 4:04an ingress resource that can route based on a set of rules. 4:08These rules are going to be really reminiscent 4:10of something like an engine X reverse proxy. 4:13So, the first thing that ingress will do is create 4:16an external load balancer 4:19that's able to handle requests coming in 4:22and let's say that request comes in for app.com 4:26which maps to an IP address that the ingress supports 4:29and now here's where the interesting part comes in. 4:32It can actually route based on a set of rules. 4:35So, let's say we have a second set of pods in the cluster 4:38and these set of pods route to a Service B. 4:47Now, this rule - maybe we introduce a rule that says if the rule comes in, 4:53or the route comes in with, let's say, serviceb.app.com, 5:01then route to this set of services, 5:03otherwise route all other traffic to Service A. 5:07We'll just say "other". 5:09So, an ingress is powerful because you can route multiple backend services 5:13with a single IP address 5:15and then do path-based routing. 5:17So, as other advantages you can do something like TLS termination, 5:21do virtual hosts 5:23and a number of other kind of capabilities that become available. 5:26So, this was Kubernetes ingress in five minutes. 5:29If you enjoyed this video, or have any questions, 5:31be sure to drop a like or a comment below. 5:33Stay tuned and follow us for more videos like this in the future. 5:36Thank you.