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



在本地minikube设置中玩K8和ingress。从networking.k8s.io/v1 api版本中的yaml文件创建入口失败。请参阅以下输出。执行

> 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

在本地minikube环境中,使用hyperkit作为vm驱动程序。

这是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

非常感谢您的帮助。

我遇到了同样的问题。我使用成功修复了它

kubectl delete -A ValidatingWebhookConfiguration ingress-nginx-admission

然后应用yaml文件:

kubectl apply -f ingress_file.yaml

我和你有同样的问题,你可以看到这个问题https://github.com/kubernetes/minikube/issues/11121.

有两种方法可以尝试:

  1. 下载新版本,或返回旧版本
  2. 做一件奇怪的事,就像巴伦比说的那样

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

Ref:期望apiVersion-networking.k8s.io/v1而不是extensions/v1beta1

TL;DR

kubectl explain早于许多通用资源解析逻辑,因此它有一个专用的--api-version标志。这应该是你想要的。

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

这应该能解决你的疑问!

在我的案例中,它是NGINX的先前部署。检查方式:

kubectl get ValidatingWebhookConfiguration -A

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

您也可以在GKE私有集群上获得此错误,因为防火墙规则不是自动配置的。https://cloud.google.com/kubernetes-engine/docs/how-to/private-clusters#add_firewall_ruleshttps://github.com/kubernetes/kubernetes/issues/79739

相关内容

  • 没有找到相关文章

最新更新