Kubernetes: nahoana no zava-dehibe ny manamboatra ny fitantanana ny loharanon-karena?

Amin'ny maha-fitsipika, ilaina foana ny manome dobo filomanosana manokana ho an'ny fampiharana iray ho an'ny fiasa marina sy maharitra. Ahoana anefa raha misy fampiharana maro mandeha amin'ny hery mitovy? Ahoana no hanomezana ny tsirairay amin'izy ireo ny loharanon-karena faran'izay kely indrindra? Ahoana no ahafahanao mametra ny fampiasana loharanon-karena? Ahoana ny fizarana tsara ny entana eo anelanelan'ny nodes? Ahoana no hiantohana fa miasa ny mekanika fanamafisam-peo marindrano raha mitombo ny enta-mavesatra?

Kubernetes: nahoana no zava-dehibe ny manamboatra ny fitantanana ny loharanon-karena?

Mila manomboka amin'izay karazana loharanon-karena lehibe misy ao amin'ny rafitra ianao - izany, mazava ho azy, dia ny fotoana processeur sy ny RAM. Ao amin'ny k8s manifests ireto karazana loharano ireto dia refesina amin'ireto singa manaraka ireto:

  • CPU - amin'ny cores
  • RAM - amin'ny bytes

Ankoatra izany, ho an'ny loharano tsirairay dia azo atao ny mametraka karazana fepetra roa - fangatahana и fetra. Fangatahana - mamaritra ny fepetra faran'izay kely indrindra ho an'ny loharano maimaim-poana amin'ny node iray mba hampandehanana kaontenera (sy pod amin'ny ankapobeny), raha ny fetra kosa dia mametraka fetra mafy amin'ny loharanon-karena azo amin'ny container.

Zava-dehibe ny mahatakatra fa ny manifest dia tsy voatery mamaritra mazava tsara ireo karazany roa ireo, fa ny fihetsika dia ho toy izao manaraka izao:

  • Raha ny fetran'ny loharano iray ihany no voafaritra mazava, ny fangatahana an'ity loharano ity dia maka sanda mitovy amin'ny fetra (azonao atao ny manamarina izany amin'ny fiantsoana ny enti-manana). Ireo. raha ny marina, ny kaontenera dia ho voafetra amin'ny habetsaky ny loharano ilainy amin'ny fandehanana.
  • Raha ny fangatahana ihany no voafaritra mazava ho an'ny loharano iray, dia tsy misy fameperana ambony apetraka amin'ity loharano ity - i.e. ny kaontenera dia voafetran'ny loharanon'ny node ihany.

Azo atao ihany koa ny manamboatra ny fitantanana ny loharanon-karena tsy amin'ny haavon'ny kaontenera manokana, fa koa amin'ny sehatra anaram-boninahitra amin'ny fampiasana ireto singa manaraka ireto:

  • LimitRange — manoritsoritra ny politika famerana eo amin'ny haavon'ny kaontenera/pod ao amin'ny ns ary ilaina mba hamaritana ny fetra mahazatra amin'ny kaontenera/pod, ary koa hisorohana ny famoronana kaontenera/pods (na ny mifamadika amin'izany), mametra ny isany. ary fantaro ny mety ho fahasamihafana eo amin'ny sanda amin'ny fetra sy ny fangatahana
  • ResourceQuotas - mamaritra ny politika famerana amin'ny ankapobeny ho an'ny kaontenera rehetra ao amin'ny ns ary ampiasaina, amin'ny ankapobeny, mba hamerana ny loharanon-karena eo amin'ny tontolo iainana (ilaina rehefa tsy voafaritra mazava ny tontolo iainana amin'ny haavon'ny node)

Ireto manaraka ireto dia ohatra amin'ny fanehoana izay mametraka fetran'ny loharanon-karena:

  • Amin'ny haavon'ny container manokana:

    containers:
    - name: app-nginx
      image: nginx
      resources:
        requests:
          memory: 1Gi
        limits:
          cpu: 200m

    Ireo. Amin'ity tranga ity, mba hampandehanana kaontenera miaraka amin'ny nginx, dia mila farafahakeliny 1G ny RAM maimaim-poana sy 0.2 CPU amin'ny node, raha ny ankamaroan'ny container dia afaka mandany 0.2 CPU sy ny RAM rehetra misy ao amin'ny node.

  • Amin'ny ambaratonga integer ns:

    apiVersion: v1
    kind: ResourceQuota
    metadata:
      name: nxs-test
    spec:
      hard:
        requests.cpu: 300m
        requests.memory: 1Gi
        limits.cpu: 700m
        limits.memory: 2Gi

    Ireo. ny fitambaran'ny kaontenera fangatahana rehetra ao amin'ny default ns dia tsy afaka mihoatra ny 300m ho an'ny CPU sy 1G ho an'ny OP, ary ny fitambaran'ny fetra rehetra dia 700m ho an'ny CPU ary 2G ho an'ny OP.

  • Fepetra mahazatra ho an'ny kaontenera ao amin'ny ns:

    apiVersion: v1
    kind: LimitRange
    metadata:
      name: nxs-limit-per-container
    spec:
     limits:
       - type: Container
         defaultRequest:
           cpu: 100m
           memory: 1Gi
         default:
           cpu: 1
           memory: 2Gi
         min:
           cpu: 50m
           memory: 500Mi
         max:
           cpu: 2
           memory: 4Gi

    Ireo. ao amin'ny toerana misy anarana ho an'ny kaontenera rehetra, ny fangatahana dia apetraka ho 100m ho an'ny CPU ary 1G ho an'ny OP, fetra - 1 CPU sy 2G. Mandritra izany fotoana izany, misy fetra ihany koa apetraka amin'ny sanda azo atao amin'ny fangatahana / fetra ho an'ny CPU (50m <x <2) sy RAM (500M <x <4G).

  • Famerana ambaratonga pod ns:

    apiVersion: v1
    kind: LimitRange
    metadata:
     name: nxs-limit-pod
    spec:
     limits:
     - type: Pod
       max:
         cpu: 4
         memory: 1Gi

    Ireo. ho an'ny pod tsirairay ao amin'ny default ns dia hisy fetra 4 vCPU sy 1G.

Ankehitriny dia tiako ny hilaza aminao hoe inona no tombony azon'ny fametrahana ireo fameperana ireo ho antsika.

Mekanisma fampifandanjana entana eo anelanelan'ny nodes

Araka ny fantatrao, ny singa k8s dia tompon'andraikitra amin'ny fizarana pods amin'ny nodes, toy ny scheduler, izay miasa araka ny algorithm manokana. Ity algorithm ity dia mandalo dingana roa rehefa misafidy ny node tsara indrindra hanombohana:

  1. fanasivanana
  2. miainga

Ireo. araka ny politika voalaza, nodes no voafantina amin'ny voalohany izay azo atao ny manomboka pod mifototra amin'ny napetraka enti-milaza (ao anatin'izany ny fanamarinana raha manana loharano ampy ny node hampandehanana ny pod - PodFitsResources), ary avy eo ho an'ny tsirairay amin'ireo node ireo, araka ny laharam-pahamehana isa dia omena (anisan'izany ny loharano maimaim-poana ananan'ny node iray, ny isa bebe kokoa omena azy - LeastResourceAllocation/LeastRequestedPriority/BlancedResourceAllocation) ary ny pod dia atomboka amin'ny node misy teboka betsaka indrindra (raha misy node maromaro mahafa-po an'io fepetra io indray mandeha, dia misy kisendrasendra no voafantina).

Mandritra izany fotoana izany, mila mahatakatra ianao fa ny mpandrindra, rehefa manombana ny loharanon-karena misy amin'ny node, dia tarihin'ny angon-drakitra voatahiry ao amin'ny etcd - i.e. ho an'ny habetsaky ny loharano nangatahana/mametra ny pod tsirairay mandeha amin'ity node ity, fa tsy ho an'ny fanjifana loharano tena izy. Ity fampahalalana ity dia azo avy amin'ny famoahana baiko kubectl describe node $NODE, ohatra:

# kubectl describe nodes nxs-k8s-s1
..
Non-terminated Pods:         (9 in total)
  Namespace                  Name                                         CPU Requests  CPU Limits  Memory Requests  Memory Limits  AGE
  ---------                  ----                                         ------------  ----------  ---------------  -------------  ---
  ingress-nginx              nginx-ingress-controller-754b85bf44-qkt2t    0 (0%)        0 (0%)      0 (0%)           0 (0%)         233d
  kube-system                kube-flannel-26bl4                           150m (0%)     300m (1%)   64M (0%)         500M (1%)      233d
  kube-system                kube-proxy-exporter-cb629                    0 (0%)        0 (0%)      0 (0%)           0 (0%)         233d
  kube-system                kube-proxy-x9fsc                             0 (0%)        0 (0%)      0 (0%)           0 (0%)         233d
  kube-system                nginx-proxy-k8s-worker-s1                    25m (0%)      300m (1%)   32M (0%)         512M (1%)      233d
  nxs-monitoring             alertmanager-main-1                          100m (0%)     100m (0%)   425Mi (1%)       25Mi (0%)      233d
  nxs-logging                filebeat-lmsmp                               100m (0%)     0 (0%)      100Mi (0%)       200Mi (0%)     233d
  nxs-monitoring             node-exporter-v4gdq                          112m (0%)     122m (0%)   200Mi (0%)       220Mi (0%)     233d
Allocated resources:
  (Total limits may be over 100 percent, i.e., overcommitted.)
  Resource           Requests           Limits
  --------           --------           ------
  cpu                487m (3%)          822m (5%)
  memory             15856217600 (2%)  749976320 (3%)
  ephemeral-storage  0 (0%)             0 (0%)

Eto isika dia mahita ny pods rehetra mandeha amin'ny node manokana, ary koa ny loharanon-karena izay angatahan'ny pod tsirairay. Ary toy izao ny endriky ny logs scheduler rehefa natomboka ny pod cronjob-cron-events-1573793820-xt6q9 (hiseho ao amin'ny log scheduler ity fampahalalana ity rehefa mametraka ny haavon'ny logging 10 ao amin'ny tohan-kevitra baiko fanombohana -v=10):

HIDITRA

I1115 07:57:21.637791       1 scheduling_queue.go:908] About to try and schedule pod nxs-stage/cronjob-cron-events-1573793820-xt6q9                                                                                                                                           
I1115 07:57:21.637804       1 scheduler.go:453] Attempting to schedule pod: nxs-stage/cronjob-cron-events-1573793820-xt6q9                                                                                                                                                    
I1115 07:57:21.638285       1 predicates.go:829] Schedule Pod nxs-stage/cronjob-cron-events-1573793820-xt6q9 on Node nxs-k8s-s5 is allowed, Node is running only 16 out of 110 Pods.                                                                               
I1115 07:57:21.638300       1 predicates.go:829] Schedule Pod nxs-stage/cronjob-cron-events-1573793820-xt6q9 on Node nxs-k8s-s6 is allowed, Node is running only 20 out of 110 Pods.                                                                               
I1115 07:57:21.638322       1 predicates.go:829] Schedule Pod nxs-stage/cronjob-cron-events-1573793820-xt6q9 on Node nxs-k8s-s3 is allowed, Node is running only 20 out of 110 Pods.                                                                               
I1115 07:57:21.638322       1 predicates.go:829] Schedule Pod nxs-stage/cronjob-cron-events-1573793820-xt6q9 on Node nxs-k8s-s4 is allowed, Node is running only 17 out of 110 Pods.                                                                               
I1115 07:57:21.638334       1 predicates.go:829] Schedule Pod nxs-stage/cronjob-cron-events-1573793820-xt6q9 on Node nxs-k8s-s10 is allowed, Node is running only 16 out of 110 Pods.                                                                              
I1115 07:57:21.638365       1 predicates.go:829] Schedule Pod nxs-stage/cronjob-cron-events-1573793820-xt6q9 on Node nxs-k8s-s12 is allowed, Node is running only 9 out of 110 Pods.                                                                               
I1115 07:57:21.638334       1 predicates.go:829] Schedule Pod nxs-stage/cronjob-cron-events-1573793820-xt6q9 on Node nxs-k8s-s11 is allowed, Node is running only 11 out of 110 Pods.                                                                              
I1115 07:57:21.638385       1 predicates.go:829] Schedule Pod nxs-stage/cronjob-cron-events-1573793820-xt6q9 on Node nxs-k8s-s1 is allowed, Node is running only 19 out of 110 Pods.                                                                               
I1115 07:57:21.638402       1 predicates.go:829] Schedule Pod nxs-stage/cronjob-cron-events-1573793820-xt6q9 on Node nxs-k8s-s2 is allowed, Node is running only 21 out of 110 Pods.                                                                               
I1115 07:57:21.638383       1 predicates.go:829] Schedule Pod nxs-stage/cronjob-cron-events-1573793820-xt6q9 on Node nxs-k8s-s9 is allowed, Node is running only 16 out of 110 Pods.                                                                               
I1115 07:57:21.638335       1 predicates.go:829] Schedule Pod nxs-stage/cronjob-cron-events-1573793820-xt6q9 on Node nxs-k8s-s8 is allowed, Node is running only 18 out of 110 Pods.                                                                               
I1115 07:57:21.638408       1 predicates.go:829] Schedule Pod nxs-stage/cronjob-cron-events-1573793820-xt6q9 on Node nxs-k8s-s13 is allowed, Node is running only 8 out of 110 Pods.                                                                               
I1115 07:57:21.638478       1 predicates.go:1369] Schedule Pod nxs-stage/cronjob-cron-events-1573793820-xt6q9 on Node nxs-k8s-s10 is allowed, existing pods anti-affinity terms satisfied.                                                                         
I1115 07:57:21.638505       1 predicates.go:1369] Schedule Pod nxs-stage/cronjob-cron-events-1573793820-xt6q9 on Node nxs-k8s-s8 is allowed, existing pods anti-affinity terms satisfied.                                                                          
I1115 07:57:21.638577       1 predicates.go:1369] Schedule Pod nxs-stage/cronjob-cron-events-1573793820-xt6q9 on Node nxs-k8s-s9 is allowed, existing pods anti-affinity terms satisfied.                                                                          
I1115 07:57:21.638583       1 predicates.go:829] Schedule Pod nxs-stage/cronjob-cron-events-1573793820-xt6q9 on Node nxs-k8s-s7 is allowed, Node is running only 25 out of 110 Pods.                                                                               
I1115 07:57:21.638932       1 resource_allocation.go:78] cronjob-cron-events-1573793820-xt6q9 -> nxs-k8s-s10: BalancedResourceAllocation, capacity 39900 millicores 66620178432 memory bytes, total request 2343 millicores 9640186880 memory bytes, score 9        
I1115 07:57:21.638946       1 resource_allocation.go:78] cronjob-cron-events-1573793820-xt6q9 -> nxs-k8s-s10: LeastResourceAllocation, capacity 39900 millicores 66620178432 memory bytes, total request 2343 millicores 9640186880 memory bytes, score 8           
I1115 07:57:21.638961       1 resource_allocation.go:78] cronjob-cron-events-1573793820-xt6q9 -> nxs-k8s-s9: BalancedResourceAllocation, capacity 39900 millicores 66620170240 memory bytes, total request 4107 millicores 11307422720 memory bytes, score 9        
I1115 07:57:21.638971       1 resource_allocation.go:78] cronjob-cron-events-1573793820-xt6q9 -> nxs-k8s-s8: BalancedResourceAllocation, capacity 39900 millicores 66620178432 memory bytes, total request 5847 millicores 24333637120 memory bytes, score 7        
I1115 07:57:21.638975       1 resource_allocation.go:78] cronjob-cron-events-1573793820-xt6q9 -> nxs-k8s-s9: LeastResourceAllocation, capacity 39900 millicores 66620170240 memory bytes, total request 4107 millicores 11307422720 memory bytes, score 8           
I1115 07:57:21.638990       1 resource_allocation.go:78] cronjob-cron-events-1573793820-xt6q9 -> nxs-k8s-s8: LeastResourceAllocation, capacity 39900 millicores 66620178432 memory bytes, total request 5847 millicores 24333637120 memory bytes, score 7           
I1115 07:57:21.639022       1 generic_scheduler.go:726] cronjob-cron-events-1573793820-xt6q9_nxs-stage -> nxs-k8s-s10: TaintTolerationPriority, Score: (10)                                                                                                        
I1115 07:57:21.639030       1 generic_scheduler.go:726] cronjob-cron-events-1573793820-xt6q9_nxs-stage -> nxs-k8s-s8: TaintTolerationPriority, Score: (10)                                                                                                         
I1115 07:57:21.639034       1 generic_scheduler.go:726] cronjob-cron-events-1573793820-xt6q9_nxs-stage -> nxs-k8s-s9: TaintTolerationPriority, Score: (10)                                                                                                         
I1115 07:57:21.639041       1 generic_scheduler.go:726] cronjob-cron-events-1573793820-xt6q9_nxs-stage -> nxs-k8s-s10: NodeAffinityPriority, Score: (0)                                                                                                            
I1115 07:57:21.639053       1 generic_scheduler.go:726] cronjob-cron-events-1573793820-xt6q9_nxs-stage -> nxs-k8s-s8: NodeAffinityPriority, Score: (0)                                                                                                             
I1115 07:57:21.639059       1 generic_scheduler.go:726] cronjob-cron-events-1573793820-xt6q9_nxs-stage -> nxs-k8s-s9: NodeAffinityPriority, Score: (0)                                                                                                             
I1115 07:57:21.639061       1 interpod_affinity.go:237] cronjob-cron-events-1573793820-xt6q9 -> nxs-k8s-s10: InterPodAffinityPriority, Score: (0)                                                                                                                   
I1115 07:57:21.639063       1 selector_spreading.go:146] cronjob-cron-events-1573793820-xt6q9 -> nxs-k8s-s10: SelectorSpreadPriority, Score: (10)                                                                                                                   
I1115 07:57:21.639073       1 interpod_affinity.go:237] cronjob-cron-events-1573793820-xt6q9 -> nxs-k8s-s8: InterPodAffinityPriority, Score: (0)                                                                                                                    
I1115 07:57:21.639077       1 selector_spreading.go:146] cronjob-cron-events-1573793820-xt6q9 -> nxs-k8s-s8: SelectorSpreadPriority, Score: (10)                                                                                                                    
I1115 07:57:21.639085       1 interpod_affinity.go:237] cronjob-cron-events-1573793820-xt6q9 -> nxs-k8s-s9: InterPodAffinityPriority, Score: (0)                                                                                                                    
I1115 07:57:21.639088       1 selector_spreading.go:146] cronjob-cron-events-1573793820-xt6q9 -> nxs-k8s-s9: SelectorSpreadPriority, Score: (10)                                                                                                                    
I1115 07:57:21.639103       1 generic_scheduler.go:726] cronjob-cron-events-1573793820-xt6q9_nxs-stage -> nxs-k8s-s10: SelectorSpreadPriority, Score: (10)                                                                                                         
I1115 07:57:21.639109       1 generic_scheduler.go:726] cronjob-cron-events-1573793820-xt6q9_nxs-stage -> nxs-k8s-s8: SelectorSpreadPriority, Score: (10)                                                                                                          
I1115 07:57:21.639114       1 generic_scheduler.go:726] cronjob-cron-events-1573793820-xt6q9_nxs-stage -> nxs-k8s-s9: SelectorSpreadPriority, Score: (10)                                                                                                          
I1115 07:57:21.639127       1 generic_scheduler.go:781] Host nxs-k8s-s10 => Score 100037                                                                                                                                                                            
I1115 07:57:21.639150       1 generic_scheduler.go:781] Host nxs-k8s-s8 => Score 100034                                                                                                                                                                             
I1115 07:57:21.639154       1 generic_scheduler.go:781] Host nxs-k8s-s9 => Score 100037                                                                                                                                                                             
I1115 07:57:21.639267       1 scheduler_binder.go:269] AssumePodVolumes for pod "nxs-stage/cronjob-cron-events-1573793820-xt6q9", node "nxs-k8s-s10"                                                                                                               
I1115 07:57:21.639286       1 scheduler_binder.go:279] AssumePodVolumes for pod "nxs-stage/cronjob-cron-events-1573793820-xt6q9", node "nxs-k8s-s10": all PVCs bound and nothing to do                                                                             
I1115 07:57:21.639333       1 factory.go:733] Attempting to bind cronjob-cron-events-1573793820-xt6q9 to nxs-k8s-s10

Eto isika dia mahita fa amin'ny voalohany ny mpandrindra ny sivana ary mamorona lisitry ny node 3 azo atomboka (nxs-k8s-s8, nxs-k8s-s9, nxs-k8s-s10). Avy eo dia manisa isa mifototra amin'ny masontsivana maromaro (anisan'izany ny BalancedResourceAllocation, LeastResourceAllocation) ho an'ny tsirairay amin'ireo node ireo mba hamaritana ny node mety indrindra. Amin'ny farany, ny pod dia voalahatra eo amin'ny node manana isa ambony indrindra (eto nodes roa miaraka amin'ny isa mitovy isa 100037, noho izany dia voafantina kisendrasendra - nxs-k8s-s10).

famaranana: raha misy node mandeha pods izay tsy misy fameperana napetraka, dia ho an'ny k8s (avy amin'ny fomba fijerin'ny fanjifana loharanon-karena) dia mitovy amin'ny hoe tsy misy pods toy izany amin'ity node ity mihitsy. Noho izany, raha manana fepetra ianao dia manana pod miaraka amin'ny dingana tendan-kanina (ohatra, wowza) ary tsy misy fameperana napetraka amin'izany, dia mety hitranga ny toe-javatra rehefa tena nihinana ny loharanon'ny node ity pod ity, fa ho an'ny k8s ity node ity. dia heverina ho tsy misy entana ary homena isa mitovy amin'ny isa izy rehefa mametraka (amin'ny teboka manombantombana ny loharanon-karena misy) ho toy ny node tsy misy pods miasa, izay mety hitarika amin'ny fizarana tsy mitovy ny entana eo anelanelan'ny node.

Fandroahana ny Pod

Araka ny fantatrao, ny pod tsirairay dia nomena ny iray amin'ireo kilasy QoS 3:

  1. azo antoka - voatendry rehefa misy fangatahana sy fetra voafaritra ho an'ny fitadidiana sy cpu ho an'ny kaontenera tsirairay ao amin'ny pod, ary tsy maintsy mifanandrify ireo soatoavina ireo.
  2. mipoaka — fara fahakeliny kaontenera iray ao amin'ny pod dia manana fangatahana sy fetra, miaraka amin'ny fangatahana < fetra
  3. ny ezaka tsara indrindra - rehefa tsy misy kaontenera iray ao amin'ny pod dia voafetra ny loharanon-karena

Mandritra izany fotoana izany, rehefa mahatsapa ny tsy fahampian'ny loharanon-karena (kapila, fitadidiana) ny node iray, dia manomboka mametraka sy mandroaka pods ny kubelet araka ny algorithm manokana izay mandray ny laharam-pahamehan'ny pod sy ny kilasy QoS. Ohatra, raha miresaka momba ny RAM isika, dia mifototra amin'ny kilasy QoS, ny teboka dia omena araka ity fitsipika manaraka ity:

  • azo antoka: -998
  • BestEffort: 1000
  • Burstable: min(max(2, 1000 - (1000 * memoryRequestBytes) / machineMemoryCapacityBytes), 999)

Ireo. miaraka amin'ny laharam-pahamehana mitovy, ny kubelet dia handroaka ny pods miaraka amin'ny ezaka tsara indrindra amin'ny kilasy QoS avy amin'ny node.

famaranana: raha tianao ny hampihenana ny mety hisian'ny pod irina esorina amin'ny node raha toa ka tsy ampy ny loharanon-karena eo aminy, miaraka amin'ny laharam-pahamehana, dia mila mikarakara ny fametrahana ny fangatahana / fetra ho azy koa ianao.

Mekanisma ho an'ny fanodikodinam-peo horizinaly amin'ny pods fampiharana (HPA)

Rehefa ny asa dia ny hampitombo ho azy sy hampihenana ny isan'ny pods arakaraka ny fampiasana ny loharanon-karena (rafitra - CPU/RAM na mpampiasa - rps), toy ny k8s entity toy ny Ambovombe (Horizontal Pod Autoscaler). Ny algorithm amin'izany dia toy izao manaraka izao:

  1. Voafaritra (currentMetricValue) ny vakiteny amin'izao fotoana izao momba ny loharano hita
  2. Ny sanda irina ho an'ny loharanon-karena dia voafaritra (desiredMetricValue), izay ho an'ny loharanon'ny rafitra dia apetraka amin'ny alàlan'ny fangatahana
  3. Voafaritra ny isan'ny kopia ankehitriny (currentReplicas)
  4. Ity raikipohy manaraka ity dia manisa ny isan'ny dika mitovy (DesiredReplicas)
    desiredReplicas = [ currentReplicas * ( currentMetricValue / desiredMetricValue )]

Amin'ity tranga ity, dia tsy hitranga ny scaling rehefa manakaiky ny 1 ny coefficient (currentMetricValue / desiredMetricValue) (amin'ity tranga ity dia afaka mametraka ny fahadisoana azo atao isika; raha ny default dia 0.1).

Andeha hojerentsika ny fomba fiasan'ny hpa amin'ny fampiasana ny ohatry ny rindranasa fitsapana fampiharana (voasoritra ho Deployment), izay ilaina ny manova ny isan'ny kopia miankina amin'ny fanjifana CPU:

  • Fampiharana fampiharana

    kind: Deployment
    apiVersion: apps/v1beta2
    metadata:
    name: app-test
    spec:
    selector:
    matchLabels:
    app: app-test
    replicas: 2
    template:
    metadata:
    labels:
    app: app-test
    spec:
    containers:
    - name: nginx
    image: registry.nixys.ru/generic-images/nginx
    imagePullPolicy: Always
    resources:
    requests:
    cpu: 60m
    ports:
    - name: http
    containerPort: 80
    - name: nginx-exporter
    image: nginx/nginx-prometheus-exporter
    resources:
    requests:
    cpu: 30m
    ports:
    - name: nginx-exporter
    containerPort: 9113
    args:
    - -nginx.scrape-uri
    - http://127.0.0.1:80/nginx-status

    Ireo. Hitantsika fa ny pod fampiharana dia natomboka tamin'ny tranga roa, izay samy misy container roa nginx sy nginx-exporter, ho an'ny tsirairay amin'izy ireo dia voafaritra. fangatahana ho an'ny CPU.

  • HPA Manifesto

    apiVersion: autoscaling/v2beta2
    kind: HorizontalPodAutoscaler
    metadata:
    name: app-test-hpa
    spec:
    maxReplicas: 10
    minReplicas: 2
    scaleTargetRef:
    apiVersion: extensions/v1beta1
    kind: Deployment
    name: app-test
    metrics:
    - type: Resource
    resource:
    name: cpu
    target:
    type: Utilization
    averageUtilization: 30

    Ireo. Namorona hpa izahay izay hanara-maso ny app-test Deployment ary hanitsy ny isan'ny pods miaraka amin'ny fampiharana mifototra amin'ny famantarana cpu (manantena izahay fa ny pod dia tokony handany ny 30% amin'ny CPU angatahany), miaraka amin'ny isan'ny kopia ao anatiny. ny isan'ny 2-10.

    Andeha hojerentsika izao ny fomba fiasan'ny hpa raha mampihatra enta-mavesatra amin'ny iray amin'ireo fatana:

     # kubectl top pod
    NAME                                                   CPU(cores)   MEMORY(bytes)
    app-test-78559f8f44-pgs58            101m         243Mi
    app-test-78559f8f44-cj4jz            4m           240Mi

Amin'ny fitambarany dia manana ireto manaraka ireto isika:

  • Ny sanda ilaina (desiredMetricValue) - araka ny fikandrana hpa dia manana 30% isika
  • Sanda amin'izao fotoana izao (currentMetricValue) - ho an'ny kajy, ny mpitantana-manara-maso dia manao kajy ny sandan'ny fanjifana loharanon-karena amin'ny %, izany hoe. conditionally manao izao manaraka izao:
    1. Mahazo sanda tanteraka amin'ny metrika pod avy amin'ny mpizara metrika, i.e. 101m sy 4m
    2. Kajy ny sandan'ny absolute antonony, i.e. (101m + 4m) / 2 = 53m
    3. Mahazo ny sanda tanteraka ho an'ny fanjifana loharanon-karena irina (amin'izany dia fintinina ny fangatahan'ny kaontenera rehetra) 60m + 30m = 90m
    4. Kajy ny salan-jaton'ny fanjifana CPU mifandraika amin'ny pod fangatahana, izany hoe. 53m / 90m * 100% = 59%

Amin'izao fotoana izao dia manana ny zavatra rehetra ilaintsika isika mba hamaritana raha mila manova ny isan'ny replicas isika, mba hanaovana izany, kajy ny coefficient:

ratio = 59% / 30% = 1.96

Ireo. tokony hampitomboina ~2 heny ny isan'ny kopia ary ho [2 * 1.96] = 4.

famaranana: Araka ny hitanao, mba hahafahan'ity mekanika ity hiasa, ny fepetra ilaina dia ny fisian'ny fangatahana ho an'ny kaontenera rehetra ao amin'ny pod voamarika.

Mekanisma ho an'ny fanodikodinana marindrano ny nodes (Cluster Autoscaler)

Mba hialana amin'ny fiantraikany ratsy eo amin'ny rafitra mandritra ny fiakaran'ny entana dia tsy ampy ny fananana hpa namboarina. Ohatra, araka ny toe-javatra ao amin'ny hpa controller manager, dia manapa-kevitra fa ny isan'ny replicas dia mila ampitomboina in-2, fa ny node tsy manana loharano maimaim-poana mba hampandehanana ny isan'ny pods (izany hoe ny node tsy afaka manome ny nangataka loharanon-karena ho an'ny fangatahana pod) ary ireo pods ireo dia mifindra any amin'ny fanjakana miandry.

Amin'ity tranga ity, raha manana IaaS/PaaS mifanaraka amin'izany ny mpamatsy (ohatra, GKE/GCE, AKS, EKS, sns.), fitaovana toy ny Node Autoscaler. Izany dia ahafahanao mametraka ny isa ambony indrindra sy kely indrindra ao amin'ny cluster ary manitsy ho azy ny isan'ny nodes ankehitriny (amin'ny fiantsoana ny API mpamatsy rahona handidy / hanala node) rehefa tsy ampy ny loharanon-karena ao amin'ny cluster sy ny pods. tsy azo voalamina (eo amin'ny fanjakana miandry).

famaranana: Mba hahafahana manara-maso ny nodes dia ilaina ny mametraka fangatahana ao amin'ny kaontenera pod mba hahafahan'ny k8s manombatombana tsara ny enta-mavesatra eo amin'ny nodes ary araka izany dia mitatitra fa tsy misy loharanon-karena ao amin'ny cluster mba hanombohana ny pod manaraka.

famaranana

Marihina fa ny fametrahana ny fetran'ny loharanon-karena dia tsy fepetra takiana amin'ny fampiharana mba hahomby, fa mbola tsara kokoa ny manao izany noho ireto antony manaraka ireto:

  1. Ho an'ny fampandehanana marina kokoa ny fandaharam-potoana amin'ny resaka fifandanjana entana eo anelanelan'ny k8s nodes
  2. Mba hampihenana ny mety hisian'ny hetsika "fandroahana pod".
  3. Mba hiasa amin'ny alàlan'ny fanodikodinana autoscaling horita (HPA).
  4. Ho an'ny fanamafisam-peo marindrano ny nodes (Cluster Autoscaling) ho an'ny mpamatsy rahona

Vakio ihany koa lahatsoratra hafa ao amin'ny bilaoginay:

Source: www.habr.com

Add a comment