作者 | 阿文
责编 | 郭芮
出品 | CSDN(ID:CSDNnews)
   
   
     
    
    
      kubectl exec -it pod -n xxx /bin/bash
    
    
      
   
   
       
    Resident Set Size 
       (常驻内存大小)的缩写,用于表示进程使用了多少内存(RAM中的物理内存),RSS不包含已经被换出的内存。 
       RSS包含了它所链接的动态库并且被加载到物理内存中的内存。 
       RSS还包含栈内存和堆内存。 
      Virtual Memory Size 
       (虚拟内存大小)的缩写。 
       它包含了进程所能访问的所有内存,包含了被换出的内存,被分配但是还没有被使用的内存,以及动态库中的内存。 
         
   
     
    
    
      cat /proc/7/status
    
    
      
   
   
       
    kubectl top pod 
      查看 pod 的内存占用 确实发现该 pod 占用 17 G ,说明并不是容器内进程内存泄露导致的问题,那这就奇怪了,是什么原因导致占用这么多内存呢? 
       
   
     
    
    
      [root@8e3715641c31 /]# dd if=/dev/zero of=my_new_file count=1024000 bs=3024
    
    
      
    
    
      
    
    
      1024000+0 records in
    
    
      
    
    
      
    
    
      1024000+0 records out
    
    
      
    
    
      
    
    
      3096576000 bytes (3.1 GB, 2.9 GiB) copied, 28.7933 s, 108 MB/s
    
    
      
   
   
       
       
   
     
    
    
      [root@8e3715641c31 /]# free -h
    
    
      
    
    
      
    
    
                    total        used        free      shared  buff/cache   available
    
    
      
    
    
      Mem:          3.7Gi       281Mi       347Mi       193Mi       3.1Gi       3.0Gi
    
    
      
    
    
      Swap:            0B          0B          0B
    
    
      
   
   
       
       
   
     
    
    
      DESCRIPTION
    
    
      
    
    
             free displays the total amount of free and used physical and swap memory in the system, as well as the buffers and caches used by the kernel. The information is gathered by parsing /proc/meminfo. The displayed columns are:
    
    
      
    
    
      
    
    
             total  Total installed memory (MemTotal and SwapTotal in /proc/meminfo)
    
    
      
    
    
      
    
    
             used   Used memory (calculated as total - free - buffers - cache)
    
    
      
    
    
      
    
    
             free   Unused memory (MemFree and SwapFree in /proc/meminfo)
    
    
      
    
    
      
    
    
             shared Memory used (mostly) by tmpfs (Shmem in /proc/meminfo)
    
    
      
    
    
      
    
    
             buffers
    
    
      
    
    
                    Memory used by kernel buffers (Buffers in /proc/meminfo)
    
    
      
    
    
      
    
    
             cache  Memory used by the page cache and slabs (Cached and SReclaimable in /proc/meminfo)
    
    
      
    
    
      
    
    
             buff/cache
    
    
      
    
    
      
    
    
                    Sum of buffers and cache
    
    
      
    
    
      
    
    
      
    
    
             available
    
    
      
    
    
                    Estimation  of  how  much  memory  is  available  for  starting  new  applications, without swapping. Unlike the data provided by the cache or free fields, this field takes into account page cache and also that not all
    
    
      
    
    
                    reclaimable memory slabs will be reclaimed due to items being in use (MemAvailable in /proc/meminfo, available on kernels 3.14, emulated on kernels 2.6.27+, otherwise the same as free)
    
    
      
   
   
       
       
   
     
    
    
      kubectl logs -f pod-name -n namespace-name 
    
    
      
   
   
       
       
   
     
    
    
      sync; echo 3 > /proc/sys/vm/drop_caches //表示清空所有缓存(pagecache、dentries 和 inodes)
    
    
      
    
    
      
   
   
       
       
   
     
    
    
      sync; echo 1 > /proc/sys/vm/drop_caches      
    
    
      
   
   
       
       
   
     
    
    
      sync; echo 2 > /proc/sys/vm/drop_caches  
    
    
      
   
   
       
       
   
     
    
    
      resources:
    
    
      
    
    
            requests:
    
    
      
    
    
              cpu: "200m"
    
    
      
    
    
      
    
    
              memory: "128Mi"
    
    
      
    
    
      
    
    
            limits:
    
    
      
    
    
              cpu: "500m"
    
    
      
    
    
      
    
    
              memory: "512Mi"