Skip to content

Commit 04e2b5f

Browse files
authored
Merge pull request #552 from mcshooter/detectKubeProxyServiceProblem
Add healthChecker functionality for kube-proxy service
2 parents 255c258 + 01cd8dd commit 04e2b5f

File tree

4 files changed

+60
-16
lines changed

4 files changed

+60
-16
lines changed

cmd/healthchecker/options/options.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ type HealthCheckerOptions struct {
4747
// AddFlags adds health checker command line options to pflag.
4848
func (hco *HealthCheckerOptions) AddFlags(fs *pflag.FlagSet) {
4949
fs.StringVar(&hco.Component, "component", types.KubeletComponent,
50-
"The component to check health for. Supports kubelet, docker and cri")
50+
"The component to check health for. Supports kubelet, docker, kube-proxy, and cri")
5151
// Deprecated: For backward compatibility on linux environment. Going forward "service" will be used instead of systemd-service
5252
if runtime.GOOS == "linux" {
5353
fs.MarkDeprecated("systemd-service", "please use --service flag instead")
@@ -73,8 +73,9 @@ func (hco *HealthCheckerOptions) AddFlags(fs *pflag.FlagSet) {
7373
// Returns error if invalid, nil otherwise.
7474
func (hco *HealthCheckerOptions) IsValid() error {
7575
// Make sure the component specified is valid.
76-
if hco.Component != types.KubeletComponent && hco.Component != types.DockerComponent && hco.Component != types.CRIComponent {
77-
return fmt.Errorf("the component specified is not supported. Supported components are : <kubelet/docker/cri>")
76+
if hco.Component != types.KubeletComponent && hco.Component != types.DockerComponent &&
77+
hco.Component != types.CRIComponent && hco.Component != types.KubeProxyComponent {
78+
return fmt.Errorf("the component specified is not supported. Supported components are : <kubelet/docker/cri/kube-proxy>")
7879
}
7980
// Make sure the service is specified if repair is enabled.
8081
if hco.EnableRepair && hco.Service == "" {
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"plugin": "custom",
3+
"pluginConfig": {
4+
"invoke_interval": "10s",
5+
"timeout": "3m",
6+
"max_output_length": 80,
7+
"concurrency": 1
8+
},
9+
"source": "health-checker",
10+
"metricsReporting": true,
11+
"conditions": [
12+
{
13+
"type": "KubeProxyUnhealthy",
14+
"reason": "KubeProxyIsHealthy",
15+
"message": "kube-proxy on the node is functioning properly"
16+
}
17+
],
18+
"rules": [
19+
{
20+
"type": "permanent",
21+
"condition": "KubeProxyUnhealthy",
22+
"reason": "KubeProxyUnhealthy",
23+
"path": "C:\\etc\\kubernetes\\node\\bin\\health-checker.exe",
24+
"args": [
25+
"--component=kube-proxy",
26+
"--enable-repair=true",
27+
"--cooldown-time=1m",
28+
"--health-check-timeout=10s"
29+
],
30+
"timeout": "3m"
31+
}
32+
]
33+
}
34+

pkg/healthchecker/health_checker_windows.go

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,9 @@ func getRepairFunc(hco *options.HealthCheckerOptions) func() {
6868
func getHealthCheckFunc(hco *options.HealthCheckerOptions) func() (bool, error) {
6969
switch hco.Component {
7070
case types.KubeletComponent:
71-
return func() (bool, error) {
72-
httpClient := http.Client{Timeout: hco.HealthCheckTimeout}
73-
response, err := httpClient.Get(types.KubeletHealthCheckEndpoint)
74-
if err != nil || response.StatusCode != http.StatusOK {
75-
return false, nil
76-
}
77-
return true, nil
78-
}
71+
return healthCheckEndpointOKFunc(types.KubeletHealthCheckEndpoint, hco.HealthCheckTimeout)
72+
case types.KubeProxyComponent:
73+
return healthCheckEndpointOKFunc(types.KubeProxyHealthCheckEndpoint, hco.HealthCheckTimeout)
7974
case types.DockerComponent:
8075
return func() (bool, error) {
8176
if _, err := execCommand("docker.exe", "ps"); err != nil {
@@ -94,6 +89,18 @@ func getHealthCheckFunc(hco *options.HealthCheckerOptions) func() (bool, error)
9489
return nil
9590
}
9691

92+
// healthCheckEndpointOKFunc returns a function to check the status of an http endpoint
93+
func healthCheckEndpointOKFunc(endpoint string, timeout time.Duration) func() (bool, error) {
94+
return func() (bool, error) {
95+
httpClient := http.Client{Timeout: timeout}
96+
response, err := httpClient.Get(endpoint)
97+
if err != nil || response.StatusCode != http.StatusOK {
98+
return false, nil
99+
}
100+
return true, nil
101+
}
102+
}
103+
97104
// execCommand creates a new process, executes the command, and returns the (output, error) from command.
98105
func execCommand(command string, args ...string) (string, error) {
99106
cmd := util.Exec(command, args...)

pkg/healthchecker/types/types.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,14 @@ const (
3030
CmdTimeout = 10 * time.Second
3131
LogParsingTimeLayout = "2006-01-02 15:04:05"
3232

33-
KubeletComponent = "kubelet"
34-
CRIComponent = "cri"
35-
DockerComponent = "docker"
36-
ContainerdService = "containerd"
33+
KubeletComponent = "kubelet"
34+
CRIComponent = "cri"
35+
DockerComponent = "docker"
36+
ContainerdService = "containerd"
37+
KubeProxyComponent = "kube-proxy"
3738

38-
KubeletHealthCheckEndpoint = "http://127.0.0.1:10248/healthz"
39+
KubeletHealthCheckEndpoint = "http://127.0.0.1:10248/healthz"
40+
KubeProxyHealthCheckEndpoint = "http://127.0.0.1:10256/healthz"
3941

4042
LogPatternFlagSeparator = ":"
4143
)

0 commit comments

Comments
 (0)