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?
This should be fairly straightforward: kubectl get nodes -o wide
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
it is important to understand that there is no such thing as single IP of the 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 internal and external IP addresses: each node is deployed on a separate (virtual) machine that has it's own IP address, either public or private depending on how you setup the (virtual) machines. Now the question is what do you need the IP for:
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.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.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.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