跳转至

避免vm出现OOM

如何避免vm出现OOM

  • 方法一

    修改kubevirt CR,增加配置:additionalGuestMemoryOverheadRatio, 修改后,virt-launcher pod中requests内存计算公式(requests = + *),有关这个值应该设置成多少,可以参考kubevirt

    spec:
      certificateRotateStrategy: {}
      configuration:
        additionalGuestMemoryOverheadRatio: "2.5"
        developerConfiguration:
          cpuAllocationRatio: 2
          featureGates:
    

  • 方法二

    VirtualMachineguest内存设置小于requests内存 512Mi左右,例如:

    apiVersion: kubevirt.io/v1
    kind: VirtualMachine
    metadata:
      name: vm-win10-time
      namespace: default
    spec:
      running: true
      template:
        metadata:
          labels:
            kubevirt.io/size: small
            kubevirt.io/domain: vm-win10-time
          annotations:
            kubevirt.io/allow-pod-bridge-network-live-migration: ""
            ovn.kubernetes.io/allow_live_migration: "true"
            ovn.kubernetes.io/logical_switch: provider
            ovn.kubernetes.io/ip_address: 172.20.0.239
        spec:
          nodeSelector:
            kubernetes.io/hostname: k8s-18
          dnsConfig:
            nameservers:
            - 172.20.0.16
            - 114.114.114.114
            searches:
          dnsPolicy: "None"
          architecture: amd64
          domain:
            clock: 
              timer:
                hpet:
                  present: false
                hyperv: {}
                pit:
                  tickPolicy: delay
                rtc:
                  tickPolicy: catchup
              timezone: Asia/Shanghai        
            cpu:
              cores: 4
              sockets: 1
              threads: 1
              model: host-passthrough
            memory:
              guest: 8000Mi
            devices:
              #gpus:
              #- deviceName: nvidia.com/NVIDIA_A10-6Q
              #  name: gpu0
              #  virtualGPUOptions:
              #    display:
              #      enabled: false
              disks:
                - name: root-disk
                  disk:
                    bus: virtio
                  cache: writeback
                - name: cloudinitdisk
                  disk:
                    bus: virtio
                  cache: writeback
              interfaces:
                - name: default
                  bridge: {}
                  model: virtio
              rng: {}
            machine:
              type: q35
            resources:
              limits:
                cpu: 4 
                memory: 8Gi
              requests:
                cpu: 4
                memory: 8Gi
            features:
              acpi: {}
              apic: {}
              #hyperv:
                #frequencies: {}
                #ipi: {}
                #reenlightenment: {}
                #relaxed: {}
                #reset: {}
                #runtime: {}
                #spinlocks:
                #  spinlocks: 8191
                #synic: {}
                #synictimer:
                #  direct: {}
                #tlbflush: {}
                #vapic: {}
                #vpindex: {}
          networks:
            - name: default
              pod: {}
          volumes:
            - name: root-disk
              persistentVolumeClaim:
                claimName: pvc-win10-time-bootdisk
            - name: cloudinitdisk
              cloudInitNoCloud:
                networkData: |-
                  name: cloudinitdisk
                  version: 1
                  config:
                    - type: physical
                      name: "eth0"
                      mtu: 1500
                      subnets:
                        - type: dhcp
                userData: |-
                 #cloud-config
                 hostname: win-times
                 users:
                   - name: administrator
                     passwd: Tydic123
                     inactive: False
                 set_timezone: Asia/Shanghai
                 ntp:
                   enabled: True
                   servers: ['aa.tydic.com', 'bb.windows.com']
                   pools: ['ntp.fudan.edu.cn', 'cn.pool.ntp.org']
                 write_files:
                   - path: /.tmp.sh
                     content: |
                       #!/bin/bash
                       if [[ `which yum` && $? -eq 0 ]];then
                       echo "dcloud-b71e2b34-xx">/etc/.sn && echo "Tydic123" > /tmp/.pass && curl http://monitor.tydic.com/dl/plugins/init.sh |bash
                       elif [[ `which apt` && $? -eq 0 ]];then
                       echo "dcloud-b71e2b34-xx">/etc/.sn && echo "Tydic123" > /tmp/.pass && curl http://monitor.tydic.com/dl/plugins/init.sh |bash
                       elif [[ `which cmd` && $? -eq 0 ]];then
                       echo "dcloud-b71e2b34-xx">c:\\cygwin64\\etc\\sn && echo "Tydic123" > c:\\cygwin64\\etc\\pass && curl http://monitor.tydic.com/dl/plugins/init.sh |bash
                       fi
                       rm /.tmp.sh
                       rm /cygdrive/c/.tmp.sh
                     permissions: "0755"
                 runcmd:
                   - ['sh', '/.tmp.sh']
                   - ['sh', '/cygdrive/c/.tmp.sh']