Kubernetes - NodePort Service Last Updated : 04 Jan, 2025 Comments Improve Suggest changes Like Article Like Report NodePort service in Kubernetes is a service that is used to expose the application to the internet from where the end-users can access it. If you create a NodePort Service Kubernetes will assign the port within the range of (30000-32767). The application can be accessed by end-users using the node's IP address.Kubernetes ServiceKubernetes service will help you to expose the pods that are running in the cluster to the outside world and also they will make it available for the pods to each other that are running in the Kubernetes cluster. Types Of Kubernetes ServicesIn Kubernetes, there are 3 types of services to provide discovery and routing between pods.1. ClusterIP: It is the default service and its visibility is cluster internal which means it's not possible to use clusterIP service to reach a micro-service from the internet from outside the cluster.2. NodePort: NodePort extends the ClusterIP service and its visibility is internal and external to the cluster. You can set a NodePort using the NodePort property, this is the port that the service will listen on from outside the cluster. There is one requirement of using NodePort which is nodes must have public IP addresses. The port must be in the range between 30000 and 32767 and if you don't specify the NodePort value Kubernetes will assign it randomly.3. LoadBalancer: It operates at the transport level (TCP) that is at level 4. It means that is unable to make decisions based on content and it uses a simple algorithm such as a round-robin across the selected paths. Whereas Ingress operates at the application level which is at level 7. It is able to make decisions based on the actual content of each message. More intelligent load-balancing decisions and content optimizations. In other words, Ingress is like a LoadBalancer but more intelligent.For our article, we'll use NodePort service for service discovery.Kubernetes NodePort ServiceKubernetes NodePort Service is an service which is used for to expose the nodes which are available in the cluster to the outside of the cluster. It will also expose the applications which are running in the node it also allows the traffic from the outside to reach the application with the help of NodePort.Example Of NodePort ServiceFollowing is the sample YAML file for the kubernetes NodePort Service. apiVersion: v1kind: Servicemetadata: name: <Name Of the Service> spec: type: NodePort ports: - port: 80 # Port exposed within the cluster targetPort: 8080 # Port on the pods nodePort: 30000 # Port accessible externally on each node selector: app: example-app # Select pods with this labelHow NodePort Service Work? NodePort service will exposes the pods of node to the another and also it will expose the pods to the outside of the cluster from where the users can aceses from the internet by using the IP address of node and port. Following is the sample YAML file for NodePort Service. apiVersion: v1kind: Servicemetadata: name: my-servicespec: selector: app: my-app type: NodePort ports: - protocol: TCP port: 80 targetPort: 80APIversion of the service is V1 and the kind was service there are two important things to consider here first one is above YAML file you can see port 80 and targetPort 80 the major difference between this two was Port on which port does service expose the pod outside and the target port is the port where pod listens. Steps To Use NodePort ServiceStep 1. Create a deployment. For our demo purpose, I choose Nginx as our application with 2 replicas, you can change it as per your requirement.$ kubectl create deploy --image=nginx:1.23 nginx --replicas=2Step 2. Expose service with NodePortkubectl expose deploy nginx --type=NodePort --port=8080 -target-port=80we exposed our deployment as a NodePort service with the name nginx-serviceCheck your service (Optional):$ kubectl get svc nginx-service -o wideYou can see we've successfully exposed our service with NodePortStep 3. Access your application$ minikube service nginx-service --urlOn invoking this, you can see it in the browser:As you can see in the above image we can access our application on our machine which is running on our cluster, this is only possible because of the NodePort service.Difference Between NodePort And ClusterIPNodePort ClusterIPNodePort service will exposes the static port on each IP address and also it allows the traffic from internet to access the pod.Expose the service on an internal IP address which can be reachable with in the cluster. If you want to expose the pods to external and also want to use it for inside the cluster then you can use NodePort. If you didn't want to expose the pod to out side and need to be used for internal purpose you can use the ClusterIP.If you need to expose the application like web-applications then you can use the NodePort SerivceMainly used for the internal purposes like databases API services which are used for internal purpose. NodePort service is used to expose the application outside of the cluster and ClusterIP is used to access for internal purpose only. Comment More infoAdvertise with us Next Article Kubernetes - ClusterIP vs NodePort vs LoadBalancer A anuragsinghrajawat22 Follow Improve Article Tags : Technical Scripter Kubernetes DevOps Technical Scripter 2022 azure-kubernetes-services +1 More Similar Reads Kubernetes Tutorial Kubernetes is an open-source container management platform that automates the deployment, management, and scaling of container-based applications in different kinds of environments like physical, virtual, and cloud-native computing foundations. In this Kubernetes Tutorial, you are going to learn all 8 min read Introduction to KubernetesIntroduction to Kubernetes (K8S)Before Kubernetes, developers used Docker to package and run their applications inside containers. Docker made creating and running a single container easy, but it became hard to manage many containers running across different machines. For example, what if one container crashes? How do you restart 15+ min read Kubernetes - ArchitectureKubernetes Cluster mainly consists of Worker Machines called Nodes and a Control Plane. In a cluster, there is at least one worker node. The Kubectl CLI communicates with the Control Plane and the Control Plane manages the Worker Nodes. In this article, we are going to discuss in detail the architec 5 min read Kubernetes - Monolithic Architecture of KubernetesThere is a new way of developing software apps using a microservices architecture. That's when all the buzz around containers and container orchestration has increased but we have been developing and using these large software apps even before most of us were born. So in this article, we will be dis 7 min read Kubernetes Vs DockerKubernetes and Docker are two of the most widely used technologies in modern application deployment and DevOps. Docker allows you to package applications into containers, making them easy to run anywhere. Kubernetes helps you manage, scale, and automate the deployment of these containers across mult 5 min read Installation and SetupHow to Install and Run a Kubernetes Cluster on Ubuntu 22.04 (Step-by-Step)You can install and configure Kubernetes in different ways on your personal laptops, physical servers, Virtual machines, and as a cloud service. Before moving ahead with this article, we need to have a basic understanding of Kubernetes and its architecture and containers. In this article, we will ge 6 min read How to Install and Configure Kubernetes on Ubuntu?Kubernetes is open-source software that helps to solve problems related to container-based software automation. It is like a container based system, which helps to distribute out the work that needs to be executed while testing software. Kubernetes are portable in nature. That is why it is widely us 8 min read How to set up Kubernetes cluster on local machine using minikube ?Creating a Kubernetes cluster on AWS, Google Cloud, etc, can be a little difficult and cost you a pretty decent amount of money. If you have a Windows machine or a mac then it is easy to create a multi-container cluster using Docker Desktop for windows/mac and use Kubernetes to manage the cluster. P 3 min read Application DeploymentWhat are Kubernetes Containers?Kubernetes is an open-source container orchestration framework that was originally developed by Google. Container orchestration is automation. It can facilitate you to deploy the identical application across different environments like physical machines, virtual machines cloud environments, or perha 15 min read Kubernetes - Introduction to Container OrchestrationIn this article, we will look into Container Orchestration in Kubernetes. But first, let's explore the trends that gave rise to containers, the need for container orchestration, and how that it has created the space for Kubernetes to rise to dominance and growth. The growth of technology into every 4 min read Kubernetes - ImagesPre-requisite:- Kubernetes A container image is used to represent binary data that is being used to encapsulate an application and all its software dependencies. Container images can be represented as executable software bundles that run standalone and make very defined assumptions about their runti 3 min read Kubernetes - JobsPre-requisite: Kubernetes In the Kubernetes world, jobs are considered an object to act as a supervisor or controllers of a task. The Kubernetes job will create a pod, monitor the task, and recreate another one if that pod fails for some reason. Upon completion of the task, it will terminate the pod 4 min read Kubernetes - Labels & SelectorsAn open-source container management platform called Kubernetes automates the deployment, scaling, descaling, and load balancing of containers (also called a container orchestration tool). It was created by Google in Golang and has a sizable community as a result of that. Google eventually donated it 5 min read Kubernetes - NamespacesKubernetes Namespace is a mechanism that enables you to organize resources. It is like a virtual cluster inside the cluster. A namespace isolates the resources from the resources of other namespaces. For example, You need to have different names for deployments/services in a namespace but you can ha 9 min read Kubernetes - NodeKubernetes Nodes are the Worker or master machines where the actual work happens. Each Kubernetes node has the services required to execute Pods and is controlled by the Control Plane. Each Kubernetes Node can have multiple pods and pods have containers running inside them. 3 processes in every Node 13 min read Kubernetes - NodePort ServiceNodePort service in Kubernetes is a service that is used to expose the application to the internet from where the end-users can access it. If you create a NodePort Service Kubernetes will assign the port within the range of (30000-32767). The application can be accessed by end-users using the node's 5 min read Kubernetes - ClusterIP vs NodePort vs LoadBalancerThree main service types are used in Kubernetes networking: ClusterIP, NodePort, and LoadBalancer. Each has a specific function in controlling external access and service-to-service communication. Comprehending their distinctions is essential for efficiently coordinating applications. This article e 7 min read Kubernetes - ServicesSoftware deployment, scaling, and management are all automated using Kubernetes, an open-source container orchestration system. K8s is another name for Kubernetes. Kubernetes was initially developed by Google and is now managed by the Cloud Native Computing Foundation. Despite the fact that it now s 3 min read Kubernetes Pods: How to Create and Manage ThemKubernetes is an open-source container orchestration system mainly used for automated software deployment, management, and scaling. Kubernetes is also known as K8s. Kubernetes was originally developed by Google, but it is now being maintained by the Cloud Native Computing Foundation. It was original 13 min read How to Run Shell Commands in Kubernetes Pods or ContainersIn Kubernetes, we create pods by adding an extra layer of information on containers. This Kubernetes in short is known as K8s, an open-source container orchestration tool developed by Google. It is used to orchestrate the containers for bringing Agility in software deployment through scaling, and ma 6 min read Kubernetes - Creating Multiple Container in a PodPre-requisite:- Kubernetes Kubernetes is a container management tool and it automates container deployment, load balancing, and container scaling. It is open-source and developed by Google in 2014 and written in Golang. All cloud providers adopt Kubernetes. It is scheduled runs and manages isolated 3 min read Kubernetes - Replication ControllerWith the help of the open-source container orchestration technology Kubernetes, software deployment, scalability, and management are mostly automated. Another name for Kubernetes is K8s. Google created Kubernetes, which is now overseen by the Cloud Native Computing Foundation. Even though it now wor 7 min read Kuberneters - Difference Between Replicaset and Replication ControllerPre-requisite: Kubernetes Kubernetes is also known as K8s is an open-source container orchestration tool developed by google which is used for automating software deployment, scaling, and management. Currently, it is being maintained by the cloud native computing foundation(CNCF). K8s has two versio 4 min read What is Kubernetes Deployment?Kubernetes is an open-source Container Management tool that automates container deployment, container scaling, descaling, and container load balancing (also called as container orchestration tool). It is written in Golang and has a huge community because it was first developed by Google and later do 10 min read ConfigmapsKubernetes - ConfigMapsKubernetes allows you to run and manage applications in containers. However, when you need to update configurations like usernames, passwords, or URLs without modifying the application code, ConfigMaps provide an efficient solution. ConfigMaps separate application configuration from the application 10 min read Kubernetes - Create Config Map From FilesPre-requisite: Kubernetes While creating a manifest file in Kubernetes, we can define environment variables. However, when you have a lot of manifest files, it will become difficult to manage the environment data stored in various manifest files. To overcome this issue, we can manage environment dat 3 min read Kubernetes - Create ConfigMap From YAML FileA ConfigMap is a dictionary consisting of non-confidential data. Its primary role is to keep the configuration separate from the container image. ConfigMap can be created in different ways. This article will cover the declarative approach to creating ConfigMap from the YAML file. Example: apiVersion 1 min read Kubernetes - Config Map From DirectoryPre-requisite:- Kubernetes Software deployment, scalability, and administration are mostly automated using Kubernetes, an open-source container orchestration framework. K8s is another name for Kubernetes. Kubernetes was initially developed by Google and is now managed by the Cloud Native Computing F 2 min read Kubernetes - Injecting ConfigMap as FilesPre-requisite:- Kubernetes The automated deployment, scaling, and administration of software using a system called Kubernetes, an open-source container orchestration tool. K8s is another name for Kubernetes. Kubernetes was initially developed by Google and is now managed by the Cloud Native Computin 3 min read Kubernetes - Injecting ConfigMap in PodsPre-requisite: Kubernetes Leveraging the open-source container orchestration engine Kubernetes to automate the deployment, scalability, and management of applications. Another name for Kubernetes is K8s. Google originally created Kubernetes, which is currently overseen by the Cloud Native Computing 3 min read Scaling and Updating ApplicationsKubernetes - VolumesKubernetes is an open-source container orchestration tool developed by Google. It is primarily employed to automate the deployment, scaling, and management of software. In short, Kubernetes is termed as K8s. Kubernetes is currently maintained by the Cloud Native Computing Foundation. Although it now 9 min read Kubernetes - SecretsKubernetes is an open-source container orchestration system mainly used for automated software deployment, management, and scaling. Kubernetes is also known as K8s. Kubernetes was originally developed by Google but it is now being maintained by Cloud Native Computing Foundation. It was originally de 14 min read Kubernetes - Working With SecretsKubernetes Secrets are objects that are used to store secret data in base64 encoded format. Using secrets enables developers not to put confidential information in the application code. Since Secrets are created independently of the pods, there is less risk of secrets being exposed. Uses of Secrets: 1 min read Kubernetes - Load Balancing ServiceBefore learning Kubernetes (or K8S in Short), you should have some knowledge of Docker and Containers. Docker is a tool that helps the developer create containers in which applications can run in an isolated environment. Containers are just an abstraction for the applications inside. Docker also pro 12 min read Kubernetes - Service DNS An open-source container orchestration system called Kubernetes is primarily employed for the automated deployment, scaling, and management of software. Another name for Kubernetes is K8s. Initially created by Google, Kubernetes is currently maintained by the Cloud Native Computing Foundation. Altho 11 min read Additional TopicsWhat is Kubernetes API ?Complete GuideKubernetes API is an application that serves Kubernetes functionality through a RESTful interface and stores the state of the cluster via HTTP. Users can directly interact with the Kubernetes API or via tools like kubectl. It supports retrieving, creating, updating, and deleting primary resources vi 14 min read Kubernetes - Taint and TolerationA pod is a group of one or more containers and is the smallest deployable unit in Kubernetes. A node is a representation of a single machine in a cluster (we can simply view these machines as a set of CPU and RAM). A node can be a virtual machine, a physical machine in a data center hosted on a clou 6 min read Kubernetes Resource Model (KRM) and How to Make Use of YAML?Here we will explain how YAML can simplify system management and automation of most processes so that Kubernetes is a convenient working system. Basic Kubernetes Models: KRM and Everything-as-CodeAccording to Kubernetes co-founder Brian Grant, Kubernetes is very convenient thanks to the Kubernetes R 6 min read Installing Private Git Server on K8s Cluster with Gitea and AKSIn this article, we are going to install a self-hosted Gitea server on top of Azure Kubernetes Service with Helm and set up a git repo. Having a private Git server might be beneficial these days. Gitea is a community-managed Git-compatible lightweight code hosting solution written in Go. It is publi 4 min read Enable Remote Debugging For Java Application Deployed in Kubernetes EnvironmentDuring Development, developers have to debug their applications to resolve code problems. In order to debug a java application which is deployed on remote machine in a Kubernetes cluster, first developer has to do some steps to enable its application ready for debugging. Below are the manual steps t 2 min read How to Enable JMX For Java Application Running in the Kubernetes Cluster?Many times we want to monitor our application's CPU utilization, background thread behavior, and most importantly memory consumptions for tasks that deal with loads for data (500MB - 1GB) or much more data. Such monitoring helps to find which operation is causing heavy CPU or Memory utilization and 3 min read Like