简体   繁体   English

通过 kubernetes 集群中的服务公开 kubernetes pod

[英]Exposing a kubernetes pod via service in kind kubernetes cluster

I'm following the tutorial here ( https://kubernetes.io/docs/tutorials/hello-minikube/ ) to test a local development setup for kubernetes.我正在按照此处的教程 ( https://kubernetes.io/docs/tutorials/hello-minikube/ ) 测试 kubernetes 的本地开发设置。 However, I am using kind, instead of minikube.但是,我使用的是 kind,而不是 minikube。

At the moment, I am stuck on step 3:目前,我被困在第 3 步:

minikube service hello-node

which is supposed to expose a LoadBalancer service.它应该公开 LoadBalancer 服务。

However, kind doesn't seem to have such a command, and I am wondering how I would expose the service from the tutorial.但是, kind 似乎没有这样的命令,我想知道如何从教程中公开服务。

My set up is a WSL2 distro with docker, kind, and kubectl.我的设置是带有 docker、kind 和 kubectl 的 WSL2 发行版。 My current port bridges are:我目前的端口桥是:

$ docker ps
CONTAINER ID        IMAGE                  COMMAND                  CREATED             STATUS              PORTS                       NAMES
b62c43ac3b2e        kindest/node:v1.17.0   "/usr/local/bin/entr…"   49 minutes ago      Up 49 minutes       127.0.0.1:32769->6443/tcp   kind-control-plane
$ kubectl cluster-info
Kubernetes master is running at https://127.0.0.1:32769
KubeDNS is running at https://127.0.0.1:32769/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy

and

$ kubectl get services
NAME         TYPE           CLUSTER-IP     EXTERNAL-IP   PORT(S)          AGE
hello-node   LoadBalancer   10.96.65.157   <pending>     8080:31578/TCP   46m
kubernetes   ClusterIP      10.96.0.1      <none>        443/TCP          51m

LoadBalancer type service internally creates NodePort . LoadBalancer类型服务在内部创建NodePort So you can access it via http://NODEIP:31578 where 31578 is the NodePort as you can see in output of kubectl get service .因此,您可以通过http://NODEIP:31578访问它,其中31578是 NodePort,您可以在kubectl get service输出中kubectl get service To get NODEIP you can use kubectl get nodes -o wide要获得NODEIP您可以使用kubectl get nodes -o wide

If you look at the output of minikube service hello-node it's has got the same NODEIP and NODEPORT .如果您查看minikube service hello-node的输出,它具有相同的NODEIPNODEPORT Unfortunately there is no equivalent command in kind and so you need to use the method described above.不幸的是,没有等效的命令,因此您需要使用上述方法。

EXTERNAL-IP will be pending because there is no cloud(AWS, GCP, Azure) like implementation in local kind cluster. EXTERNAL-IP将挂起,因为在本地种类集群中没有云(AWS、GCP、Azure)之类的实现。 If you really want to make LoadBalancer type service work you can use metallb as loadbalancer implementation.如果你真的想让LoadBalancer类型的服务工作,你可以使用 metallb 作为负载均衡器实现。 In this way you will have EXTERNAL-IP assigned instead of pending and you can use that IP to access the pod.通过这种方式,您将分配EXTERNAL-IP而不是pending ,您可以使用该 IP 访问 pod。

Here is a guide on how to make metallb with kind work.是有关如何用善意制作金属的指南。

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

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