简体   繁体   English

如何获取k8s主控ip地址?

[英]How to get k8s master ip address?

I have learn that I need to create a service so the deployment pods's ports will be exposed in the cluster.我了解到我需要创建一个服务,以便部署 pod 的端口将在集群中公开。 so the service provides me the port, and all is left is to find the cluster ip.所以服务为我提供了端口,剩下的就是找到集群 ip。

Problem问题

using https://github.com/kubernetes-client/javascript , I have created a deployment and a service.使用https://github.com/kubernetes-client/javascript ,我创建了一个部署和一个服务。

Question问题

I'm not sure how to get the master address.我不确定如何获得主地址。

In bash, I would do:在 bash 中,我会这样做:

> kubectl cluster-info
Kubernetes master is running at https://<this-is-what-I-need>:8443
KubeDNS is running at https://<this-is-what-I-need>:8443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy

To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.

but I'm not sure how to extract the ip.但我不确定如何提取 ip。 is there a better bash command?有没有更好的 bash 命令? or any api for that?或任何 api ? (maybe in https://github.com/kubernetes-client/javascript )? (也许在https://github.com/kubernetes-client/javascript中)?


more context更多上下文

I created a demployment on my local machine for a docker image that exposes a service on port 4873 .我在本地计算机上为 docker 映像创建了一个部署,该映像在端口4873上公开了一个服务。

> kubectl get service stav-service1
NAME            TYPE       CLUSTER-IP      EXTERNAL-IP   PORT(S)          AGE
stav-service1   NodePort   10.104.10.251   <none>        4873:30219/TCP   39m

> kubectl get deployment stav-deployment1
NAME               READY   UP-TO-DATE   AVAILABLE   AGE
stav-deployment1   1/1     1            1           41m

I can reach that service from my local machine by running curl http://192.168.64.2:30219我可以通过运行curl http://192.168.64.2:30219从本地计算机访问该服务

Is this what you are looking for?这是你想要的?

kubectl get nodes --selector=node-role.kubernetes.io/master -o jsonpath='{$.items[*].status.addresses[?(@.type=="InternalIP")].address}'

If you are using minikube as you stated in your comment please try the following one:如果您按照评论中所述使用 minikube,请尝试以下方法:

minikube ip

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM