Port Definitions
In the kubernetes service, there is one section called targetPort in the nodePort service instead of using the port number you can directly use the name of the pods.
Example
kind: Pod
metadata:
name: tomcat
labels:
deployemnt: deployemnet-java
spec:
containers:
- name: tomcat
image: tomact:latest
ports:
- containerPort: 8080
name: http-deplyment-port
---
apiVersion: v1
kind: Service
metadata:
name:tomcat-service
spec:
selector:
deployemnt: deployemnet-java
ports:
- name: name-of-service-port
protocol: TCP
port: 80
targetPort:http-deplyment-port
For example, we can see that instead of using the “targetPortnumber” you can use the name of the container as mentioned below. The target port is the port number that the service or pod is forwarding requests to.
What are Kubernetes Services? | Complete Guide
In Kubernetes, each pod is assigned its IP address but the pods are ephemeral that is they can be destroyed easily and when a new pod is created in place of them a new IP address is assigned to them. Here the role of services comes into the picture. A service is like a permanent IP address assigned to a pod. A service IP address is stable. So instead of sending a request to a pod, the client requests a service, and the service forwards that request to the desired pod. Services also help in load-balancing.
Table of Content
- What Are Services in Kubernetes?
- How do Kubernetes Service Work?
- How do You Define A Kubernetes Service?
- Port Definitions
- Services Without Selectors
- EndpointSlices
- Application Protocol
- Multi-Port Services
- Load Balancers With Mixed Protocol Types
- Choosing Your Own IP Address
- Choosing Your Own Port
- Types of Services
- How do You Access A Kubernetes Service? A Step-By-Step Guide
- Headless Services
- How to Create and Use A Kubernetes Service to Expose Your Application?: A Step-By-Step Guide
- What are the Differences between Kubernetes Service vs pod?
- What are the Differences between a Service and a Deployment?
- What are the Differences of Docker Service and Kubernetes Service?
- Discovering services
- Kubernetes Service – FAQs