setting the k8s cluster to use the hostname/IP address instead of localhost

5/10/2016

I just installed k8s cluster but the URLs are all using localhost and would like to change it to use the hostname or even IP address. Due to this the cluster can be accessed only from the master node. I am unable to find the right place to make this change. Any help is really appreciated.

OS: Redhat 7.1
Kubernetes version: 1.2

[rakeshk@ kubernetes]$ kubectl cluster-info
Kubernetes master is running at http://localhost:8080
Elasticsearch is running at http://localhost:8080/api/v1/proxy/namespaces/kube-system/services/elasticsearch-logging
Heapster is running at http://localhost:8080/api/v1/proxy/namespaces/kube-system/services/heapster
Kibana is running at http://localhost:8080/api/v1/proxy/namespaces/kube-system/services/kibana-logging
KubeDNS is running at http://localhost:8080/api/v1/proxy/namespaces/kube-system/services/kube-dns
kubedash is running at http://localhost:8080/api/v1/proxy/namespaces/kube-system/services/kubedash
kubernetes-dashboard is running at http://localhost:8080/api/v1/proxy/namespaces/kube-system/services/kubernetes-dashboard
Grafana is running at http://localhost:8080/api/v1/proxy/namespaces/kube-system/services/monitoring-grafana
InfluxDB is running at http://localhost:8080/api/v1/proxy/namespaces/kube-system/services/monitoring-influxdb
-- rks
kubernetes

1 Answer

12/16/2016

Based on the port number (8080, which is the default value of --insecure-port of kube-apiserver), I am guessing that you are running the kubectl cluster-info command on the same machine where the kube-apiserver is running.

If the above assumption is correct, then copy the /etc/kubernetes/admin.conf file (from the machine thats running the kube-apiserver) to your local machine ~/.kube/config. Run kubectl cluster-info on your local machine (install kubectl program on your local machine, if you haven't already). This should give you cluster address as either a hostname or IP address. Whether it shows it as an IP address or a hostname depends on whether a reverse lookup of the IP address resolves a DNS record.

If you are initialising kubernetes using kubeadm program. kubeadm init will autodetect the network interface to advertise the master on as the interface with the default gateway. If default gateway IP address is not routable IP address, ensure that you set --api-advertise-addresses to a routable IP address.

-- Gajus
Source: StackOverflow