kubernetes microk8s中的入口不分配地址

bwleehnv  于 2023-11-17  发布在  Kubernetes
关注(0)|答案(1)|浏览(144)

我的问题是为什么入口不分配一个地址的服务?
首先,我创建了3个部署:

kubectl create deployment cheddar --image=errm/cheese:cheddar
kubectl create deployment stilton --image=errm/cheese:stilton
kubectl create deployment wensleydale --image=errm/cheese:wensleydale

字符串
第二,我将展示这三个部署:

kubectl expose deployment cheddar --port=80                  
kubectl expose deployment stilton --port=80                  
kubectl expose deployment wensleydale --port=80


然后我将我的ingress.yaml与kubectl apply -f ingress.yaml一起应用,ingress.yaml的内容是:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: cheddar
spec:
  ingressClassName: nginx
  rules:
  - host: cheddar.127.0.0.1.nip.io
    http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: cheddar
            port:
              number: 80
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: stilton
spec:
  ingressClassName: nginx
  rules:
  - host: stilton.127.0.0.1.nip.io
    http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: stilton
            port:
              number: 80
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: wensleydale
spec:
  ingressClassName: nginx
  rules:
  - host: wensleydale.127.0.0.1.nip.io
    http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: wensleydale
            port:
              number: 80
---


但是当我路由这些路径时,结果仍然是404-nginx
kubectl get ingress返回:

NAME          CLASS   HOSTS                          ADDRESS   PORTS   AGE
cheddar       nginx   cheddar.127.0.0.1.nip.io                 80      43s
stilton       nginx   stilton.127.0.0.1.nip.io                 80      43s
wensleydale   nginx   wensleydale.127.0.0.1.nip.io             80      43s


注1:我在ubuntu上使用microk8s,我的集群版本是:v1.21.7-3+7700880a5c71e2

➜  ~ k get no
NAME   STATUS   ROLES    AGE   VERSION
ali    Ready    <none>   8d    v1.21.7-3+7700880a5c71e2

➜  ~ kubectl version
Client Version: version.Info{Major:"1", Minor:"21+", GitVersion:"v1.21.7-3+7700880a5c71e2", GitCommit:"7700880a5c71e25c44491ef5c7d7fb30527d8337", GitTreeState:"clean", BuildDate:"2021-11-17T22:07:23Z", GoVersion:"go1.16.10", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"21+", GitVersion:"v1.21.7-3+7700880a5c71e2", GitCommit:"7700880a5c71e25c44491ef5c7d7fb30527d8337", GitTreeState:"clean", BuildDate:"2021-11-17T22:02:47Z", GoVersion:"go1.16.10", Compiler:"gc", Platform:"linux/amd64"}


注2:我已经通过以下命令启用了入口扩展名:microk8s enable ingress

yk9xbfzb

yk9xbfzb1#

如果你使用的是这个集群的裸机,你必须使用类似metallb的东西。Kubernetes没有实现网络负载均衡器,因此,将无法为你的入口分配IP地址。
由于您使用的是microk8s,因此可以使用microk8s enable metallb
如果你正在使用aws,gcp,aks,你可以在他们的文档中找到。
对于裸机,请参见以下内容:https://metallb.org/

相关问题