- We deploy pod as a deployment in kubernetes, deployment will crete a replica-set and RS wiil create a POD
- We have a requirement of creating 3 replica-sets, Let say their are 10 concurrent users (That means users are using the application at same point of time) If it is one replica it usually go down that'y we use multiple replicas
- No. of replicas depends up on no. of users trying to access the application and no of connections one particular pod can take
- If a pod goes down then replica-set will create a pod again auto healing but as pervious pod had different IP and now NEWLY CREATED POD AS NEW IP different from old pod
- The application come up but IP ADDRESS of the application is changed.
- This application IP should be shared to other teams to work on in prod
- When a pod goes down, it will create new pod replica-set controller ensures to do that by using auto-healing concept.
- But after creating new pod it place of old pod the new pod has new IP ADDRESS, so end user or others can not use the application.
- SO, TO SOLVE THIS ISSUE WE USE SERVICE ON TOP OF DEPLOYMENT AND THAT WILL ACT AS LOAD BALANCER AND WE GIVE THAT SERVICE IP ADDRESS TO ACCESS THE APPLICATION TO END USER OR OTHER TEAMS FOR TESTING AND STUFF.
- Access by using service names, The service internally uses KUBE PROXY
- SERVICE usees Kube proxy it will forward the request
- When service-name is given instead of pod IP address that's fine, But service should know the new IP address of the pod
- If service also follow the same problem of keeping a track of IP address the problem is not solved at all.
- THis PROBLEM SOLVED is done by Service Discovery
- What service does i will not bother about IP address at all it will come up with new process called LABELS AND SELECTORS.
- labels and selectors for every pod that is getting created, dev's will apply a LABEL, the LABEL will be common for all the PODS
- THE PROBLEM IS Solved, This is the service discovery machism of kubernetes
- Whenever we create deployment, inside the metadata of our deployment we create something called as a LABEL (It is jsut a TAG ) this deployment will create REPLICA-SET it will create PODS and for both the PODS it will have LABEL , Let say one pod gone down so the IP will be changed the replica-set will create new pod which has same LABEL
- SERVICE offer load balacing, and service will keep track of LABELS instead of IP address, It maintains all the stuff and this process is called SERVICE DISCOVERY PROCESS.
- A service can EXPOSE our application, Service can allow our application to access outside the kubernetes cluster
- SERVICE OF 3 types Cluster ip, Node Port, Load Balancer ( These are the default type)
- IF we create service by cluster IP -- It still only be access inside the kubernetes cluster, We get two benefies that are discovery and load balancer
- NodePort mode -- It will allow our application to access inside your Organziation, anybody within your Organization or anybody within your Network, Whoever have the node ip address they can access the application.
- Load Balanceer -- It is basically our service will expose the application to external world Ex: on cloud EKS -- we will get Elastic load balancer -- anywhere in the world access using public IP address NOTE: This load balancer will not work on Minikube only works on Cloud paltforms
- Kubernetes cluster, created a deployment -- replica-set -- pod all of these things is inside a NODE (Worker node 1) On up of this we have SERVICE
We create this as a CLUSTET IP
- This service will be only accessed by the people who has access to this KUBERNETES CLUSTER
- THERE IS CUSTOMER WHO IS OUTSIDE THE ORGANISATION BOTH ARE NOT IN SAME NETWORK HE DO NOT HAVE ACCESS TO APPLICATIONON
We have crated LOAD BALANCER TYPE SERVICE
- The service that got created it will say that if we assume this cluster in AWS, It will notify aws kubernetes api server will notify aws -- EKS -- service load balancer mode -- Can you give me a elastic load balancer IP address which means a PUBLIC IP ADDRESS. CLOUD CONTROL MANAGER IS DOING THIS IT IS PART of master node
- Now anyone can access the application using internet
NODE PORT mode
- It can give access to people who has access to WORKER NODE 1, So whoever can access the workder node IP ADDRESS. Let say the worker nodes are EC2 instance ip address, They can access me
- Whoever has EC2 instance trafiic or VPC traffic they can access the application or pods.
kubectl edit svc <svc-name>
minikube service node-app-service
idrbt1@idrbt1:~/k8s$ minikube service node-app-service
|-----------|------------------|-------------|-----------------------------|
| NAMESPACE | NAME | TARGET PORT | URL |
|-----------|------------------|-------------|-----------------------------|
| default | node-app-service | 5000 | http://192.168.59.100:30001 |
|-----------|------------------|-------------|-----------------------------|
🎉 Opening service default/node-app-service in default browser...
- NodePort -- local as well as who has access to instance or minikube
- LoadBalncer -- Everyone in the world Note: Bydefault minikube does not support LoadBalancer type only EC2 or other clouds supports, people are working to get this feature in minikube as well.