0

I am new to kubernetes and I went through many articles but didnt find a basic answer to my doubt.

Suppose I have 2 nodes kubernete cluster and I have deployed 2 applications on it then.

  1. My both of the apps will be hosted on both of the nodes? Like app1 on both of the nodes and similarly app2? it means we have replication factor of 2 by default. Correct?

  2. It will have 1 pod per node? What will be the structure?

Node 1, Pod1 - > App1
Node 1, Pod1 - > App2
Node 2, Pod1 - > App1
Node 2, Pod1 - > App2
  1. If I have set replication factor=2 then how it will affect the structure? Will it create
Node 1- Pod1 - > App1
Node 1- Pod2 - > App2
Node 2- Pod1 - > App1
Node 2- Pod2 - > App2
  1. What is deployment in terms of above physical/logical structures? How it differs with service? Deployment is specific to per node?
Roobal Jindal
  • 214
  • 2
  • 13

3 Answers3

3

There's no predefined tying of pods to nodes. The Kubernetes scheduler dynamically decides which node to assign a pod to when the pod is created.

In general, a Kubernetes app consists of a set of replicated pods (in most cases managed by a Deployment resource). Which nodes these pods end up running on is up to the scheduler. There's no built-in policy that replica pods of the same app must run on different nodes.

However, you can influence the decision of the scheduler with various mechanisms:

weibeld
  • 13,643
  • 2
  • 36
  • 50
  • To your statement "There's no built-in policy that replica pods of the same app must run on different nodes", then if I have made cluster of 2 nodes and have deployed 1 app. It means app will reside in either of these 2 nodes. Then what is the use of making a cluster with multiple nodes? I doubt that all nodes of a cluster runs an instance of app. Please clearify – Roobal Jindal Sep 20 '19 at 09:36
  • The purpose of multiple nodes is to assemble compute resources. If you have many apps and they require 20 GB of memory together, and you have nodes with 10 GB of memory, then you need at least two of these nodes so that your apps can run. If you create a cluster with two nodes only to run a single app consisting of a single Pod, then the app will run only on one node and the second node is wasted. But that's not a normal use case. Kubernetes is made for running many apps consisting of many pods on the same cluster. – weibeld Sep 20 '19 at 11:03
0

It depends on how many replicas do you set in your deployment ? If you have 2 nodes and you set 1 replicas in A deployment then you will have 1 pod in first node OR the second node. If you set 3 replicas in A deployment then you will have 3 pod in first node or the second node or 2 pod in first node and 1 pod in second node or also otherwise.

Nicky Puff
  • 149
  • 3
  • 14
  • Thanks, it makes sense. If I have 5 microservices, then how many deployments I should make? Should I make 5 services under one deployment or 5 different deployments? What is the deciding factor? – Roobal Jindal Sep 20 '19 at 09:45
  • Each microservice should be defined in one [Deployment](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.15/#deployment-v1-apps) consisting of a configurable number of pod replicas. So, you can scale each microservice separately. – weibeld Sep 20 '19 at 11:10
0

A pod comprises of an application container or a group of application containers. When there are more than 1 containers in a pod, the kubernetes scheduler makes sure that all the containers defined in the pod spec gets created on the same Node.

Kubernetes scheduler always tries to spread pods across nodes depending on various factors including resource availability.

Regarding your questions:

  1. My both of the apps will be hosted on both of the nodes? Like app1 on both of the nodes and similarly app2? it means we have replication factor of 2 by default. Correct?

If the replication count is '1' for both pods, then only one pod instance will be created for each app regardless of the number of nodes. Otherwise, Kubernetes scheduler dynamically decides where to put extra replicas depending on the resource (CPU, memory) availabile on each node. The default replication count (aka replicas) is 1.

  1. It will have 1 pod per node? What will be the structure?

If both nodes have enough resource availability, the structure could look like this:

Node 1 - Pod 1 -> App1
Node 2 - Pod 2 -> App2
  1. If I have set replication factor=2 then how it will affect the structure? Will it create

Depending upon the resource availability, the kubernetes scheduler could create additional replicas like this:

Node 1 - Pod 1 -> App1
         Pod 2 -> App2
Node 2 - Pod 1 -> App1
         Pod 2 -> App2
Junaid
  • 3,477
  • 1
  • 24
  • 24
  • From what I have seen, usually the scheduler tries to balance the number of pods across nodes, and also tries not to put the same pod replica on the same node but same pod replicas can end up on the same node. I'm not familiar (and haven't looked) at the backend code for scheduler though. – Junaid Sep 20 '19 at 09:52