Skip to content
This repository has been archived by the owner on Apr 29, 2019. It is now read-only.

Support the Kubernetes Metrics Server #319

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
Binary file removed .swp
Binary file not shown.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,10 @@ Most aspects of your cluster setup can be customized with environment variables.

Defaults to `false`.

- **USE_METRICS_SERVER** defines whether to deploy or not the [Kubernetes Metrics Server](https://github.com/kubernetes-incubator/metrics-server)

Defaults to `false`.
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
Defaults to `false`.
Defaults to `true`.

This is required for the Horizontal Pod Autoscaler to work.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I would say agree because HPA is my motivation for adding this feature. The reason why I put it to false by default is that I haven't tested it in Windows nor RBAC (and I probably won't because I don't have this kind of setup).

Copy link
Owner

Choose a reason for hiding this comment

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

I'm sure @bmcstdio can help here, right Bruno?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Definitely. However, it seems to me that this PR needs some love. I checked out this branch and ran the following command:

$ NODES=1 USE_METRICS_SERVER=true vagrant up

Turns out the Kubernetes API can never be reachable:

$ kubectl get node
Unable to connect to the server: net/http: TLS handshake timeout

This does not happen in USE_METRICS_SERVER is set to false.

I also noticed high load on the system - far higher than usual. While I am not sure, part of what the root cause for this may be the fact that the following flag is not being defined:

--enable-aggregator-routing=true

https://kubernetes.io/docs/tasks/access-kubernetes-api/configure-aggregation-layer/#enable-apiserver-flags

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, definitely need more tests. I only tested it on macOS. Also, good catch on --enable-aggregator-routing=true.


- **AUTHORIZATION_MODE** setting this to `RBAC` enables RBAC for the kubernetes cluster.

Defaults to `AlwaysAllow`.
Expand Down
17 changes: 17 additions & 0 deletions Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ DNS_DOMAIN = ENV["DNS_DOMAIN"] || "cluster.local"
SERIAL_LOGGING = (ENV["SERIAL_LOGGING"].to_s.downcase == "true")
GUI = (ENV["GUI"].to_s.downcase == "true")
USE_KUBE_UI = (ENV["USE_KUBE_UI"].to_s.downcase == "true") || false
USE_METRICS_SERVER = (ENV["USE_METRICS_SERVER"].to_s.downcase == "true") || false

BOX_TIMEOUT_COUNT = (ENV["BOX_TIMEOUT_COUNT"] || 50).to_i

Expand Down Expand Up @@ -362,6 +363,18 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|

info "Kubernetes Dashboard will be available at http://#{MASTER_IP}:8080/ui/"
end

if USE_METRICS_SERVER
info "Configuring Kubernetes Metrics Server..."

if OS.windows?
run_remote "/opt/bin/kubectl apply -f /home/core/metrics-server/"
else
system "kubectl apply -f plugins/metrics-server/"
end

info "Kubernetes Metrics Server will be available at http://#{MASTER_IP}:8080/apis/metrics.k8s.io/"
end
end

# copy setup files to master vm if host is windows
Expand All @@ -377,6 +390,10 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
kHost.vm.provision :file, :source => File.join(File.dirname(__FILE__), "plugins/dashboard/dashboard-rbac.yaml"), :destination => "/home/core/dashboard-rbac.yaml"
kHost.vm.provision :file, :source => File.join(File.dirname(__FILE__), "plugins/dashboard/dashboard.yaml"), :destination => "/home/core/dashboard.yaml"
end

if USE_METRICS_SERVER
kHost.vm.provision :file, :source => File.join(File.dirname(__FILE__), "plugins/dashboard/metrics-server"), :destination => "/home/core/metrics-server"
end
end

# clean temp directory after master is destroyed
Expand Down
11 changes: 11 additions & 0 deletions env
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export NODES=3
export MASTER_MEM=2048
export MASTER_CPUS=2
export NODE_MEM=4096
export NODE_CPUS=3
export USE_KUBE_UI=true
export KUBERNETES_VERSION=1.12.1
export VAGRANT_USE_VAGRANT_TRIGGERS=false
export AUTHORIZATION_MODE=AlwaysAllow
# export AUTHORIZATION_MODE=RBAC
export USE_METRICS_SERVER=true
7 changes: 7 additions & 0 deletions manifests/master-apiserver-rbac.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ spec:
- --tls-private-key-file=/etc/kubernetes/ssl/apiserver-key.pem
- --client-ca-file=/etc/kubernetes/ssl/ca.pem
- --service-account-key-file=/etc/kubernetes/ssl/apiserver-key.pem
- --proxy-client-cert-file=/etc/kubernetes/ssl/apiserver.pem
- --proxy-client-key-file=/etc/kubernetes/ssl/apiserver-key.pem
- --requestheader-allowed-names=
- --requestheader-client-ca-file=/etc/kubernetes/ssl/ca.pem
- --requestheader-extra-headers-prefix=X-Remote-Extra-
- --requestheader-group-headers=X-Remote-Group
- --requestheader-username-headers=X-Remote-User
- --runtime-config=extensions/v1beta1=true,networking.k8s.io/v1,batch/v2alpha1=true,admissionregistration.k8s.io/v1alpha1=true
- --authorization-mode=RBAC
ports:
Expand Down
7 changes: 7 additions & 0 deletions manifests/master-apiserver.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ spec:
- --tls-private-key-file=/etc/kubernetes/ssl/apiserver-key.pem
- --client-ca-file=/etc/kubernetes/ssl/ca.pem
- --service-account-key-file=/etc/kubernetes/ssl/apiserver-key.pem
- --proxy-client-cert-file=/etc/kubernetes/ssl/apiserver.pem
- --proxy-client-key-file=/etc/kubernetes/ssl/apiserver-key.pem
- --requestheader-allowed-names=
- --requestheader-client-ca-file=/etc/kubernetes/ssl/ca.pem
- --requestheader-extra-headers-prefix=X-Remote-Extra-
- --requestheader-group-headers=X-Remote-Group
- --requestheader-username-headers=X-Remote-User
ports:
- containerPort: 443
hostPort: 443
Expand Down
12 changes: 12 additions & 0 deletions plugins/metrics-server/aggregated-metrics-reader.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: system:aggregated-metrics-reader
labels:
rbac.authorization.k8s.io/aggregate-to-view: "true"
rbac.authorization.k8s.io/aggregate-to-edit: "true"
rbac.authorization.k8s.io/aggregate-to-admin: "true"
rules:
- apiGroups: ["metrics.k8s.io"]
resources: ["pods"]
verbs: ["get", "list", "watch"]
13 changes: 13 additions & 0 deletions plugins/metrics-server/auth-delegator.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRoleBinding
metadata:
name: metrics-server:system:auth-delegator
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: system:auth-delegator
subjects:
- kind: ServiceAccount
name: metrics-server
namespace: kube-system
14 changes: 14 additions & 0 deletions plugins/metrics-server/auth-reader.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: RoleBinding
metadata:
name: metrics-server-auth-reader
namespace: kube-system
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: extension-apiserver-authentication-reader
subjects:
- kind: ServiceAccount
name: metrics-server
namespace: kube-system
14 changes: 14 additions & 0 deletions plugins/metrics-server/metrics-apiservice.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
apiVersion: apiregistration.k8s.io/v1beta1
kind: APIService
metadata:
name: v1beta1.metrics.k8s.io
spec:
service:
name: metrics-server
namespace: kube-system
group: metrics.k8s.io
version: v1beta1
insecureSkipTLSVerify: true
groupPriorityMinimum: 100
versionPriority: 100
37 changes: 37 additions & 0 deletions plugins/metrics-server/metrics-server-deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: metrics-server
namespace: kube-system
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: metrics-server
namespace: kube-system
labels:
k8s-app: metrics-server
spec:
selector:
matchLabels:
k8s-app: metrics-server
template:
metadata:
name: metrics-server
labels:
k8s-app: metrics-server
spec:
serviceAccountName: metrics-server
volumes:
# mount in tmp so we can safely use from-scratch images and/or read-only containers
- name: tmp-dir
emptyDir: {}
containers:
- name: metrics-server
image: k8s.gcr.io/metrics-server-amd64:v0.3.1
imagePullPolicy: Always
volumeMounts:
- name: tmp-dir
mountPath: /tmp

15 changes: 15 additions & 0 deletions plugins/metrics-server/metrics-server-service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
apiVersion: v1
kind: Service
metadata:
name: metrics-server
namespace: kube-system
labels:
kubernetes.io/name: "Metrics-server"
spec:
selector:
k8s-app: metrics-server
ports:
- port: 443
protocol: TCP
targetPort: 443
38 changes: 38 additions & 0 deletions plugins/metrics-server/resource-reader.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: system:metrics-server
rules:
- apiGroups:
- ""
resources:
- pods
- nodes
- nodes/stats
- namespaces
verbs:
- get
- list
- watch
- apiGroups:
- "extensions"
resources:
- deployments
verbs:
- get
- list
- watch
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: system:metrics-server
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: system:metrics-server
subjects:
- kind: ServiceAccount
name: metrics-server
namespace: kube-system