内存分析

结构体定义

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
文件位置 pkg/kubelet/apis/stats/v1alpha1/types.go

// MemoryStats contains data about memory usage.
type MemoryStats struct {
	// The time at which these stats were updated.
	Time metav1.Time `json:"time"`
	// Available memory for use.  This is defined as the memory limit - workingSetBytes.
	// If memory limit is undefined, the available bytes is omitted.
	// +optional
	AvailableBytes *uint64 `json:"availableBytes,omitempty"`
	// Total memory in use. This includes all memory regardless of when it was accessed.
	// +optional
	UsageBytes *uint64 `json:"usageBytes,omitempty"`
	// The amount of working set memory. This includes recently accessed memory,
	// dirty memory, and kernel memory. WorkingSetBytes is <= UsageBytes
	// +optional
	WorkingSetBytes *uint64 `json:"workingSetBytes,omitempty"`
	// The amount of anonymous and swap cache memory (includes transparent
	// hugepages).
	// +optional
	RSSBytes *uint64 `json:"rssBytes,omitempty"`
	// Cumulative number of minor page faults.
	// +optional
	PageFaults *uint64 `json:"pageFaults,omitempty"`
	// Cumulative number of major page faults.
	// +optional
	MajorPageFaults *uint64 `json:"majorPageFaults,omitempty"`
}

AvailableBytes: 根据pod设定的limit所来,是limits减去workingSetBytes得来的值如果limits没有设置这个值会被忽略
UsageBytes: 所有使用的内存;
WorkingSetBytes: 最近访问的内存包括访问的内存脏内存内核内存WorkingSetBytes <= UsageBytes;
RSSBytes: 匿名内存swap内存

获取指标

1
2
3
# 每个节点访问取得信息
# 如果没有端口配置文件需要加载: KUBELET_EXTRA_ARGS="--read-only-port=10255"
curl 127.0.0.1:10255/stats/summary

Metrics-server

1
与kubectl top pod |grep pod_name相同取值是WorkingSetBytes

超限OOM

1
基于WorkingSetBytes的值OOM kill,UsageBytes到顶不涨但不会kill,直到WorkingSetBytes到达才会killer

pod内存使用率

1
2
3
4
如果设置了 AvailableBytes 设置了
(WorkingSetBytes/AvailableBytes+WorkingSetBytes)*100
否则
WorkingSetBytes / node内存