-
Notifications
You must be signed in to change notification settings - Fork 130
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
Support Web Interface #146
Comments
ProposalHow to build a web serverSample code: https://github.com/zheng1/kubeeye/tree/dev-web/web First we build a static file server for the front-end //go:embed dist/*
var assets embed.FS
func RunWebService(ctx context.Context) error {
subFS, _ := fs.Sub(assets, "dist")
assetsFs := http.FileServer(http.FS(subFS))
mux := http.NewServeMux()
mux.Handle("/", assetsFs)
return http.ListenAndServe(":8000", mux)
} Then we forward the API to the kube-apiserver type errorResponder struct{}
func (e *errorResponder) Error(w http.ResponseWriter, req *http.Request, err error) {
klog.Error(err)
responsewriters.InternalError(w, req, err)
}
func loadConfig() (*rest.Config, error) {
config, err := rest.InClusterConfig()
if err == nil {
return config, nil
}
return clientcmd.BuildConfigFromFlags("", os.Getenv("HOME")+"/.kube/config")
}
func RunWebService(ctx context.Context) error {
config, err := loadConfig()
if err != nil {
return err
}
kubernetes, _ := url.Parse(config.Host)
defaultTransport, err := rest.TransportFor(config)
if err != nil {
return err
}
var handleKubeAPIfunc = func(w http.ResponseWriter, req *http.Request) {
klog.Info(req.URL)
s := *req.URL
s.Host = kubernetes.Host
s.Scheme = kubernetes.Scheme
// make sure we don't override kubernetes's authorization
req.Header.Del("Authorization")
httpProxy := proxy.NewUpgradeAwareHandler(&s, defaultTransport, true, false, &errorResponder{})
httpProxy.UpgradeTransport = proxy.NewUpgradeRequestRoundTripper(defaultTransport, defaultTransport)
httpProxy.ServeHTTP(w, req)
return
}
mux := http.NewServeMux()
mux.HandleFunc("/apis/", handleKubeAPIfunc)
mux.HandleFunc("/api/", handleKubeAPIfunc)
return http.ListenAndServe(":8000", mux)
} In this way we only need to put the relative index.html and js and css files in the dist folder. https://parceljs.org/ is a blazing fast javascript packer! Lines 7 to 8 in ce7ddab
DevelopmentRun Here is just an example, we have listed all the namespaces in the cluster in the code. Lines 6 to 33 in ce7ddab
kubeeye/web/src/services/namespace.js Lines 3 to 8 in ce7ddab
In the following configuration, port 1234 will proxy k8s request to port 8000 Lines 2 to 7 in ce7ddab
ProductionRun |
What would you like to be added:
Provide a web interface that allows users to view results directly through a browser
Why is this needed:
The pure CLI view of the inspect results is not easy to visualize, it is easier to understand the visual results through the web page, and it can be increased for the inspection and solution of the results.
The text was updated successfully, but these errors were encountered: