简体   繁体   中英

In Kubernetes (k8s) why do deployments supports replicas?

In K8S, the below creates a deployment with n replicas -
$ kubectl run nginx --imaage nginx --replicas 6

But how can these replicas be accessed in a load balanced way as they don't have any common entry point (like service wrapped around them).

So what is the purpose of deployments being able to scale OR how can they be accessed in a load balanced fashion (without a service wrapped over deployment).

Replicas

.spec.replicas is an optional field that specifies the number of desired Pods. It defaults to 1. and which will help replicaset to manage pods and desired number of pods should be available no matter what kubernetes controller-manager will take care of that.

Well if you are running deployment without service then it does not make any sense, no matter what you scale for 1 replicas or 6. If your create service and map to your deployment then kubernetes will take care of load balancing between pods. For more info please check this section of docs https://kubernetes.io/docs/concepts/services-networking/service/#virtual-ips-and-service-proxies

It depends on the use-cases that you are solving with a deployment. For most use cases applications need to be exposed by service over HTTP/TCP layer to receive traffic and load balance between replicas.

Some applications does not need to be exposed by a service and load balanced at HTTP or TCP layer but you may need multiple replicas to be running using a deployment.For example if you have a non HTTP/TCP application which processes a batch of records periodically or triggered by an external non HTTP/TCP event. Having a deployment in this case makes sense because you can easily scale up/down or rollback and make use of other key features provided by deployment.

So in short depending on the use cases deployment without a service sometimes makes sense. Service is only needed to do load balancing between multiple replicas at HTTP/TCP layer.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM