Shashikant shah

Monday, 29 April 2024

What is NodePort Service in kubernetes ?

 NodePort:-

1. A NodePort service exposes the service on the IP of each node at a static port. A ClusterIP service is created automatically to route the traffic to the NodePort service. Users can communicate with the service from the outside by requesting <NodeIP>:<NodePort>

2. You can only use ports 30000–32767.

3. You can only have one service per port.

4. If you create a NodePort, then the endpoint service will also be created.


i) The node IP will be connected to nodeport 30010 and the 30010 port will be redirected to port 8081.

ii) 8081 will redirect to the port 80 endpoint.

# kubectl create deployment nodeport-deployment --image=nginx --replicas=2

# kubectl get deploy -o wide


# vim nodeport.yaml

apiVersion: v1

kind: Service

metadata:

  name: nginx-service

spec:

  type: NodePort

  selector:

    app: nodeport-deployment

  ports:

    - protocol: TCP

      port: 8081

      targetPort: 80

      nodePort: 30010

 

for svc

# kubectl get svc nginx-service -o wide

for pods

# kubectl get pods --show-labels

# kubectl get pods -o wide

Test NodePort with NodeIP.


For ClusterIP with endpoint Port.




No comments:

Post a Comment