k8s中创建ingress资源时报错

当我想要做一个ingress域名访问时出现如下错误:

以下错误解决示范可以仅作参考,需要根据个人配置决定如何修改

1、错误一

[root@master ingress-controller]# kubectl apply -f ingress-http.yaml
error: resource mapping not found for name: "ingress-http" namespace: "lty" from "ingress-http.yaml": no matches for kind "Ingress" in version "extensions/v1beta1"
ensure CRDs are installed first

== “extensions/v1beta1”==
这里主要提示是版本的错误

我们可以通过命令查出在我们使用这个资源时,所对应的版本是多少

[root@master ingress-controller]# kubectl explain ingress
KIND:     Ingress
VERSION:  networking.k8s.io/v1   //将其添加到配置文件既可

2、错误2

接下来在此创建时又报错了:Error from server (BadRequest): error when creating "ingress-http.yaml": Ingress in version "v1" cannot be handled as a Ingress: json: cannot unmarshal number into Go struct field IngressServiceBackend.spec.rules.==http.paths.backend.service.port== of type v1.ServiceBackendPort

从关键字可以看出是port的问题
于是将其port:添加一个子目录number:80指定端口
配置文件大概如下:

spec:
  ingressClassName: nginx
  rules:
  - host: nginx.hhh.com
    http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: nginx-service
            port:
              number: 80     //添加

接下来创建后完美解决

你可能感兴趣的:(运维报错解决时刻,kubernetes,容器,云原生)