How to find cluster node ip address

前端 未结 4 1593
庸人自扰
庸人自扰 2021-01-28 19:58

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?

4条回答
  •  甜味超标
    2021-01-28 20:29

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

    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
    

提交回复
热议问题