kubernetes 通过http使用nginx入口的Microk 8 s Jmeter 板不工作(错误:'在版本“extensions/v1 beta1”中没有类型“Ingress”的匹配项')

b4qexyjb  于 2023-03-17  发布在  Kubernetes
关注(0)|答案(3)|浏览(192)

我有microk 8 s v1.22.2运行在Ubuntu 20.04.3 LTS上。
/etc/hosts的输出:

127.0.0.1 localhost
127.0.1.1 main

摘自microk8s status

addons:
  enabled:
    dashboard            # The Kubernetes dashboard
    ha-cluster           # Configure high availability on the current node
    ingress              # Ingress controller for external access
    metrics-server       # K8s Metrics Server for API access to service metrics

我检查了正在运行的 Jmeter 板(kubectl get all --all-namespaces):

NAMESPACE     NAME                                             READY   STATUS    RESTARTS   AGE
kube-system   pod/calico-node-2jltr                            1/1     Running   0          23m
kube-system   pod/calico-kube-controllers-f744bf684-d77hv      1/1     Running   0          23m
kube-system   pod/metrics-server-85df567dd8-jd6gj              1/1     Running   0          22m
kube-system   pod/kubernetes-dashboard-59699458b-pb5jb         1/1     Running   0          21m
kube-system   pod/dashboard-metrics-scraper-58d4977855-94nsp   1/1     Running   0          21m
ingress       pod/nginx-ingress-microk8s-controller-qf5pm      1/1     Running   0          21m

NAMESPACE     NAME                                TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)    AGE
default       service/kubernetes                  ClusterIP   10.152.183.1     <none>        443/TCP    23m
kube-system   service/metrics-server              ClusterIP   10.152.183.81    <none>        443/TCP    22m
kube-system   service/kubernetes-dashboard        ClusterIP   10.152.183.103   <none>        443/TCP    22m
kube-system   service/dashboard-metrics-scraper   ClusterIP   10.152.183.197   <none>        8000/TCP   22m

NAMESPACE     NAME                                               DESIRED   CURRENT   READY   UP-TO-DATE   AVAILABLE   NODE SELECTOR            AGE
kube-system   daemonset.apps/calico-node                         1         1         1       1            1           kubernetes.io/os=linux   23m
ingress       daemonset.apps/nginx-ingress-microk8s-controller   1         1         1       1            1           <none>                   22m

NAMESPACE     NAME                                        READY   UP-TO-DATE   AVAILABLE   AGE
kube-system   deployment.apps/calico-kube-controllers     1/1     1            1           23m
kube-system   deployment.apps/metrics-server              1/1     1            1           22m
kube-system   deployment.apps/kubernetes-dashboard        1/1     1            1           22m
kube-system   deployment.apps/dashboard-metrics-scraper   1/1     1            1           22m

NAMESPACE     NAME                                                   DESIRED   CURRENT   READY   AGE
kube-system   replicaset.apps/calico-kube-controllers-69d7f794d9     0         0         0       23m
kube-system   replicaset.apps/calico-kube-controllers-f744bf684      1         1         1       23m
kube-system   replicaset.apps/metrics-server-85df567dd8              1         1         1       22m
kube-system   replicaset.apps/kubernetes-dashboard-59699458b         1         1         1       21m
kube-system   replicaset.apps/dashboard-metrics-scraper-58d4977855   1         1         1       21m

我想在本地网络中公开microk 8 s控制面板,以便通过http://main/dashboard/访问它
为此,我执行了以下nano ingress.yaml

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  annotations:
    kubernetes.io/ingress.class: public
    nginx.ingress.kubernetes.io/backend-protocol: "HTTPS"
  name: dashboard
  namespace: kube-system
spec:
  rules:
  - host: main
    http:
      paths:
      - backend:
          serviceName: kubernetes-dashboard
          servicePort: 443
        path: /

通过kubectl apply -f ingress.yaml启用ingress-config时出现以下错误:

error: unable to recognize "ingress.yaml": no matches for kind "Ingress" in version "extensions/v1beta1"

帮助将不胜感激,谢谢!

更新:@harsh-manvar指出了配置版本中的一个不匹配。我已经将ingress.yaml重写为一个非常精简的版本:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: dashboard
  namespace: kube-system
spec:
  rules:
  - http:
      paths:
      - path: /dashboard
        pathType: Prefix
        backend:
          service:
            name: kubernetes-dashboard
            port:
              number: 443

应用此命令可以正常工作,同时也创建了入口规则。

NAMESPACE     NAME        CLASS    HOSTS   ADDRESS     PORTS   AGE
kube-system   dashboard   public   *       127.0.0.1   80      11m

但是,当我通过http://<ip-of-kubernetes-master>/dashboard访问 Jmeter 板时,我得到了一个400错误。
来自入口控制器的日志:

192.168.0.123 - - [10/Oct/2021:21:38:47 +0000] "GET /dashboard HTTP/1.1" 400 54 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.71 Safari/537.36" 466 0.002 [kube-system-kubernetes-dashboard-443] [] 10.1.76.3:8443 48 0.000 400 ca0946230759edfbaaf9d94f3d5c959a

Jmeter 板是否也需要使用microk8s proxy来暴露?我以为入口控制器会处理这个问题,还是我误解了这一点?

093gszye

093gszye1#

要修复错误error: unable to recognize "ingress.yaml": no matches for kind "Ingress" in version "extensions/v1beta1,您需要将apiVersion设置为networking.k8s.io/v1。从Kubernetes v1.16 article about deprecated APIs

  • 不再提供extensions/v1 beta1API版本中的NetworkPolicy-迁移以使用自v1.8起提供的networking.k8s.io/v1API版本。可以通过新版本检索/更新现有的持久数据。

现在转到第二个问题,您需要添加一些注解,并对Ingress定义进行一些修改,以使dashboard在microk 8 s集群上正确显示:

我们需要它们将请求正确转发到后端pod-good explanation in this article

注意:“nginx.ingress.kubernetes.io/rewrite-target“注解会在将请求转发到后端Pod之前重写URL。在**/dashboard(/|$)(.表示路径**,**(.存储访问Kubernetes Jmeter 板时生成的动态URL。“nginx.ingress.kubernetes.io/rewrite-target”注解会在将请求转发到kubernetes-dashboard服务之前替换URL中捕获的数据。“nginx.ingress.kubernetes.io/configuration-snippet“注解会重写URL以添加一个尾部斜杠(“/”)仅当访问ALB-URL/ Jmeter 板**时。

此外,我们还需要另外两项更改:

实现以上所有内容后,最终的YAML文件如下所示:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /$2
    nginx.ingress.kubernetes.io/configuration-snippet: |
      rewrite ^(/dashboard)$ $1/ redirect;
    nginx.ingress.kubernetes.io/backend-protocol: "HTTPS"
    kubernetes.io/ingress.class: public
  name: dashboard
  namespace: kube-system
spec:
  rules:
  - http:
      paths:
      - path: /dashboard(/|$)(.*)
        pathType: Prefix
        backend:
          service:
            name: kubernetes-dashboard
            port:
              number: 443

它应该工作正常。不需要运行microk8s proxy命令。

hgc7kmma

hgc7kmma2#

error: unable to recognize "ingress.yaml": no matches for kind "Ingress" in version "extensions/v1beta1"

这是由于入口API版本不匹配。
您正在运行v1.22.2,而YAML中API版本较旧。
好例子:https://kubernetes.io/docs/tasks/access-application-cluster/ingress-minikube/
您在YAML中使用的是较旧的入口API版本extensions/v1beta1
您需要根据正在运行的入口版本和K8s版本更改此设置。
这适用于K8s中的版本1.19,也适用于1.22
示例:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: minimal-ingress
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /
spec:
  rules:
  - http:
      paths:
      - path: /testpath
        pathType: Prefix
        backend:
          service:
            name: test
            port:
              number: 80

参考:https://kubernetes.io/docs/concepts/services-networking/ingress/

xtupzzrd

xtupzzrd3#

**如果您在尝试安装AWS ALB控制器〈2.0时遇到此错误!**会发生以下情况:ALB控制器v1.x.x使用networking.k8s.io/v1beta1 API,该API在k8s的新版本中被删除(https://kubernetes.io/blog/2021/07/14/upcoming-changes-in-kubernetes-1-22/#api-changes)

所有beta版入口API(扩展/v1 beta1和networking.k8s.io/v1beta1API版本)

  • (推荐)解决方案是升级ALB版本。
  • (不鼓励的)解决方案是降级你的k8s版本。

相关问题