DEV Community

Cover image for #043 Kubernetes - Services 3
Omar
Omar

Posted on

#043 Kubernetes - Services 3

Introduction

intro
this is part 43 from the journey it's a long journey(360 day) so go please check previous parts , and if you need to walk in the journey with me please make sure to follow because I may post more than once in 1 Day but surely I will post daily at least one 😍.

And I will cover lot of tools as we move on.


NodePort

theory
let's start with the theory first ,

ClusterIP vs NodePort

The clusterIP service let us to communicate inside the cluster itself , but let's say we need the user to interact with the app , so he need a service to do this , it's can be assigned to any pod inside the cluster , it's valid using the NodePort service which let our cluster communicate with the outside of cluster.
communicate
In the picture we can see that the user can't interact with the cluster directly.

how NodePort work

nodeport1
We need to know that every node it self have an port ranging between 30000-32767 , also container had port called target port , and lastly our service had a port.

apiVersion: v1
kind: Service
metadata:
  name: api-service
spec:
  type: Nodeport
  ports:
    - targetPort: 10253
      port: 8081
      nodePort: 30005
    selector:
      app: myapp
      type: rest-api
Enter fullscreen mode Exit fullscreen mode

we can see in the specs the ports we describe them like this , myapp is the name of the pod.

if i need to access the pod in browser I use the link in this form NodeIP:port , NodeIp in the image is 192.168.99.102 and port is 30005 , so the link will look like this 192.168.99.102:30005 and now I can access the node from outside of cluster.
in real life the port is 80 , those settings can be done when we buy the host , we can use a proxy to change port from 30005 to 80 , and domain name to access it using a name not ip.

A good question here if I have a 10 replicas , every one is in a node every node have an IP , What is the solution?
problema
We can do a lot of things here like load balancing and Ingress , Ingress is very good for big applications.

Top comments (0)