MsA
MsA

Reputation: 2979

How to manually autoscale pods while load balancing?

I have tried defining LoadBalancer in my service type and creating a deployment for it with 3 replicas:

kind: Service
apiVersion: v1
metadata:
  name: springboot-postgres-k8s
  labels:
    name: springboot-postgres-k8s
spec:
  ports: # ...
  selector: # type: ...
  type: LoadBalancer # <=====

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: springboot-postgres-k8s
spec:
  selector:
    matchLabels:
      app: springboot-postgres-k8s
  replicas: 3 # <=====
  template: # ...

This starts up three pod and a load balancer which successfully load balances request among these three pods.

I want to know if k8s allows to manually autoscale the pods. That is if my cluster with 3 replicas + a load balancer is up and running, how can I manually increase replicas and still make the existing load balancer to scale across all 4 replicas (3 old and one newly created)?

Do I have to run (ref1 ref2):

kubectl scale --current-replicas=3 --replicas=4 deployment/springboot-postgres-k8s

Q1. Will above command notify existing load balancer of newly created pod?

or I have to run following (as specified in ref2)

kubectl scale --replicas=4 -f foo.yaml

Q2. Will above command notify existing load balancer of newly created pod?
Q3. What if my foo.yaml contains both service and deployment definition?

Upvotes: 0

Views: 125

Answers (1)

Tarum
Tarum

Reputation: 993

Yes its allows manual autoscale.

When you create a service in Kubernetes, k8s automatically creates kind: Endpoints type resource(s) for your pods with a matching label selector. This resource referenced by a Service to define which Pods the traffic can be sent to and periodically updated by the k8s when pods are created or deleted.

So regardless of the creation time of resources, k8s will handle the update and pods will be able to receive traffic from loadbalancer.

Upvotes: 1

Related Questions