Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use a cheaper way to ping the Kubernetes API in the health check endpoint #180

Open
arschles opened this issue Feb 12, 2016 · 3 comments
Open

Comments

@arschles
Copy link
Member

After #149, the health check server (/healthz) will be listing all namespaces in the cluster as a way to ping the Kubernetes API to determine whether it's available. This method of checking availability is more heavyweight than it has to be, since the API server should also have a healthz endpoint. Some code similar to the following should be used to check that endpoint:

// kubeClient is a *(k8s.io/kubernetes/pkg/client/unversioned).Client
res := kubeClient.Get().AbsPath("/healthz").Do()
if res.Error() != nil{
  // not possible to reach the server
}

This idea was first proposed by @aledbf in https://github.com/deis/builder/pull/149/files#r52692363

@aledbf
Copy link
Contributor

aledbf commented Feb 12, 2016

@arschles this is a working version of the check

apiUrl := kubeClient.Get().AbsPath("/healthz").URL()
err := checkApiServer(apiUrl.String(), time.Duration(1*time.Second))
if err != nil {
  // something
}
// checkApiServer checks if is possible to reach the api server or not
func checkApiServer(url string, timeout time.Duration) error {
    // we don't know if the 
    client := http.Client{
        Timeout: timeout,
        Transport: &http.Transport{
            TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
        },
    }

    res, err := client.Get(url)
    if err != nil {
        return err
    }
    res.Body.Close()
    return nil
}

@arschles
Copy link
Member Author

thanks @aledbf

@Cryptophobia
Copy link

This issue was moved to teamhephy/builder#35

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants