From 6ea02dc63fcda3ab59e182c1171fdf661b450cd1 Mon Sep 17 00:00:00 2001 From: Darren Foo Date: Sat, 26 Nov 2016 23:40:07 -0800 Subject: [PATCH] allow override of kubelet host with KUBERNETES_KUBELET_HOST env var - this addresses kubernetes environments where the kubelet api is not reachable at the default gateway - addresses projectcalico/calico-containers#1099 --- conf.d/kubernetes.yaml.example | 3 ++- utils/kubernetes/kubeutil.py | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/conf.d/kubernetes.yaml.example b/conf.d/kubernetes.yaml.example index e55c283d11..740a995de1 100644 --- a/conf.d/kubernetes.yaml.example +++ b/conf.d/kubernetes.yaml.example @@ -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: # diff --git a/utils/kubernetes/kubeutil.py b/utils/kubernetes/kubeutil.py index 08f9076ef3..ec34841a61 100644 --- a/utils/kubernetes/kubeutil.py +++ b/utils/kubernetes/kubeutil.py @@ -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)