Skip to content

Commit

Permalink
Merge pull request #3051 from stonith/allow_specify_kubelet_host
Browse files Browse the repository at this point in the history
allow override of kubelet host with KUBERNETES_KUBELET_HOST env var
  • Loading branch information
hkaj authored Dec 5, 2016
2 parents da02e5f + 6ea02dc commit 8b0932f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
3 changes: 2 additions & 1 deletion conf.d/kubernetes.yaml.example
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ init_config:
instances:
# The kubernetes check retrieves metrics from cadvisor running under kubelet.
# By default we will assume we're running under docker and will use the address
# of the default router to reach the cadvisor api.
# of the default router to reach the cadvisor api unless the environment variable
# KUBERNETES_KUBELET_HOST is found.
#
# To override, e.g. in the case of a standalone cadvisor instance, use the following:
#
Expand Down
5 changes: 3 additions & 2 deletions utils/kubernetes/kubeutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,15 @@ def __init__(self, instance=None):

self.method = instance.get('method', KubeUtil.DEFAULT_METHOD)
self.host = instance.get("host") or self.docker_util.get_hostname()
self.kubelet_host = os.environ.get('KUBERNETES_KUBELET_HOST') or self.host
self._node_ip = self._node_name = None # lazy evaluation
self.host_name = os.environ.get('HOSTNAME')

self.cadvisor_port = instance.get('port', KubeUtil.DEFAULT_CADVISOR_PORT)
self.kubelet_port = instance.get('kubelet_port', KubeUtil.DEFAULT_KUBELET_PORT)

self.kubelet_api_url = '%s://%s:%d' % (self.method, self.host, self.kubelet_port)
self.cadvisor_url = '%s://%s:%d' % (self.method, self.host, self.cadvisor_port)
self.kubelet_api_url = '%s://%s:%d' % (self.method, self.kubelet_host, self.kubelet_port)
self.cadvisor_url = '%s://%s:%d' % (self.method, self.kubelet_host, self.cadvisor_port)
self.kubernetes_api_url = 'https://%s/api/v1' % (os.environ.get('KUBERNETES_SERVICE_HOST') or self.DEFAULT_MASTER_NAME)

self.metrics_url = urljoin(self.cadvisor_url, KubeUtil.METRICS_PATH)
Expand Down

0 comments on commit 8b0932f

Please sign in to comment.