Bob
Bob

Reputation: 8724

Kubernetes number of pods

I am not sure where is the number of pods that should run defined in Kubernetes.

If I run kubectl get pods -n my-namespace, I can see:

NAME                                                              READY     STATUS    RESTARTS   AGE
my-project-code-php-fpm-6db9cc4796-spz72                          3/3       Running   0          52m
my-project-code-php-fpm-6cb598f7c5-4hhhc                          3/3       Running   0          45m
my-project-code-rabbit-worker-6cb598f7c5-4ldx9                    3/3       Running   0          4m

I would like to change the number of pods for my-project-code-rabbit-worker-6cb598f7c5-4ldx9, but I am not sure where this number 3 is coming from. Any help?

Thanks!

Upvotes: 0

Views: 1987

Answers (2)

Btc Sources
Btc Sources

Reputation: 2061

When you deploy your application in kubernetes (k8s), it is weird that you rely directly on pod deployments (deploying pods yourself).

The Managed Approach

There are a set of higher abstraction entities that allow you to control the behavior of your application, and they can manage the number of desired pods.

These entities include statefulsets, replicasets or deployments. The latest, deployments, are the most common used for stateless apps. They use beneath them replicasets, which is the real component that is able to manage how many pods do you want to have deployed.

If you have deployed your application by defining a deployment, in your .yaml file you should have a replicas key with the desired number of pods that you want to be executing in parallel. Something like:

spec:
  replicas: 3

If you were to get this info after having deployed your deployment object, your should get it with kubectl as:

kubectl get deployments

With an output like, for example:

NAME               READY   UP-TO-DATE   AVAILABLE   AGE
nginx-deployment   0/3     0            0           1s

Where the ready column is the one with pods ready / desired pod replicas.

The Unmanaged Approach

On the other side, if you choose to initialize your pods without these higher level entities, they will be not managed pods, and therefore you will have to manage them yourself.

Find further info in the links from the official docs above.

Pods VS Containers

If we jump back to your question, you were watching a 3/3 value in your kubectl answer. When getting pods, a pod is composed by one or several containers. They are defined in the pod .yaml definition file, and they don't have to be the same application or service.

In fact, they usually aren't, since you will group in the same pod containers that need to be together for some reason or to achieve some specific tasks (see Init Containers patterns, and so on).

So when you're retrieving the pods, you're not looking at a number of how many pod replicas are available, but how many of its containers have reached a ready state / all containers that compose the pod.

Upvotes: 2

user80867
user80867

Reputation: 50

Check you .yaml

spec:
  replicas: 3  --> change this

Upvotes: 0

Related Questions