https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale/ https://kubernetes.io/docs/concepts/cluster-administration/cluster-autoscaling/ https://github.com/kubernetes/autoscaler/tree/master/cluster-autoscaler Inspiré de https://connect.ed-diamond.com/linux-pratique/lphs-051/equilibrage-de-charge-dans-les-environnements-traditionnels-et-cloud#index_h3_34 : k top po --sum --containers k top no [ OPTIONS ] root@noeud1:~# microk8s enable metrics-server k top po --sum --containers k top no [ OPTIONS ] root@noeud1:~# cat whoami-deployment.yaml apiVersion: apps/v1 kind: Deployment metadata: name: whoami-deployment labels: app: whoami spec: selector: matchLabels: app: whoami replicas: 1 template: metadata: labels: app: whoami spec: containers: - name: whoami image: containous/whoami:v1.5.0 ports: - containerPort: 80 # Il faut spécifier le champ `requests` pour le CPU # pour que l'autoscaling basé sur celui-ci fonctionne resources: requests: cpu: 10m # 10 milli-cpu => 0.01 CPU requis / INDISPENSABLE pour la mise en place d'un autoscaler root@noeud1:~# k create -f whoami-deployment.yaml root@noeud1:~# k expose deploy whoami-deployment k autoscale deployment unserveur --min=2 --max=10 --cpu-percent=20 # invocation avant version K8s 1.3? (autoscaling/v1) k autoscale deployment essai --min=2 --max=10 --cpu=20% # K8s 1.3? et + (autoscaling/v2) --dry-run=client -o yaml > manifeste_hpa.yaml root@noeud1:~# cat whoami-hpa.yaml apiVersion: autoscaling/v1 kind: HorizontalPodAutoscaler # https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale/ metadata: name: whoami-hpa labels: app: whoami spec: minReplicas: 1 # Nombre de réplicats minimal garanti maxReplicas: 10 # Nombre de réplicats maximal garanti scaleTargetRef: apiVersion: apps/v1 kind: Deployment name: whoami-deployment targetCPUUtilizationPercentage: 50 # 50% d'utilisation CPU # Formule utilisée par le HPA pour calculer le nombre de réplicas : desiredReplicas = ceil[currentReplicas * ( currentMetricValue / desiredMetricValue )] root@noeud1:~# k create -f whoami-hpa.yaml root@noeud1:~# watch -n .5 kubectl get all -l app==whoami Dans autre panneau tmux : root@noeud1:~# for N in {1..2500} ; do curl -s ADRESSE_IP_DU_SERVICE_GÉNÉRÉ_CI-DESSUS > /dev/null ; done