denied the request: rejecting admission review because the request does not contains an Ingress resource but networking.k8s.io/v1 - kubernetes

I was upgrade kubernetes 1.19.1. then ingress deployment give this warning;
Warning: networking.k8s.io/v1beta1 Ingress is deprecated in v1.19+, unavailable in v1.22+; use networking.k8s.io/v1 Ingress
ingress.networking.k8s.io/msrs-ingress created
I have changed correct new version of ingress api ( v1beta to v1) but now I cant install again because of admission rule;
Error from server: error when creating "disabled/my-ingress-prod-v2.yaml": admission webhook "validate.nginx.ingress.kubernetes.io" denied the request: rejecting admission review because the request does not contains an Ingress resource but networking.k8s.io/v1, Resource=ingresses with name my-ingress2 in namespace my-pro
actualy I changed my-ingress2 like this;
after:
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
annotations:
kubernetes.io/ingress.class: nginx
name: my-ingress
spec:
rules:
- http:
paths:
- path: /
backend:
serviceName: frontend
servicePort: 80
befor:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: my-ingress
spec:
rules:
- http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: frontend
port:
number: 80
how can I found correct way to install ingress rules. I don't want to disable admission
kubectl delete -A ValidatingWebhookConfiguration ingress-nginx-admission

Here is pull request which fixed it:
https://github.com/kubernetes/ingress-nginx/pull/6187
You just need to wait for new release. You can track progress here:
https://github.com/kubernetes/ingress-nginx/projects/43#card-45661384

Related

error: resource mapping not found || make sure CRDs are installed first

error: resource mapping not found for name: "ingress-srv" namespace: "" from "ingress-srv.yaml": no matches for kind "Ingress" in version "networking.k8s.io/v1beta1"
ensure CRDs are installed first
I am new to Kubernetes, I was setting up ingress nginx on minikube and it installed successfully but when I try to run using kubectl apply -f filename it gives above error
here is the code
filename: ingress-srv.yaml
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: ingress-srv
annotations:
kubernetes.io/ingress.class: nginx
spec:
rules:
- host: posts.com
http:
paths:
- path: /posts
pathType: Prefix
backend:
serviceName: posts-clusterip-srv
servicePort: 4000
The resource type specified in your manifest, networking.k8s.io/v1beta1 Ingress, was removed in Kubernetes v1.22 and replaced by networking.k8s.io/v1 Ingress (see the deprecation guide for details). If your cluster's Kubernetes server version is 1.22 or higher (which I suspect it is) trying to create an Ingress resource from your manifest will result in exactly the error you're getting.
You can check your cluster's Kubernetes server version (as Kamol Hasan points out) using the command kubectl version --short.
If the version is indeed 1.22 or higher, you'll need to modify your YAML file so that its format is valid in the new version of the API. This pull request summarises the format differences. In your case, ingress-srv.yaml needs to be changed to:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: ingress-srv
annotations:
kubernetes.io/ingress.class: nginx
spec:
rules:
- host: posts.com
http:
paths:
- path: /posts
pathType: Prefix
backend:
service:
name: posts-clusterip-srv
port:
number: 4000

How can I use Kong’s Capturing Group in Ingress k8s object for rewirting logic?

I want to use Kong’s Capturing Group in Ingress k8s object to perform an uri rewriting.
I want to implement the following logic:
https://kong_host:30000/service/audits/health -> (rewrite) https://kong_host:30000/service/audit/v1/health
Ingress resource:
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: audits
annotations:
konghq.com/plugins: audits-rewrite
spec:
rules:
- http:
paths:
- path: /service/audits/(?<path>\\\S+)
backend:
serviceName: audits
servicePort: 8080
KongPlugin
apiVersion: configuration.konghq.com/v1
kind: KongPlugin
metadata:
name: audits-rewrite
config:
replace:
uri: /service/audit/v1/$(uri_captures["path"])
plugin: request-transformer
Thanks.
As pointed in documentation you are not able to use v1beat1 ingress API version to capture groups in paths.
https://docs.konghq.com/hub/kong-inc/request-transformer/#examples
You need to upgrade you k8s cluster to 1.19 or higher version to use this feature.
I also had similar problem and resolved it will following configuration:
Ingress resource:
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: audits
annotations:
konghq.com/plugins: audits-rewrite
spec:
rules:
- http:
paths:
- path: /service/audits/(.*)
backend:
serviceName: audits
servicePort: 8080
KongPlugin
apiVersion: configuration.konghq.com/v1
kind: KongPlugin
metadata:
name: audits-rewrite
config:
replace:
uri: /service/audit/v1/$(uri_captures[1])
plugin: request-transformer

GCE Ingress error 400 ensureRedirectUrlMap() redirect To Https

I'm using GCE ingress, and I need to redirect all HTTP traffic to HTPPS, I added a custom frontend configuration like the following:
apiVersion: networking.gke.io/v1beta1
kind: FrontendConfig
metadata:
name: frontendconfig
spec:
redirectToHttps:
enabled: true
responseCodeName: MOVED_PERMANENTLY_DEFAULT
I used this configuration in the ingress:
apiVersion: "networking.k8s.io/v1beta1"
kind: "Ingress"
metadata:
name: "api-ingress"
namespace: "default"
annotations:
kubernetes.io/ingress.global-static-ip-name: "STATIC_IP_NAME"
networking.gke.io/managed-certificates: "CERTIFICATE_MANAGER_NAME"
networking.gke.io/v1beta1.FrontendConfig: "frontendconfig"
spec:
rules:
- host: PROJECT_URL
http:
paths:
- path: /*
backend:
serviceName: "api"
servicePort: 3000
But I see in the ingress logs errors:
Error syncing to GCP: error running load balancer syncing routine: loadbalancer lo6kz19c-default-api-ingress-arsturnd does not exist: ensureRedirectUrlMap() = googleapi: Error 400: The url_map resource 'projects/******/global/urlMaps/k8s2-rm-lo6kz19c-default-api-ingress-arsturnd' is already being used by 'projects/******/global/targetHttpProxies/k8s2-tp-lo6kz19c-default-api-ingress-arsturnd', resourceInUseByAnotherResource
Updated: Solved
I found the issue, it was a duplicate entry from ingress in another file.
The issue has been resolved, the error was in the code(duplicate code), I was using another ingress in the same deployment but in another file with the same name of the existing ingress.

traefik ingress custom error in kubernetes

I need to set a custom error in traefik ingress on kubernetes so that when there is no endpoint or when the status is "404", or "[500-600]" it redirects to another error service or another custom error message I used the annotation as it's in the documentation in the ingress file as this (Note: this a helm template output of passing the annotation as a yaml in the values.yaml file)
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: frontend
namespace: "default"
annotations:
external-dns.alpha.kubernetes.io/target: "domain.com"
kubernetes.io/ingress.class: "traefik"
traefik.ingress.kubernetes.io/error-pages: "map[/:map[backend:hello-world status:[502 503]]]"
spec:
rules:
- host: frontend.domain.com
http:
paths:
- backend:
serviceName: frontend
servicePort: 3000
path: /
The answer by ldez is correct, but there are a few caveats:
First off, these annotations only work for traefik >= 1.6.x (earlier versions may support error pages, but not for the kubernetes backend)
Second, the traefik backend must be configured through kubernetes. You cannot create a backend in a config file and use it with kubernetes, at least not in traefik 1.6.x
Here's how the complete thing looks like. foo is just a name, as explained in the other answer, and can be anything:
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: frontend
namespace: "default"
annotations:
external-dns.alpha.kubernetes.io/target: "domain.com"
kubernetes.io/ingress.class: "traefik"
traefik.ingress.kubernetes.io/error-pages: |-
foo:
status:
- "404"
- "500"
# See below on where "error-pages" comes from
backend: error-pages
query: "/{{status}}.html"
spec:
rules:
# This creates an ingress on an non-existing host name,
# which binds to a service. As part of this a traefik
# backend "error-pages" will be created, which is the one
# we use above
- host: error-pages
http:
paths:
- backend:
serviceName: error-pages-service
servicePort: https
- host: frontend.domain.com
http:
# The configuration for your "real" Ingress goes here
# This is the service to back the ingress defined above
# Note that you can use anything for this, including an internal app
# Also: If you use https, the cert on the other side has to be valid
---
kind: Service
apiVersion: v1
metadata:
name: error-pages-service
namespace: default
spec:
ports:
- name: https
port: 443
type: ExternalName
externalName: my-awesome-errors.mydomain.test
If you use this configuration, and your app sends a 404, then https://my-awesome-errors.mydomain.test/404.html would be shown as the error page.
The correct syntax is:
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: frontend
namespace: "default"
annotations:
external-dns.alpha.kubernetes.io/target: "domain.com"
kubernetes.io/ingress.class: "traefik"
traefik.ingress.kubernetes.io/error-pages: |-
foo:
status:
- "404"
backend: bar
query: /bar
fii:
status:
- "500-600"
backend: bar
query: /bir
spec:
rules:
- host: frontend.domain.com
http:
paths:
- backend:
serviceName: frontend
servicePort: 3000
path: /
https://docs.traefik.io/v1.6/configuration/backends/kubernetes/#general-annotations
Note that, currently, the Helm Charts doesn't support this feature.
Ingress does not support that annotations that you guys are using there!
That annotations are supported with Service only, Ingress is using host section.

Defining a fallback service for Kubernetes ingress

Is it possible to have a fallback service for Kubernetes ingresses in the event that none of the normal pods are live/ready? In other words, how would you go about presenting a friendly "website down" page to visitors if all pods crashed or went down somehow?
Right now, a page appears that says "default backend - 404" if that happens.
Here's what we tried, to no avail:
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: example-ingress
spec:
backend:
serviceName: website-down-service
servicePort: 80
rules:
- host: example.com
http:
paths:
- path: /
backend:
serviceName: example-service
servicePort: 80
For reference, we're testing locally with Minikube and deploying to the cloud on Google's Container Engine.
If using Nginx then default backend annotation should do the trick, sample:
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: ingress-name
namespace: your-namespace
annotations:
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/default-backend: fallback-backend
spec:
<your spec here>
For the Nginx Ingress Controller there is a flag --default-backend-service, which currently points to the service showing the "default backend - 404" message. Just replace it with the service you want. See https://github.com/kubernetes/ingress/tree/master/controllers/nginx#command-line-arguments
If you're using another Ingress Controller, I expect it to have a similar option.