mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 13:37:30 +00:00
move minGCAge to ImageGCPolicy and make it configurable
This commit is contained in:
parent
b1dedc0900
commit
641ba92aa3
@ -87,6 +87,7 @@ func NewKubeletServer() *KubeletServer {
|
|||||||
HostPIDSources: kubetypes.AllSource,
|
HostPIDSources: kubetypes.AllSource,
|
||||||
HostIPCSources: kubetypes.AllSource,
|
HostIPCSources: kubetypes.AllSource,
|
||||||
HTTPCheckFrequency: unversioned.Duration{20 * time.Second},
|
HTTPCheckFrequency: unversioned.Duration{20 * time.Second},
|
||||||
|
ImageMinimumGCAge: unversioned.Duration{2 * time.Minute},
|
||||||
ImageGCHighThresholdPercent: 90,
|
ImageGCHighThresholdPercent: 90,
|
||||||
ImageGCLowThresholdPercent: 80,
|
ImageGCLowThresholdPercent: 80,
|
||||||
LowDiskSpaceThresholdMB: 256,
|
LowDiskSpaceThresholdMB: 256,
|
||||||
@ -182,6 +183,7 @@ func (s *KubeletServer) AddFlags(fs *pflag.FlagSet) {
|
|||||||
fs.DurationVar(&s.NodeStatusUpdateFrequency.Duration, "node-status-update-frequency", s.NodeStatusUpdateFrequency.Duration, "Specifies how often kubelet posts node status to master. Note: be cautious when changing the constant, it must work with nodeMonitorGracePeriod in nodecontroller. Default: 10s")
|
fs.DurationVar(&s.NodeStatusUpdateFrequency.Duration, "node-status-update-frequency", s.NodeStatusUpdateFrequency.Duration, "Specifies how often kubelet posts node status to master. Note: be cautious when changing the constant, it must work with nodeMonitorGracePeriod in nodecontroller. Default: 10s")
|
||||||
bindableNodeLabels := util.ConfigurationMap(s.NodeLabels)
|
bindableNodeLabels := util.ConfigurationMap(s.NodeLabels)
|
||||||
fs.Var(&bindableNodeLabels, "node-labels", "<Warning: Alpha feature> Labels to add when registering the node in the cluster. Labels must are key=value pairs seperated by ','.")
|
fs.Var(&bindableNodeLabels, "node-labels", "<Warning: Alpha feature> Labels to add when registering the node in the cluster. Labels must are key=value pairs seperated by ','.")
|
||||||
|
fs.DurationVar(&s.ImageMinimumGCAge.Duration, "minimum-image-ttl-duration", s.ImageMinimumGCAge.Duration, "Minimum age for a unused image before it is garbage collected. Examples: '300ms', '10s' or '2h45m'. Default: '2m'")
|
||||||
fs.IntVar(&s.ImageGCHighThresholdPercent, "image-gc-high-threshold", s.ImageGCHighThresholdPercent, "The percent of disk usage after which image garbage collection is always run. Default: 90%")
|
fs.IntVar(&s.ImageGCHighThresholdPercent, "image-gc-high-threshold", s.ImageGCHighThresholdPercent, "The percent of disk usage after which image garbage collection is always run. Default: 90%")
|
||||||
fs.IntVar(&s.ImageGCLowThresholdPercent, "image-gc-low-threshold", s.ImageGCLowThresholdPercent, "The percent of disk usage before which image garbage collection is never run. Lowest disk usage to garbage collect to. Default: 80%")
|
fs.IntVar(&s.ImageGCLowThresholdPercent, "image-gc-low-threshold", s.ImageGCLowThresholdPercent, "The percent of disk usage before which image garbage collection is never run. Lowest disk usage to garbage collect to. Default: 80%")
|
||||||
fs.IntVar(&s.LowDiskSpaceThresholdMB, "low-diskspace-threshold-mb", s.LowDiskSpaceThresholdMB, "The absolute free disk space, in MB, to maintain. When disk space falls below this threshold, new pods would be rejected. Default: 256")
|
fs.IntVar(&s.LowDiskSpaceThresholdMB, "low-diskspace-threshold-mb", s.LowDiskSpaceThresholdMB, "The absolute free disk space, in MB, to maintain. When disk space falls below this threshold, new pods would be rejected. Default: 256")
|
||||||
|
@ -154,6 +154,7 @@ func UnsecuredKubeletConfig(s *options.KubeletServer) (*KubeletConfig, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
imageGCPolicy := kubelet.ImageGCPolicy{
|
imageGCPolicy := kubelet.ImageGCPolicy{
|
||||||
|
MinAge: s.ImageMinimumGCAge.Duration,
|
||||||
HighThresholdPercent: s.ImageGCHighThresholdPercent,
|
HighThresholdPercent: s.ImageGCHighThresholdPercent,
|
||||||
LowThresholdPercent: s.ImageGCLowThresholdPercent,
|
LowThresholdPercent: s.ImageGCLowThresholdPercent,
|
||||||
}
|
}
|
||||||
|
@ -116,6 +116,7 @@ kubelet
|
|||||||
--maximum-dead-containers=100: Maximum number of old instances of containers to retain globally. Each container takes up some disk space. Default: 100.
|
--maximum-dead-containers=100: Maximum number of old instances of containers to retain globally. Each container takes up some disk space. Default: 100.
|
||||||
--maximum-dead-containers-per-container=2: Maximum number of old instances to retain per container. Each container takes up some disk space. Default: 2.
|
--maximum-dead-containers-per-container=2: Maximum number of old instances to retain per container. Each container takes up some disk space. Default: 2.
|
||||||
--minimum-container-ttl-duration=1m0s: Minimum age for a finished container before it is garbage collected. Examples: '300ms', '10s' or '2h45m'
|
--minimum-container-ttl-duration=1m0s: Minimum age for a finished container before it is garbage collected. Examples: '300ms', '10s' or '2h45m'
|
||||||
|
--minimum-image-ttl-duration=2m0s: Minimum age for a unused image before it is garbage collected. Examples: '300ms', '10s' or '2h45m'. Default: '2m'
|
||||||
--network-plugin="": <Warning: Alpha feature> The name of the network plugin to be invoked for various events in kubelet/pod lifecycle
|
--network-plugin="": <Warning: Alpha feature> The name of the network plugin to be invoked for various events in kubelet/pod lifecycle
|
||||||
--network-plugin-dir="/usr/libexec/kubernetes/kubelet-plugins/net/exec/": <Warning: Alpha feature> The full path of the directory in which to search for network plugins
|
--network-plugin-dir="/usr/libexec/kubernetes/kubelet-plugins/net/exec/": <Warning: Alpha feature> The full path of the directory in which to search for network plugins
|
||||||
--node-ip="": IP address of the node. If set, kubelet will use this IP address for the node
|
--node-ip="": IP address of the node. If set, kubelet will use this IP address for the node
|
||||||
@ -151,7 +152,7 @@ kubelet
|
|||||||
--volume-stats-agg-period=1m0s: Specifies interval for kubelet to calculate and cache the volume disk usage for all pods and volumes. To disable volume calculations, set to 0. Default: '1m'
|
--volume-stats-agg-period=1m0s: Specifies interval for kubelet to calculate and cache the volume disk usage for all pods and volumes. To disable volume calculations, set to 0. Default: '1m'
|
||||||
```
|
```
|
||||||
|
|
||||||
###### Auto generated by spf13/cobra on 12-Feb-2016
|
###### Auto generated by spf13/cobra on 15-Feb-2016
|
||||||
|
|
||||||
|
|
||||||
<!-- BEGIN MUNGE: GENERATED_ANALYTICS -->
|
<!-- BEGIN MUNGE: GENERATED_ANALYTICS -->
|
||||||
|
@ -229,6 +229,7 @@ min-pr-number
|
|||||||
min-request-timeout
|
min-request-timeout
|
||||||
min-resync-period
|
min-resync-period
|
||||||
minimum-container-ttl-duration
|
minimum-container-ttl-duration
|
||||||
|
minimum-image-ttl-duration
|
||||||
minion-max-log-age
|
minion-max-log-age
|
||||||
minion-max-log-backups
|
minion-max-log-backups
|
||||||
minion-max-log-size
|
minion-max-log-size
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -197,6 +197,9 @@ type KubeletConfiguration struct {
|
|||||||
// status to master. Note: be cautious when changing the constant, it
|
// status to master. Note: be cautious when changing the constant, it
|
||||||
// must work with nodeMonitorGracePeriod in nodecontroller.
|
// must work with nodeMonitorGracePeriod in nodecontroller.
|
||||||
NodeStatusUpdateFrequency unversioned.Duration `json:"nodeStatusUpdateFrequency"`
|
NodeStatusUpdateFrequency unversioned.Duration `json:"nodeStatusUpdateFrequency"`
|
||||||
|
// minimumGCAge is the minimum age for a unused image before it is
|
||||||
|
// garbage collected.
|
||||||
|
ImageMinimumGCAge unversioned.Duration `json:"imageMinimumGCAge"`
|
||||||
// imageGCHighThresholdPercent is the percent of disk usage after which
|
// imageGCHighThresholdPercent is the percent of disk usage after which
|
||||||
// image garbage collection is always run.
|
// image garbage collection is always run.
|
||||||
ImageGCHighThresholdPercent int `json:"imageGCHighThresholdPercent"`
|
ImageGCHighThresholdPercent int `json:"imageGCHighThresholdPercent"`
|
||||||
|
@ -32,10 +32,6 @@ import (
|
|||||||
"k8s.io/kubernetes/pkg/util/wait"
|
"k8s.io/kubernetes/pkg/util/wait"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
|
||||||
defaultGCAge = time.Minute * 1
|
|
||||||
)
|
|
||||||
|
|
||||||
// Manages lifecycle of all images.
|
// Manages lifecycle of all images.
|
||||||
//
|
//
|
||||||
// Implementation is thread-safe.
|
// Implementation is thread-safe.
|
||||||
@ -62,6 +58,9 @@ type ImageGCPolicy struct {
|
|||||||
// Any usage below this threshold will never trigger garbage collection.
|
// Any usage below this threshold will never trigger garbage collection.
|
||||||
// This is the lowest threshold we will try to garbage collect to.
|
// This is the lowest threshold we will try to garbage collect to.
|
||||||
LowThresholdPercent int
|
LowThresholdPercent int
|
||||||
|
|
||||||
|
// Minimum age at which a image can be garbage collected.
|
||||||
|
MinAge time.Duration
|
||||||
}
|
}
|
||||||
|
|
||||||
type realImageManager struct {
|
type realImageManager struct {
|
||||||
@ -75,10 +74,6 @@ type realImageManager struct {
|
|||||||
// The image garbage collection policy in use.
|
// The image garbage collection policy in use.
|
||||||
policy ImageGCPolicy
|
policy ImageGCPolicy
|
||||||
|
|
||||||
// Minimum age at which a image can be garbage collected, zero for no limit.
|
|
||||||
// TODO(mqliang): move it to ImageGCPolicy and make it configurable
|
|
||||||
minAge time.Duration
|
|
||||||
|
|
||||||
// cAdvisor instance.
|
// cAdvisor instance.
|
||||||
cadvisor cadvisor.Interface
|
cadvisor cadvisor.Interface
|
||||||
|
|
||||||
@ -118,7 +113,6 @@ func newImageManager(runtime container.Runtime, cadvisorInterface cadvisor.Inter
|
|||||||
im := &realImageManager{
|
im := &realImageManager{
|
||||||
runtime: runtime,
|
runtime: runtime,
|
||||||
policy: policy,
|
policy: policy,
|
||||||
minAge: defaultGCAge,
|
|
||||||
imageRecords: make(map[string]*imageRecord),
|
imageRecords: make(map[string]*imageRecord),
|
||||||
cadvisor: cadvisorInterface,
|
cadvisor: cadvisorInterface,
|
||||||
recorder: recorder,
|
recorder: recorder,
|
||||||
@ -279,7 +273,8 @@ func (im *realImageManager) freeSpace(bytesToFree int64, freeTime time.Time) (in
|
|||||||
|
|
||||||
// Avoid garbage collect the image if the image is not old enough.
|
// Avoid garbage collect the image if the image is not old enough.
|
||||||
// In such a case, the image may have just been pulled down, and will be used by a container right away.
|
// In such a case, the image may have just been pulled down, and will be used by a container right away.
|
||||||
if freeTime.Sub(image.firstDetected) < im.minAge {
|
|
||||||
|
if freeTime.Sub(image.firstDetected) < im.policy.MinAge {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,7 +38,6 @@ func newRealImageManager(policy ImageGCPolicy) (*realImageManager, *container.Fa
|
|||||||
return &realImageManager{
|
return &realImageManager{
|
||||||
runtime: fakeRuntime,
|
runtime: fakeRuntime,
|
||||||
policy: policy,
|
policy: policy,
|
||||||
minAge: 0,
|
|
||||||
imageRecords: make(map[string]*imageRecord),
|
imageRecords: make(map[string]*imageRecord),
|
||||||
cadvisor: mockCadvisor,
|
cadvisor: mockCadvisor,
|
||||||
recorder: &record.FakeRecorder{},
|
recorder: &record.FakeRecorder{},
|
||||||
@ -406,13 +405,13 @@ func TestGarbageCollectImageNotOldEnough(t *testing.T) {
|
|||||||
policy := ImageGCPolicy{
|
policy := ImageGCPolicy{
|
||||||
HighThresholdPercent: 90,
|
HighThresholdPercent: 90,
|
||||||
LowThresholdPercent: 80,
|
LowThresholdPercent: 80,
|
||||||
|
MinAge: time.Minute * 1,
|
||||||
}
|
}
|
||||||
fakeRuntime := &container.FakeRuntime{}
|
fakeRuntime := &container.FakeRuntime{}
|
||||||
mockCadvisor := new(cadvisor.Mock)
|
mockCadvisor := new(cadvisor.Mock)
|
||||||
manager := &realImageManager{
|
manager := &realImageManager{
|
||||||
runtime: fakeRuntime,
|
runtime: fakeRuntime,
|
||||||
policy: policy,
|
policy: policy,
|
||||||
minAge: defaultGCAge,
|
|
||||||
imageRecords: make(map[string]*imageRecord),
|
imageRecords: make(map[string]*imageRecord),
|
||||||
cadvisor: mockCadvisor,
|
cadvisor: mockCadvisor,
|
||||||
recorder: &record.FakeRecorder{},
|
recorder: &record.FakeRecorder{},
|
||||||
@ -443,7 +442,7 @@ func TestGarbageCollectImageNotOldEnough(t *testing.T) {
|
|||||||
assert.Len(fakeRuntime.ImageList, 2)
|
assert.Len(fakeRuntime.ImageList, 2)
|
||||||
|
|
||||||
// move clock by minAge duration, then 1 image will be garbage collected
|
// move clock by minAge duration, then 1 image will be garbage collected
|
||||||
fakeClock.Step(manager.minAge)
|
fakeClock.Step(policy.MinAge)
|
||||||
spaceFreed, err = manager.freeSpace(1024, fakeClock.Now())
|
spaceFreed, err = manager.freeSpace(1024, fakeClock.Now())
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.EqualValues(1024, spaceFreed)
|
assert.EqualValues(1024, spaceFreed)
|
||||||
|
Loading…
Reference in New Issue
Block a user