Kubernetes入口:发生内部错误:调用webhook“validate.nginx.ingress.kubernetes.io“失败

bihw5rsg  于 2022-11-21  发布在  Kubernetes
关注(0)|答案(5)|浏览(301)

在本地minikube设置中使用K8和入口。从www.example.com api版本中的yaml文件创建入口networking.k8s.io/v1失败。请参见以下输出。正在执行

> kubectl apply -f ingress.yaml

返回

Error from server (InternalError): error when creating "ingress.yaml": Internal error occurred: failed calling webhook "validate.nginx.ingress.kubernetes.io": an error on the server ("") has prevented the request from succeeding

在具有Hyperkit作为VM驱动程序本地minikube环境中。
下面是ingress.yaml文件:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: mongodb-express-ingress
  namespace: hello-world
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /$1
spec:
  rules:
    - host: mongodb-express.local
      http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: mongodb-express-service-internal
                port:
                  number: 8081

下面是mongodb-express部署文件:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: mongodb-express
  namespace: hello-world
  labels:
    app: mongodb-express
spec:
  replicas: 1
  selector:
    matchLabels:
      app: mongodb-express
  template:
    metadata:
      labels:
        app: mongodb-express
    spec:
      containers:
        - name: mongodb-express
          image: mongo-express
          ports:
            - containerPort: 8081
          env:
            - name: ME_CONFIG_MONGODB_ADMINUSERNAME
              valueFrom:
                secretKeyRef:
                  name: mongodb-secret
                  key: mongodb-root-username
            - name: ME_CONFIG_MONGODB_ADMINPASSWORD
              valueFrom:
                secretKeyRef:
                  name: mongodb-secret
                  key: mongodb-root-password
            - name: ME_CONFIG_MONGODB_SERVER
              valueFrom:
                configMapKeyRef:
                  name: mongodb-configmap
                  key: mongodb_url
---
apiVersion: v1
kind: Service
metadata:
  name: mongodb-express-service-external
  namespace: hello-world
spec:
  selector:
    app: mongodb-express
  type: LoadBalancer
  ports:
    - protocol: TCP
      port: 8081
      targetPort: 8081
      nodePort: 30000
---
apiVersion: v1
kind: Service
metadata:
  name: mongodb-express-service-internal
  namespace: hello-world
spec:
  selector:
    app: mongodb-express
  ports:
    - protocol: TCP
      port: 8081
      targetPort: 8081

更多信息:

> kubectl version
Client Version: version.Info{Major:"1", Minor:"19", GitVersion:"v1.19.7", GitCommit:"1dd5338295409edcfff11505e7bb246f0d325d15", GitTreeState:"clean", BuildDate:"2021-01-13T13:23:52Z", GoVersion:"go1.15.5", Compiler:"gc", Platform:"darwin/amd64"}
Server Version: version.Info{Major:"1", Minor:"20", GitVersion:"v1.20.2", GitCommit:"faecb196815e248d3ecfb03c680a4507229c2a56", GitTreeState:"clean", BuildDate:"2021-01-13T13:20:00Z", GoVersion:"go1.15.5", Compiler:"gc", Platform:"linux/amd64"}

> minikube version
minikube version: v1.19.0
commit: 15cede53bdc5fe242228853e737333b09d4336b5

> kubectl get all -n hello-world
NAME                                   READY   STATUS    RESTARTS   AGE
pod/mongodb-68d675ddd7-p4fh7           1/1     Running   0          3h29m
pod/mongodb-express-6586846c4c-5nfg7   1/1     Running   6          3h29m

NAME                                       TYPE           CLUSTER-IP       EXTERNAL-IP   PORT(S)          AGE
service/mongodb-express-service-external   LoadBalancer   10.106.185.132   <pending>     8081:30000/TCP   3h29m
service/mongodb-express-service-internal   ClusterIP      10.103.122.120   <none>        8081/TCP         3h3m
service/mongodb-service                    ClusterIP      10.96.197.136    <none>        27017/TCP        3h29m

NAME                              READY   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/mongodb           1/1     1            1           3h29m
deployment.apps/mongodb-express   1/1     1            1           3h29m

NAME                                         DESIRED   CURRENT   READY   AGE
replicaset.apps/mongodb-68d675ddd7           1         1         1       3h29m
replicaset.apps/mongodb-express-6586846c4c   1         1         1       3h29m

> minikube addons enable ingress
    ▪ Using image k8s.gcr.io/ingress-nginx/controller:v0.44.0
    ▪ Using image docker.io/jettech/kube-webhook-certgen:v1.5.1
    ▪ Using image docker.io/jettech/kube-webhook-certgen:v1.5.1
🔎  Verifying ingress addon...
🌟  The 'ingress' addon is enabled

> kubectl get all -n ingress-nginx
NAME                                            READY   STATUS      RESTARTS   AGE
pod/ingress-nginx-admission-create-2bn8h        0/1     Completed   0          4h4m
pod/ingress-nginx-admission-patch-vsdqn         0/1     Completed   0          4h4m
pod/ingress-nginx-controller-5d88495688-n6f67   1/1     Running     0          4h4m

NAME                                         TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)                      AGE
service/ingress-nginx-controller             NodePort    10.111.176.223   <none>        80:32740/TCP,443:30636/TCP   4h4m
service/ingress-nginx-controller-admission   ClusterIP   10.97.107.77     <none>        443/TCP                      4h4m

NAME                                       READY   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/ingress-nginx-controller   1/1     1            1           4h4m

NAME                                                  DESIRED   CURRENT   READY   AGE
replicaset.apps/ingress-nginx-controller-5d88495688   1         1         1       4h4m

NAME                                       COMPLETIONS   DURATION   AGE
job.batch/ingress-nginx-admission-create   1/1           7s         4h4m
job.batch/ingress-nginx-admission-patch    1/1           9s         4h4m

但是,它适用于beta版api,即

apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: mongodb-express-ingress-deprecated
  namespace: hello-world
spec:
  rules:
    - host: mongodb-express.local
      http:
        paths:
          - path: /
            backend:
              serviceName: mongodb-express-service-internal
              servicePort: 8081

任何帮助都非常感谢。

e5njpo68

e5njpo681#

我遇到了同样的问题。我使用以下方法成功修复了该问题:
kubectl delete -A ValidatingWebhookConfiguration ingress-nginx-admission
然后应用yaml文件:
kubectl apply -f ingress_file.yaml

mwyxok5s

mwyxok5s2#

我有同样的问题与你,你可以看到这个问题https://github.com/kubernetes/minikube/issues/11121
有两种方法可以尝试:
1.下载新版本,或返回旧版本
1.像balnbibarbi说的那样做一件奇怪的事情。
2.奇怪的事情

# Run without --addons=ingress
sudo minikube start --vm-driver=none #--addons=ingress

# install external ingress-nginx
sudo helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx
sudo helm repo update
sudo helm install ingress-nginx ingress-nginx/ingress-nginx

# expose your services

然后你会发现你的入口缺少端点。然后:

sudo minikube addons enable ingress

在分钟画面之后,会出现端点。

问题

如果你搜索谷歌插件Ingress的例子,你会发现下面缺少的是入口

root@ubuntu:~# kubectl get pods -n kube-system 
NAME                             READY   STATUS    RESTARTS   AGE
coredns-74ff55c5b-xnmx2          1/1     Running   1          4h40m
etcd-ubuntu                      1/1     Running   1          4h40m
kube-apiserver-ubuntu            1/1     Running   1          4h40m
kube-controller-manager-ubuntu   1/1     Running   1          4h40m
kube-proxy-k9lnl                 1/1     Running   1          4h40m
kube-scheduler-ubuntu            1/1     Running   2          4h40m
storage-provisioner              1/1     Running   3          4h40m
6rqinv9w

6rqinv9w3#

引用:应为apiVersion -networking.k8s.io/v1而不是扩展/v1 beta1

TL;DR

kubectl解释了很多通用的资源解析逻辑,所以它有一个专用的--api-version标志,这应该可以满足你的需要。

kubectl explain ingresses --api-version=networking.k8s.io/v1

这应该能解开你的疑惑!

7vhp5slm

7vhp5slm4#

在我的例子中,这是NGINX的一个以前的部署。

kubectl get ValidatingWebhookConfiguration -A

如果有多个NGINX,则删除旧的NGINX。

7xzttuei

7xzttuei5#

您也可能在GKE专用群集上收到此错误,因为未自动配置防火墙规则。https://cloud.google.com/kubernetes-engine/docs/how-to/private-clusters#add_firewall_rules https://github.com/kubernetes/kubernetes/issues/79739

相关问题