外部ip总是< none>或< pending>在kubernetes中 [英] External ip always <none> or <pending> in kubernetes
问题描述
最近,我开始使用一些Raspberry pi来构建自己的kubernetes集群.
Recently i started building my very own kubernetes cluster using a few Raspberry pi's.
我已经到了可以运行群集的地步!
I have gotten to the point where i have a cluster up and running!
有关如何设置群集的一些背景信息,我使用了本指南
Some background info on how i setup the cluster, i used this guide
但是现在,当我想部署和公开应用程序时,我遇到了一些问题...
But now, when i want to deploy and expose an application i encounter some issues...
在kubernetes教程之后,我进行了nginx的部署,运行良好.当我进行端口转发时,我可以在本地主机上看到默认的nginx页面.
Following the kubernetes tutorials i have made an deployment of nginx, this is running fine. when i do a port-forward i can see the default nginx page on my localhost.
现在最棘手的部分是创建服务,并通过入口将来自互联网的流量路由到服务.
Now the tricky part, creating an service and routing the traffic from the internet through an ingress to the service.
我已经执行了以下命令
kubectl expose deployment/nginx --type="NodePort" --port 80
kubectl expose deployment/nginx --type="Loadbalancer" --port 80
这些导致以下结果.
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 25h
nginx NodePort 10.103.77.5 <none> 80:30106/TCP 7m50s
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 25h
nginx LoadBalancer 10.107.233.191 <pending> 80:31332/TCP 4s
外部IP地址从不显示,这使我无法通过curl some-ip:80
从集群外部访问应用程序,这最终是我设置此集群的全部原因.
The external ip address never shows, which makes it quite impossible for me to access the application from outside of the cluster by doing curl some-ip:80
which in the end is the whole reason for me to setup this cluster.
如果您有任何明确的指导或建议,我可以与之合作,我们将不胜感激!
If any of you have some clear guides or advice i can work with it would be really appreciated!
注意: 我已经阅读了有关LoadBalancer的内容,该内容应该由云主机提供.由于我使用RPI运行,所以我认为这对我不起作用.但我相信NodePort应该可以与入口路由.
Note: I have read things about LoadBalancer, this is supposed to be provided by the cloud host. since i run on RPI i don't think this will work for me. but i believe NodePort should be just fine to route with an ingress.
我也意识到我应该有某种类型的入口控制器才能使入口工作.
Also i am aware of the fact that i should have an ingress-controller of some sort for ingress to work.
所以我现在将以下用于节点端口-30168
So i have the following now for the nodeport - 30168
$ kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 26h
nginx NodePort 10.96.125.112 <none> 80:30168/TCP 6m20s
,对于IP地址,我有192.168.178.102
或10.44.0.1
and for the ip address i have either 192.168.178.102
or 10.44.0.1
$ kubectl describe pod nginx-688b66fb9c-jtc98
Node: k8s-worker-2/192.168.178.102
IP: 10.44.0.1
但是当我在浏览器中使用nodeport输入这些IP地址中的任何一个时,我仍然看不到nginx页面.我在做错什么吗?
But when i enter either of these ip addresses in the browser with the nodeport i still don't see the nginx page. am i doing something wrong?
推荐答案
Since you are not in a cloud provider, you need to use MetalLB to have the LoadBalancer features working.
Kubernetes没有为裸机群集提供网络负载平衡器(类型为LoadBalancer的服务)的实现. Kubernetes附带的Network LB的实现都是调用各种IaaS平台(GCP,AWS,Azure等)的粘合代码.如果您未在受支持的IaaS平台(GCP,AWS,Azure等)上运行,则LoadBalancers在创建后将无限期保持待处理"状态.
Kubernetes does not offer an implementation of network load-balancers (Services of type LoadBalancer) for bare metal clusters. The implementations of Network LB that Kubernetes does ship with are all glue code that calls out to various IaaS platforms (GCP, AWS, Azure…). If you’re not running on a supported IaaS platform (GCP, AWS, Azure…), LoadBalancers will remain in the "pending" state indefinitely when created.
裸机集群运营商只剩下两个较小的工具,即"NodePort"和"externalIPs"服务,可将用户流量引入其集群.这两种选择在生产用途上都有很大的缺点,这使裸金属集群成为Kubernetes生态系统中的第二等公民.
Bare metal cluster operators are left with two lesser tools to bring user traffic into their clusters, "NodePort" and "externalIPs" services. Both of these options have significant downsides for production use, which makes bare metal clusters second class citizens in the Kubernetes ecosystem.
MetalLB旨在通过提供与标准网络设备集成的Network LB实施来纠正这种不平衡,从而使裸机群集上的外部服务也尽可能正常运行".
MetalLB aims to redress this imbalance by offering a Network LB implementation that integrates with standard network equipment, so that external services on bare metal clusters also "just work" as much as possible
MetalLB 设置非常简单:
The MetalLB setup is very easy:
kubectl apply -f https://raw.githubusercontent.com/google/metallb/v0.8.3/manifests/metallb.yaml
这会将MetalLB部署到您的集群中,位于metallb系统名称空间下
This will deploy MetalLB to your cluster, under the metallb-system namespace
您需要使用要使用的ip范围创建一个configMap,创建一个名为metallb-cf.yaml
的文件:
You need to create a configMap with the ip range you want to use, create a file named metallb-cf.yaml
:
apiVersion: v1
kind: ConfigMap
metadata:
namespace: metallb-system
name: config
data:
config: |
address-pools:
- name: default
protocol: layer2
addresses:
- 192.168.1.240-192.168.1.250 <= Select the range you want.
kubectl apply -f metallb-cf.yaml
仅此而已.
要在您的服务上使用,只需使用LoadBalancer
类型创建,其余的操作将由MetalLB完成.如果要自定义配置,请参见此处
To use on your services just create with type LoadBalancer
and MetalLB will do the rest. If you want to customize the configuration see here
MetalLB将为您的服务/入口分配IP,但是如果您在NAT网络中,则需要配置路由器以转发对入口/服务IP的请求.
MetalLB will assign a IP for your service/ingress, but if you are in a NAT network you need to configure your router to forward the requests for your ingress/service IP.
您在使用Raspberry Pi上运行的MetalLB获取外部IP时遇到问题,请尝试将iptables更改为旧版:
You have problem to get External IP with MetalLB running on Raspberry Pi, try to change iptables to legacy version:
sudo sysctl net.bridge.bridge-nf-call-iptables=1
sudo update-alternatives --set iptables /usr/sbin/iptables-legacy
参考:我希望能帮上忙.
这篇关于外部ip总是< none>或< pending>在kubernetes中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!