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

Metrics "Sidecar" (scraping container) support #3504

Merged
merged 21 commits into from
Jun 17, 2019
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 8 additions & 40 deletions aio/deploy/recommended/kubernetes-dashboard-head.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,6 @@
# See the License for the specific language governing permissions and
jeefy marked this conversation as resolved.
Show resolved Hide resolved
# limitations under the License.

# ------------------- Dashboard Secrets ------------------- #

apiVersion: v1
kind: Secret
metadata:
labels:
k8s-app: kubernetes-dashboard-head
name: kubernetes-dashboard-certs
jeefy marked this conversation as resolved.
Show resolved Hide resolved
namespace: kube-system
type: Opaque

---

apiVersion: v1
kind: Secret
metadata:
labels:
k8s-app: kubernetes-dashboard-head
name: kubernetes-dashboard-csrf
namespace: kube-system
type: Opaque
data:
csrf: ""

---
# ------------------- Dashboard Service Account ------------------- #

apiVersion: v1
Expand All @@ -53,7 +28,7 @@ metadata:
kind: Role
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: kubernetes-dashboard-minimal-head
name: kubernetes-dashboard-minimal
namespace: kube-system
rules:
# Allow Dashboard to create 'kubernetes-dashboard-key-holder' secret.
Expand All @@ -67,7 +42,7 @@ rules:
# Allow Dashboard to get, update and delete Dashboard exclusive secrets.
- apiGroups: [""]
resources: ["secrets"]
resourceNames: ["kubernetes-dashboard-key-holder", "kubernetes-dashboard-certs", "kubernetes-dashboard-csrf"]
resourceNames: ["kubernetes-dashboard-key-holder"]
verbs: ["get", "update", "delete"]
# Allow Dashboard to get and update 'kubernetes-dashboard-settings' config map.
- apiGroups: [""]
Expand All @@ -87,12 +62,12 @@ rules:
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: kubernetes-dashboard-minimal-head
name: kubernetes-dashboard-minimal
namespace: kube-system
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: kubernetes-dashboard-minimal-head
name: kubernetes-dashboard-minimal
subjects:
- kind: ServiceAccount
name: kubernetes-dashboard-head
Expand Down Expand Up @@ -125,31 +100,24 @@ spec:
# Image is tagged and updated with :head, so always pull it.
imagePullPolicy: Always
ports:
- containerPort: 8443
- containerPort: 9090
protocol: TCP
args:
- --auto-generate-certificates
# Uncomment the following line to manually specify Kubernetes API server Host
# If not specified, Dashboard will attempt to auto discover the API server and connect
# to it. Uncomment only if the default does not work.
# - --apiserver-host=http://my-address:port
volumeMounts:
- name: kubernetes-dashboard-certs
mountPath: /certs
# Create on-disk volume to store exec logs
- mountPath: /tmp
name: tmp-volume
livenessProbe:
httpGet:
scheme: HTTPS
path: /
port: 8443
port: 9090
initialDelaySeconds: 30
timeoutSeconds: 30
volumes:
- name: kubernetes-dashboard-certs
secret:
secretName: kubernetes-dashboard-certs
- name: tmp-volume
emptyDir: {}
serviceAccountName: kubernetes-dashboard-head
Expand All @@ -170,7 +138,7 @@ metadata:
namespace: kube-system
spec:
ports:
- port: 443
targetPort: 8443
- port: 80
targetPort: 9090
selector:
k8s-app: kubernetes-dashboard-head
13 changes: 12 additions & 1 deletion aio/gulp/conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,24 @@ export default {
* dashboard defaults to INFO, publishing sanitized logs to STDOUT
*/
apiLogLevel: gulpUtil.env.apiLogLevel !== undefined ? gulpUtil.env.apiLogLevel : '',
/**
* Setting for metrics provider. Defaults to sidecar.
*/
metricsProvider: gulpUtil.env.metricsProvider !== undefined ? gulpUtil.env.metricsProvider : 'sidecar',
/**
* Address for the Heapster API server. If blank, the dashboard
* will attempt to connect to Heapster via a service proxy.
*/
heapsterServerHost: gulpUtil.env.heapsterServerHost !== undefined ?
gulpUtil.env.heapsterServerHost :
'',
'http://localhost:8001',
/**
* Address for the Sidecar API server. If blank, the dashboard
* will attempt to connect to Sidecar via a service proxy.
*/
sidecarServerHost: gulpUtil.env.sidecarServerHost !== undefined ?
gulpUtil.env.sidecarServerHost :
'http://localhost:8000',
/**
* File containing the default x509 Certificate for HTTPS.
*/
Expand Down
2 changes: 1 addition & 1 deletion aio/gulp/serve.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ let runningBackendProcess = null;
*/
function getBackendArgs() {
let args = [
`--heapster-host=${conf.backend.heapsterServerHost}`,
`--sidecar-host=${conf.backend.sidecarServerHost}`,
`--tls-cert-file=${conf.backend.tlsCert}`,
`--tls-key-file=${conf.backend.tlsKey}`,
`--auto-generate-certificates=${conf.backend.autoGenerateCerts}`,
Expand Down
12 changes: 12 additions & 0 deletions src/app/backend/args/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,24 @@ func (self *holderBuilder) SetApiServerHost(apiServerHost string) *holderBuilder
return self
}

// SetMetricsProvider 'metrics-provider' argument of Dashboard binary.
func (self *holderBuilder) SetMetricsProvider(metricsProvider string) *holderBuilder {
self.holder.metricsProvider = metricsProvider
return self
}

// SetHeapsterHost 'heapster-host' argument of Dashboard binary.
func (self *holderBuilder) SetHeapsterHost(heapsterHost string) *holderBuilder {
self.holder.heapsterHost = heapsterHost
return self
}

// SetSidecarHost 'sidecar-host' argument of Dashboard binary.
func (self *holderBuilder) SetSidecarHost(sidecarHost string) *holderBuilder {
self.holder.sidecarHost = sidecarHost
return self
}

// SetKubeConfigFile 'kubeconfig' argument of Dashboard binary.
func (self *holderBuilder) SetKubeConfigFile(kubeConfigFile string) *holderBuilder {
self.holder.kubeConfigFile = kubeConfigFile
Expand Down
12 changes: 12 additions & 0 deletions src/app/backend/args/holder.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ type holder struct {
certFile string
keyFile string
apiServerHost string
metricsProvider string
heapsterHost string
sidecarHost string
kubeConfigFile string
systemBanner string
systemBannerSeverity string
Expand Down Expand Up @@ -111,11 +113,21 @@ func (self *holder) GetApiServerHost() string {
return self.apiServerHost
}

// GetMetricsProvider 'metrics-provider' argument of Dashboard binary.
func (self *holder) GetMetricsProvider() string {
return self.metricsProvider
}

// GetHeapsterHost 'heapster-host' argument of Dashboard binary.
func (self *holder) GetHeapsterHost() string {
return self.heapsterHost
}

// GetSidecarHost 'sidecar-host' argument of Dashboard binary.
func (self *holder) GetSidecarHost() string {
return self.sidecarHost
}

// GetKubeConfigFile 'kubeconfig' argument of Dashboard binary.
func (self *holder) GetKubeConfigFile() string {
return self.kubeConfigFile
Expand Down
24 changes: 21 additions & 3 deletions src/app/backend/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,15 @@ var (
"to connect to in the format of protocol://address:port, e.g., "+
"http://localhost:8080. If not specified, the assumption is that the binary runs inside a "+
"Kubernetes cluster and local discovery is attempted.")
argHeapsterHost = pflag.String("heapster-host", "", "The address of the Heapster Apiserver "+
argMetricsProvider = pflag.String("metrics-provider", "sidecar", "Select provider type for metrics. Defaults to 'sidecar'")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't include the default in the help text, this is already printed by the help system:

      --metrics-provider string          Select provider type for metrics. Defaults to 'sidecar' (default "sidecar")

Consider instead listing the options: "sidecar" or "heapster".

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm picking this comment to say: You're awesome and I'm going to try to go through all these in the next couple days. Thanks so much!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will you change that?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I totally missed this, and I'll PR in a change this week.

argHeapsterHost = pflag.String("heapster-host", "", "The address of the Heapster Apiserver "+
"to connect to in the format of protocol://address:port, e.g., "+
"http://localhost:8082. If not specified, the assumption is that the binary runs inside a "+
"Kubernetes cluster and service proxy will be used.")
argSidecarHost = pflag.String("sidecar-host", "", "The address of the Sidecar Apiserver "+
"to connect to in the format of protocol://address:port, e.g., "+
"http://localhost:8000. If not specified, the assumption is that the binary runs inside a "+
"Kubernetes cluster and service proxy will be used.")
argKubeConfigFile = pflag.String("kubeconfig", "", "Path to kubeconfig file with authorization and master location information.")
argTokenTTL = pflag.Int("token-ttl", int(authApi.DefaultTokenTTL), "Expiration time (in seconds) of JWE tokens generated by dashboard. Default: 15 min. 0 - never expires")
argAuthenticationMode = pflag.StringSlice("authentication-mode", []string{authApi.Token.String()}, "Enables authentication options that will be reflected on login screen. Supported values: token, basic. Default: token."+
Expand Down Expand Up @@ -116,8 +121,19 @@ func main() {

// Init integrations
integrationManager := integration.NewIntegrationManager(clientManager)
integrationManager.Metric().ConfigureHeapster(args.Holder.GetHeapsterHost()).
EnableWithRetry(integrationapi.HeapsterIntegrationID, time.Duration(args.Holder.GetMetricClientCheckPeriod()))

fmt.Println("Hi dude")
jeefy marked this conversation as resolved.
Show resolved Hide resolved
fmt.Println(args.Holder.GetSidecarHost())
fmt.Println(args.Holder.GetHeapsterHost())

if args.Holder.GetMetricsProvider() == "sidecar" {
jeefy marked this conversation as resolved.
Show resolved Hide resolved
integrationManager.Metric().ConfigureSidecar(args.Holder.GetSidecarHost()).
EnableWithRetry(integrationapi.SidecarIntegrationID, time.Duration(args.Holder.GetMetricClientCheckPeriod()))
}
if args.Holder.GetMetricsProvider() == "heapster" {
integrationManager.Metric().ConfigureHeapster(args.Holder.GetHeapsterHost()).
EnableWithRetry(integrationapi.HeapsterIntegrationID, time.Duration(args.Holder.GetMetricClientCheckPeriod()))
}

apiHandler, err := handler.CreateHTTPAPIHandler(
integrationManager,
Expand Down Expand Up @@ -218,7 +234,9 @@ func initArgHolder() {
builder.SetCertFile(*argCertFile)
builder.SetKeyFile(*argKeyFile)
builder.SetApiServerHost(*argApiserverHost)
builder.SetMetricsProvider(*argMetricsProvider)
builder.SetHeapsterHost(*argHeapsterHost)
builder.SetSidecarHost(*argSidecarHost)
builder.SetKubeConfigFile(*argKubeConfigFile)
builder.SetSystemBanner(*argSystemBanner)
builder.SetSystemBannerSeverity(*argSystemBannerSeverity)
Expand Down
1 change: 1 addition & 0 deletions src/app/backend/integration/api/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type IntegrationID string
// Integration app IDs should be registered in this block.
const (
HeapsterIntegrationID IntegrationID = "heapster"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we plan to remove Heapster soon?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking that we'd have one or two releases that supported both Heapster and Metrics Server, then remove Heapster support entirely.

If consensus is to rip the bandaid off and remove Heapster support with this PR, I can do that pretty easily. Just let me know. :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@floreks WDYT?

Copy link
Member

@floreks floreks Apr 25, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd do as @jeefy suggests. Leave it for a couple of releases until heapster is completely removed.

SidecarIntegrationID IntegrationID = "sidecar"
)

// Integration represents application integrated into the dashboard. Every application
Expand Down
1 change: 1 addition & 0 deletions src/app/backend/integration/metric/heapster/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,5 +248,6 @@ func CreateHeapsterClient(host string, k8sClient kubernetes.Interface) (
}
log.Printf("Creating remote Heapster client for %s", host)
c := remoteHeapsterClient{client: restClient.CoreV1().RESTClient()}

return heapsterClient{client: c}, nil
}
18 changes: 17 additions & 1 deletion src/app/backend/integration/metric/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
integrationapi "github.com/kubernetes/dashboard/src/app/backend/integration/api"
metricapi "github.com/kubernetes/dashboard/src/app/backend/integration/metric/api"
"github.com/kubernetes/dashboard/src/app/backend/integration/metric/heapster"
"github.com/kubernetes/dashboard/src/app/backend/integration/metric/sidecar"
"k8s.io/apimachinery/pkg/util/wait"
)

Expand All @@ -40,7 +41,9 @@ type MetricManager interface {
EnableWithRetry(id integrationapi.IntegrationID, period time.Duration)
// List returns list of available metric related integrations.
List() []integrationapi.Integration
// ConfigureHeapster configures and adds heapster to clients list.
// ConfigureSidecar configures and adds sidecar to clients list.
ConfigureSidecar(host string) MetricManager
// ConfigureSidecar configures and adds sidecar to clients list.
jeefy marked this conversation as resolved.
Show resolved Hide resolved
jeefy marked this conversation as resolved.
Show resolved Hide resolved
ConfigureHeapster(host string) MetricManager
}

Expand Down Expand Up @@ -114,6 +117,19 @@ func (self *metricManager) List() []integrationapi.Integration {
return result
}

// ConfigureSidecar implements metric manager interface. See MetricManager for more information.
func (self *metricManager) ConfigureSidecar(host string) MetricManager {
kubeClient := self.manager.InsecureClient()
metricClient, err := sidecar.CreateSidecarClient(host, kubeClient)
if err != nil {
log.Printf("There was an error during sidecar client creation: %s", err.Error())
return self
}

self.clients[metricClient.ID()] = metricClient
return self
}

// ConfigureHeapster implements metric manager interface. See MetricManager for more information.
func (self *metricManager) ConfigureHeapster(host string) MetricManager {
kubeClient := self.manager.InsecureClient()
Expand Down
Loading