Kubernetes: vim li cas nws thiaj li tseem ceeb rau kev teeb tsa kev tswj hwm kev tswj hwm?

Raws li txoj cai, yeej ib txwm yuav tsum tau muab lub koom haum tshwj xeeb ntawm cov peev txheej rau daim ntawv thov rau nws txoj haujlwm raug thiab ruaj khov. Tab sis yuav ua li cas yog tias ntau daim ntawv thov khiav ntawm tib lub zog? Yuav ua li cas muab txhua tus ntawm lawv nrog yam tsawg kawg nkaus cov peev txheej tsim nyog? Koj tuaj yeem txwv kev siv cov peev txheej li cas? Yuav ua li cas kom raug faib cov load ntawm nodes? Yuav ua li cas kom ntseeg tau tias kab rov tav scaling mechanism ua haujlwm yog tias daim ntawv thov load nce?

Kubernetes: vim li cas nws thiaj li tseem ceeb rau kev teeb tsa kev tswj hwm kev tswj hwm?

Koj yuav tsum pib nrog yam tseem ceeb ntawm cov peev txheej muaj nyob hauv qhov system - qhov no, tau kawg, yog lub sijhawm processor thiab RAM. Nyob rau hauv k8s manifests cov hom kev pab no yog ntsuas nyob rau hauv cov nram qab no units:

  • CPU - hauv cores
  • RAM - nyob rau hauv bytes

Ntxiv mus, rau txhua qhov peev txheej nws tuaj yeem teeb tsa ob hom kev xav tau - thov ΠΈ txwv. Kev thov - piav qhia txog qhov tsawg kawg nkaus uas yuav tsum muaj rau cov peev txheej pub dawb ntawm lub node los khiav lub thawv (thiab cov pod tag nrho), thaum cov kev txwv teeb tsa ib qho nyuaj rau cov peev txheej muaj rau lub thawv.

Nws yog ib qho tseem ceeb kom nkag siab tias qhov tshwm sim tsis tas yuav qhia meej meej ob hom, tab sis tus cwj pwm yuav ua raws li hauv qab no:

  • Yog tias tsuas yog qhov txwv ntawm cov peev txheej tau teev meej meej, ces kev thov rau cov peev txheej no cia li siv tus nqi sib npaug (koj tuaj yeem txheeb xyuas qhov no los ntawm kev hu xov tooj piav qhia cov chaw). Cov. qhov tseeb, lub thawv yuav raug txwv rau tib yam khoom siv uas nws yuav tsum tau khiav.
  • Yog tias qhov kev thov tsuas yog qhia meej meej rau cov peev txheej, ces tsis muaj kev txwv sab saud ntawm cov peev txheej no - i.e. lub thawv tsuas yog txwv los ntawm cov peev txheej ntawm cov node nws tus kheej.

Nws kuj tseem tuaj yeem teeb tsa kev tswj hwm kev tswj hwm tsis yog nyob rau theem ntawm lub thawv tshwj xeeb, tab sis kuj tseem nyob ntawm qib namespace siv cov chaw hauv qab no:

  • LimitRange - piav qhia txog txoj cai txwv ntawm lub thawv / pods qib hauv ns thiab xav tau txhawm rau piav qhia txog qhov kev txwv tsis pub dhau ntawm lub thawv / pods, nrog rau kev tiv thaiv kev tsim cov thawv ntim / pods (lossis lwm qhov), txwv lawv tus lej thiab txiav txim siab qhov sib txawv ntawm qhov tseem ceeb hauv kev txwv thiab kev thov
  • ResourceQuotas - piav qhia txog txoj cai txwv feem ntau rau txhua lub ntim hauv ns thiab siv, raws li txoj cai, txwv tsis pub cov peev txheej ntawm ib puag ncig (muaj txiaj ntsig zoo thaum ib puag ncig tsis nruj me ntsis txwv ntawm qib ntawm node)

Cov hauv qab no yog cov piv txwv ntawm manifests uas teev cov peev txheej txwv:

  • Nyob rau theem tshwj xeeb ntim:

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

    Cov. Hauv qhov no, txhawm rau khiav lub thawv nrog nginx, koj yuav xav tau tsawg kawg 1G ntawm RAM dawb thiab 0.2 CPU ntawm lub pob, thaum feem ntau lub thawv tuaj yeem haus 0.2 CPU thiab tag nrho cov RAM muaj nyob ntawm node.

  • Hauv qib integer ns:

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

    Cov. cov sum ntawm tag nrho cov thov ntim hauv lub neej ntawd ns tsis tuaj yeem tshaj 300m rau CPU thiab 1G rau OP, thiab cov lej ntawm tag nrho cov txwv yog 700m rau CPU thiab 2G rau OP.

  • Default txwv rau ntim hauv 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

    Cov. nyob rau hauv lub default namespace rau tag nrho cov ntim, thov yuav teem rau 100m rau CPU thiab 1G rau OP, txwv - 1 CPU thiab 2G. Nyob rau tib lub sijhawm, kev txwv kuj tau teeb tsa ntawm qhov muaj peev xwm ua tau hauv kev thov / txwv rau CPU (50m < x < 2) thiab RAM (500M < x < 4G).

  • Pod-level txwv ns:

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

    Cov. rau txhua lub pod hauv lub neej ntawd ns yuav muaj qhov txwv ntawm 4 vCPU thiab 1G.

Tam sim no kuv xav qhia koj seb qhov zoo li cas teeb tsa cov kev txwv no tuaj yeem muab rau peb.

Load balancing mechanism ntawm nodes

Raws li koj paub, k8s tivthaiv yog lub luag haujlwm rau kev faib cov pods ntawm cov nodes, xws li tus teem sijhawm, uas ua haujlwm raws li qhov tshwj xeeb algorithm. Qhov algorithm no mus dhau ob theem thaum xaiv qhov zoo tshaj plaws los tso tawm:

  1. filtering
  2. Kev sib tw

Cov. raws li txoj cai tau piav qhia, cov nodes yog thawj zaug xaiv rau qhov uas nws muaj peev xwm tsim tau ib lub pod raws li lub teeb kwv yees (nrog rau kev tshuaj xyuas seb lub node puas muaj peev txheej txaus los khiav lub pod - PodFitsResources), thiab tom qab ntawd rau txhua qhov ntawm cov nodes, raws li tseem ceeb cov ntsiab lus tau txais txiaj ntsig (xws li, cov peev txheej pub dawb ntau dua qhov muaj, qhov ntau cov ntsiab lus nws tau muab - LeastResourceAllocation/LeastRequestedPriority/BalancedResourceAllocation) thiab cov pod yog launched rau ntawm node nrog cov ntsiab lus feem ntau (yog tias ob peb lub nodes txaus siab rau tus mob no ib zaug, ces xaiv ib qho random).

Nyob rau tib lub sijhawm, koj yuav tsum nkag siab tias lub sijhawm teem sijhawm, thaum ntsuas cov peev txheej muaj nyob ntawm lub node, yog coj los ntawm cov ntaub ntawv khaws cia hauv lwm yam - i.e. rau tus nqi ntawm qhov thov / txwv cov peev txheej ntawm txhua lub pod khiav ntawm node, tab sis tsis yog rau cov peev txheej siv tiag. Cov ntaub ntawv no tuaj yeem tau txais los ntawm cov lus txib tso tawm kubectl describe node $NODE, piv txwv:

# 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%)

Ntawm no peb pom tag nrho cov pods khiav ntawm ib qho ntawm qhov tshwj xeeb, nrog rau cov peev txheej uas txhua lub pods thov. Thiab ntawm no yog dab tsi lub sij hawm teem sij hawm zoo li thaum lub cronjob-cron-events-1573793820-xt6q9 pod yog launched (cov ntaub ntawv no yuav tshwm sim nyob rau hauv lub sij hawm teem sij hawm thaum 10th logging theem yog teem nyob rau hauv qhov kev sib cav ntawm lub launch command -v=10 ):

log

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

Ntawm no peb pom tias thaum pib lub sijhawm lim dej thiab tsim cov npe ntawm 3 ntawm qhov uas nws tuaj yeem tsim tawm (nxs-k8s-s8, nxs-k8s-s9, nxs-k8s-s10). Tom qab ntawd nws suav cov qhab nia raws li ntau qhov tsis muaj (xws li BalancedResourceAllocation, LeastResourceAllocation) rau txhua qhov ntawm cov nodes txhawm rau txiav txim siab qhov tsim nyog tshaj plaws. Thaum kawg, lub plhaub taum yog teem rau ntawm cov ntsiab lus siab tshaj plaws (ntawm no ob lub nodes ib zaug muaj tib tus lej ntawm cov ntsiab lus 100037, yog li ib qho random xaiv - nxs-k8s-s10).

xaus: Yog hais tias ib lub node sau cov pods uas tsis muaj kev txwv, ces rau k8s (los ntawm qhov pom ntawm kev siv peev txheej) qhov no yuav sib npaug li yog tias tsis muaj cov pods ntawm node txhua. Yog li ntawd, yog hais tias koj, conditionally, muaj ib tug pod nrog ib tug gluttonous txheej txheem (piv txwv li, wowza) thiab tsis muaj kev txwv rau nws, ces qhov teeb meem yuav tshwm sim thaum lub pod no tau noj tag nrho cov kev pab cuam ntawm lub node, tab sis rau k8s no node. yog suav tias yog unloaded thiab nws yuav tau muab tsub nqi tib yam ntawm cov ntsiab lus thaum ranking (ntxhais nyob rau hauv cov ntsiab lus ntsuam xyuas muaj peev xwm) raws li ib tug node uas tsis muaj ua hauj lwm pods, uas thaum kawg tuaj yeem ua rau tsis sib npaug ntawm cov load ntawm cov nodes.

Pod txoj kev ntiab tawm

Raws li koj paub, txhua lub pod yog muab ib qho ntawm 3 QoS chav kawm:

  1. lav - raug muab thaum rau txhua lub thawv hauv lub plhaub taum ib qhov kev thov thiab txwv tau teev tseg rau kev nco thiab cpu, thiab cov txiaj ntsig no yuav tsum sib phim
  2. tawg tau - yam tsawg kawg ib lub thawv hauv lub plhaub taum muaj kev thov thiab txwv, nrog kev thov < txwv
  3. ua kom zoo tshaj - thaum tsis muaj ib lub thawv rau hauv lub plhaub yog cov peev txheej txwv

Nyob rau tib lub sijhawm, thaum lub node ntsib qhov tsis muaj peev txheej (disk, nco), kubelet pib qeb duas thiab tshem tawm cov pods raws li cov txheej txheem tshwj xeeb uas siv rau hauv tus account qhov tseem ceeb ntawm cov pod thiab nws QoS chav kawm. Piv txwv li, yog tias peb tab tom tham txog RAM, tom qab ntawd raws li QoS chav kawm, cov ntsiab lus tau txais txiaj ntsig raws li cov hauv qab no:

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

Cov. nrog tib qhov tseem ceeb, kubelet yuav ua ntej tshem tawm cov pods nrog kev siv zog zoo tshaj plaws QoS chav kawm los ntawm cov node.

xaus: Yog tias koj xav kom txo qis qhov xav tau ntawm lub plhaub xav tau raug ntiab tawm ntawm lub pob hauv qhov xwm txheej tsis muaj peev txheej ntawm nws, ces nrog rau qhov tseem ceeb, koj kuj yuav tsum tau saib xyuas qhov kev thov / txwv rau nws.

Mechanism rau kab rov tav autoscaling ntawm daim ntawv thov pods (HPA)

Thaum lub luag haujlwm yog kom cia li nce thiab txo tus naj npawb ntawm cov pods nyob ntawm kev siv cov peev txheej (system - CPU / RAM lossis cov neeg siv - rps), xws li k8s qhov chaw xws li HPA ( Kab rov tav Pod Autoscaler ). Lub algorithm ntawm uas yog raws li nram no:

  1. Kev nyeem tam sim no ntawm cov peev txheej pom tau raug txiav txim siab (tam sim noMetricValue)
  2. Cov txiaj ntsig xav tau rau cov peev txheej tau txiav txim siab (xav tau MetricValue), uas rau cov peev txheej txheej txheem tau teeb tsa siv kev thov
  3. Tam sim no tus naj npawb ntawm replicas yog txiav txim siab (currentReplicas)
  4. Cov qauv hauv qab no suav cov lej xav tau ntawm cov khoom sib txawv (xav tauReplicas)
    xavReplicas = [currentReplicas * ( currentMetricValue / DesiredMetricValue )]

Nyob rau hauv cov ntaub ntawv no, scaling yuav tsis tshwm sim thaum lub coefficient (tam sim noMetricValue / DesiredMetricValue) yog ze rau 1 (nyob rau hauv cov ntaub ntawv no, peb yuav teem lub permissible yuam kev rau peb tus kheej; los ntawm lub neej ntawd nws yog 0.1).

Cia peb saib seb hpa ua haujlwm li cas siv cov piv txwv ntawm daim ntawv thov-kev xeem (piv txwv li Kev Tshaj Tawm), qhov twg nws yog qhov tsim nyog los hloov tus lej replicas nyob ntawm CPU noj:

  • Daim ntawv thov manifest

    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

    Cov. peb pom tias daim ntawv thov pod yog pib pib hauv ob qhov xwm txheej, txhua qhov muaj ob lub nginx thiab nginx-exporter ntim, rau txhua qhov uas tau teev tseg. thov rau 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

    Cov. Peb tsim ib qho hpa uas yuav saib xyuas qhov Kev Tshaj Tawm app-test thiab kho tus naj npawb ntawm cov pods nrog daim ntawv thov raws li qhov ntsuas cpu (peb cia siab tias lub plhaub taum yuav tsum haus 30% ntawm CPU nws thov), nrog rau cov xov tooj ntawm cov replicas nyob rau hauv qhov ntau ntawm 2-10.

    Tam sim no, cia peb saib cov txheej txheem ntawm kev ua haujlwm hpa yog tias peb siv lub nra rau ib qho ntawm lub hearths:

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

Hauv tag nrho peb muaj cov hauv qab no:

  • Tus nqi xav tau (xav tau MetricValue) - raws li hpa nqis, peb muaj 30%
  • Tus nqi tam sim no (tam sim noMetricValue) - rau kev suav, tus tswj hwm-tus tswj hwm suav cov nqi nruab nrab ntawm cov peev txheej siv hauv %, i.e. conditionally ua cov hauv qab no:
    1. Tau txais qhov tseem ceeb ntawm pod metrics los ntawm metric server, i.e. 101m 4 m
    2. Xam qhov nruab nrab tus nqi kiag li, i.e. (101m + 4m) / 2 = 53m
    3. Tau txais tus nqi tiag tiag rau cov khoom siv uas xav tau (rau qhov no, qhov kev thov ntawm tag nrho cov ntim tau suav nrog) 60m + 30m = 90m
    4. Xam qhov nruab nrab feem pua ​​​​ntawm CPU noj txheeb ze rau qhov thov pod, i.e. Luas = 53 m / 90 m * 100% = 59%

Tam sim no peb muaj txhua yam peb xav tau los txiav txim seb peb puas yuav tsum tau hloov tus lej replicas; ua qhov no, peb suav cov coefficient:

ratio = 59% / 30% = 1.96

Cov. tus naj npawb ntawm replicas yuav tsum tau nce los ntawm ~ 2 zaug thiab tus nqi rau [2 * 1.96] = 4.

Xaus: Raws li koj tuaj yeem pom, txhawm rau txhawm rau txhawm rau txhawm rau ua haujlwm, qhov xwm txheej tsim nyog yog qhov muaj kev thov rau tag nrho cov ntim hauv cov pods pom.

Mechanism rau kab rov tav autoscaling ntawm nodes (Cluster Autoscaler)

Txhawm rau kom tsis txhob cuam tshuam qhov tsis zoo ntawm lub kaw lus thaum lub sij hawm thauj khoom surges, muaj kev teeb tsa hpa tsis txaus. Piv txwv li, raws li kev teeb tsa hauv tus thawj tswj hwm hpa, nws txiav txim siab tias tus naj npawb ntawm cov replicas yuav tsum tau nce ntxiv 2 zaug, tab sis cov nodes tsis muaj kev pab dawb los khiav xws li ib tug xov tooj ntawm cov pods (piv txwv li lub node tsis tuaj yeem muab cov thov cov peev txheej rau cov ntaub ntawv thov) thiab cov pods no hloov mus rau Pending state.

Hauv qhov no, yog tias tus kws kho mob muaj IaaS/PaaS sib raug (piv txwv li, GKE/GCE, AKS, EKS, thiab lwm yam), cov cuab yeej xws li Node Autoscaler. Nws tso cai rau koj los teeb tsa qhov siab tshaj plaws thiab tsawg kawg ntawm cov nodes hauv pawg thiab hloov kho tus naj npawb tam sim no ntawm cov nodes (los ntawm kev hu xov tooj rau huab muab API kom xaj / tshem tawm ib qho) thaum tsis muaj peev txheej hauv pawg thiab cov pods. tsis tuaj yeem teem sijhawm (yog nyob rau hauv Pending state).

Xaus: Yuav kom muaj peev xwm autoscale nodes, nws yog ib qho tsim nyog yuav tsum tau teeb tsa kev thov hauv cov thawv ntim khoom kom k8s tuaj yeem txheeb xyuas qhov load ntawm cov nodes kom raug thiab ua raws li qhia tias tsis muaj cov peev txheej hauv pawg los tso cov pod tom ntej.

xaus

Nws yuav tsum raug sau tseg tias kev teeb tsa cov peev txheej txwv tsis yog qhov yuav tsum tau ua rau daim ntawv thov kom ua tiav, tab sis nws tseem zoo dua ua li ntawd rau cov laj thawj hauv qab no:

  1. Rau kev ua haujlwm raug ntau dua ntawm lub sijhawm teem sijhawm ntawm kev sib npaug ntawm k8s nodes
  2. Txhawm rau txo qhov yuav tshwm sim ntawm "pob kev tshem tawm" tshwm sim
  3. Rau kab rov tav autoscaling ntawm daim ntawv thov pods (HPA) ua haujlwm
  4. Rau kab rov tav autoscaling ntawm nodes (Cluster Autoscaling) rau huab muab

Kuj nyeem lwm cov ntawv hauv peb blog:

Tau qhov twg los: www.hab.com

Ntxiv ib saib