ccd
ccd

Reputation: 6948

How to find cluster node ip address

Minikube has the specific node ip address (192.168.99.100) for single cluster, if I using kubeadm to create many nodes cluster, what should I do to find this ip address?

Upvotes: 16

Views: 60662

Answers (7)

Aidar Gatin
Aidar Gatin

Reputation: 843

Use Json Output

kubectl get node node-name -o json --output='jsonpath={.status.addresses[0].address}'

Upvotes: 0

user21028463
user21028463

Reputation:

Simplest ways is

kubectl get nodes -o wide 

Upvotes: 0

Hasni Mehdi
Hasni Mehdi

Reputation: 656

This command display the nodes name, private and public IP addresses.

kubectl get nodes -o wide | awk -v OFS='\t\t' '{print $1, $6, $7}'

Upvotes: 9

morgwai
morgwai

Reputation: 2823

generally, there is no such thing as a single IP of a kubernetes cluster. Minikube has it, because it's a special 1 node case. Most production clusters will be one way or another operating with many network-internal, cluster-internal and external IP addresses. For example each node is usually deployed on a separate (virtual) machine that has it's own IP address, either external or network-internal (like 10.x.y.z or 192.168.x.y) depending on your network setup. Moreover, many kubernetes objects, like pods or services have their IPs also (cluster-internal or external). Now the question is what do you need the IP for:

  • if you are looking for the address of your kubernetes API endpoint server (the endpoint to which kubectl talks) then in case of clusters created manually with kubeadm, this will be the IP of the master node that you created with kubeadm init command (assuming single master case). See this official doc for details. To talk to your cluster using kubectl you will need some authorization data except its IP: see subsequent sections of the mentioned document how to obtain it.
  • if you are looking for the IP of a LoadBalancer type service, then it will be reported among lots of other stuff in the output of kubectl get service name-of-your-service -o yaml or kubectl describe service name-of-your-service. Note however that clusters created with kubeadm don't provide external load-balancers on their own (that's why they are called external) and if you intend to setup a fully functional production cluster manually, you will need to use something like MetalLB in addition.
  • if you are looking for IPs of NodePort type services then these will be all the IPs of worker node (virtual) machines that you assimilated into you cluster by running kubeadm join command on them. if you don't remember them then you can use kubectl get nodes -o wide as suggested in the other answer.

Upvotes: 4

Alex W
Alex W

Reputation: 38253

Here's a command that should show the internal IP addresses of each node in the cluser:

ubuntu@astrocyte:~$ kubectl get nodes -o yaml | grep -- "- address:"
    - address: 192.168.1.6
    - address: astrocyte
    - address: 192.168.1.20
    - address: axon2.local
    - address: 192.168.1.7
    - address: axon3.local

It also shows hostnames, if you have them configured

Upvotes: 0

PjoterS
PjoterS

Reputation: 14102

To get informations about Kubernetes objects you should use kubectl get <resource> or kubectl describe <resource>.

In docs

Display one or many resources

Prints a table of the most important information about the specified resources. You can filter the list using a label selector and the --selector flag. If the desired resource type is namespaced you will only see results in your current namespace unless you pass --all-namespaces.

If you will check manual for kubectl get you will get information about -o flag.

-o, --output='': Output format. One of: json|yaml|wide|name|custom-columns=...|custom-columns-file=...|go-template=...|go-template-file=...|jsonpath=...|jsonpath-file=... See custom columns [http://kubernetes.io/docs/user-guide/kubectl-overview/#custom-columns], golang template [http://golang.org/pkg/text/template/#pkg-overview] and jsonpath template [http://kubernetes.io/docs/user-guide/jsonpath].

Thats mean you can get output in YAMLs or JSON format. Detailed information can be found in this doc.

As @Bernard Halas mentioned, you can just use kubectl get nodes -o wide.

Another option is use describe with grep. -A will print number lines of trailing context. Its helpful if you need to get list about information per node.

$ kubectl describe node | grep Addresses: -A 4
Addresses:
  InternalIP:   10.164.0.63
  ExternalIP:   35.204.67.223
  InternalDNS:  gke-test-default-pool-d11b1330-g44z.c.composite-rune-239911.internal
  Hostname:     gke-test-default-pool-d11b1330-g44z.c.composite-rune-239911.internal
--
Addresses:
  InternalIP:   10.164.0.61
  ExternalIP:   35.204.63.113
  InternalDNS:  gke-test-default-pool-d11b1330-gtpj.c.composite-rune-239911.internal
  Hostname:     gke-test-default-pool-d11b1330-gtpj.c.composite-rune-239911.internal
--
Addresses:
  InternalIP:   10.164.0.62
  ExternalIP:   35.204.202.107
  InternalDNS:  gke-test-default-pool-d11b1330-r4dw.c.composite-rune-239911.internal
  Hostname:     gke-test-default-pool-d11b1330-r4dw.c.composite-rune-239911.internal

You can also use YAML or JSON format. Output will be similar to previous one.

$ kubectl get nodes -o yaml | grep addresses: -A 8
    addresses:
    - address: 10.164.0.63
      type: InternalIP
    - address: 35.204.67.223
      type: ExternalIP
    - address: gke-test-default-pool-d11b1330-g44z.c.composite-rune-239911.internal
      type: InternalDNS
    - address: gke-test-default-pool-d11b1330-g44z.c.composite-rune-239911.internal
      type: Hostname
...

In addition if you will need some specific output (only information you need and ar not print as default) you can use custom columns. It's based on YAML format.

$ kubectl get pods -o custom-columns=Name:.metadata.name,NS:.metadata.namespace,HostIP:.status.hostIP,PodIP:status.podIP,REQ_CPU:.spec.containers[].resources.requests.cpu
Name                          NS        HostIP        PodIP       REQ_CPU
httpd-5d8cbbcd67-gtzcx        default   10.164.0.63   10.32.2.7   100m
nginx-7cdbd8cdc9-54dds        default   10.164.0.62   10.32.1.5   100m
nginx-7cdbd8cdc9-54ggt        default   10.164.0.62   10.32.1.3   100m
nginx-7cdbd8cdc9-bz86v        default   10.164.0.62   10.32.1.4   100m
nginx-7cdbd8cdc9-zcvrf        default   10.164.0.62   10.32.1.2   100m
nginx-test-59df8dcb7f-hlrcr   default   10.164.0.63   10.32.2.4   100m

Upvotes: 2

Bernard Halas
Bernard Halas

Reputation: 1190

This should be fairly straightforward: kubectl get nodes -o wide

Upvotes: 27

Related Questions