Nginx Ingress controller - Error when getting IngressClass nginx

Asking for help? Comment out what you need so we can get more information to help you!

Cluster information:

Kubernetes version: 1.22.1
Cloud being used: bare-metal
Installation method:
Host OS: CentOS
CNI and version:
CRI and version:

I have Kubernetes cluster v1.22.1 set up in bare metal CentOS. I am facing a problem when I am setting up Nginx Ingress controller following the following link

I followed exactly the same in step 1 - 3, but got a CrashLoopBackOff error in nginx ingress controller pod. I checked the logs of the pod and found below

[root@dev1 deployments]# kubectl logs -n nginx-ingress nginx-ingress-5cd5c7549d-hw6l7
I0910 23:15:20.729196       1 main.go:271] Starting NGINX Ingress controller Version=1.12.1 GitCommit=6f72db6030daa9afd567fd7faf9d5fffac9c7c8f Date=2021-09-08T13:39:53Z PlusFlag=false
W0910 23:15:20.770569       1 main.go:310] The '-use-ingress-class-only' flag will be deprecated and has no effect on versions of kubernetes >= 1.18.0. Processing ONLY resources that have the 'ingressClassName' field in Ingress equal to the class.
F0910 23:15:20.774788       1 main.go:314] Error when getting IngressClass nginx: the server could not find the requested resource

I believe I have the IngressClass setup properly as shown in below

[root@dev1 deployments]# kubectl get IngressClass
NAME    CONTROLLER                     PARAMETERS   AGE
nginx   nginx.org/ingress-controller   <none>       2m12s

So I have no idea why it said Error when getting IngressClass nginx. Can anyone shed me some lights please?

Hi, I done the same steps, all running as expected. Logs also looking fine.

Thanks @mohenraj_s. Have you run all the steps from 1 - 3? And did you run Deployment of DeamonSet?

@kinman below are the steps executed. Let me know if this works

root@controlplane:~# git clone https://github.com/nginxinc/kubernetes-ingress/
Cloning into ‘kubernetes-ingress’…
remote: Enumerating objects: 38217, done.
remote: Counting objects: 100% (2156/2156), done.
remote: Compressing objects: 100% (1187/1187), done.
remote: Total 38217 (delta 1220), reused 1566 (delta 874), pack-reused 36061
Receiving objects: 100% (38217/38217), 57.33 MiB | 4.90 MiB/s, done.
Resolving deltas: 100% (21160/21160), done.
Checking out files: 100% (1155/1155), done.
root@controlplane:~# ls
kubernetes-ingress
root@controlplane:~# cd kubernetes-ingress/
root@controlplane:~/kubernetes-ingress# ls
CHANGELOG.md LICENSE build docs go.mod hack perf-tests tools.go
CODE_OF_CONDUCT.md Makefile cmd examples go.sum internal pkg
CONTRIBUTING.md README.md deployments examples-of-custom-resources grafana netlify.toml tests
root@controlplane:~/kubernetes-ingress# cd deployments/
root@controlplane:~/kubernetes-ingress/deployments# ls
README.md common daemon-set deployment helm-chart rbac service
root@controlplane:~/kubernetes-ingress/deployments# git checkout v1.12.1
Note: checking out ‘v1.12.1’.

You are in ‘detached HEAD’ state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:

git checkout -b

HEAD is now at 6f72db60 Release 1.12.1 (#1940)
root@controlplane:~/kubernetes-ingress/deployments# kubectl apply -f common/ns-and-sa.yaml
namespace/nginx-ingress created
serviceaccount/nginx-ingress created
root@controlplane:~/kubernetes-ingress/deployments# kubectl apply -f rbac/rbac.yaml
clusterrole.rbac.authorization.k8s.io/nginx-ingress created
clusterrolebinding.rbac.authorization.k8s.io/nginx-ingress created
root@controlplane:~/kubernetes-ingress/deployments# kubectl apply -f common/default-server-secret.yaml
secret/default-server-secret created
root@controlplane:~/kubernetes-ingress/deployments# ubectl apply -f common/nginx-config.yaml
bash: ubectl: command not found
root@controlplane:~/kubernetes-ingress/deployments# kubectl apply -f common/nginx-config.yaml
configmap/nginx-config created
root@controlplane:~/kubernetes-ingress/deployments# kubectl apply -f common/ingress-class.yaml
Warning: networking.k8s.io/v1beta1 IngressClass is deprecated in v1.19+, unavailable in v1.22+; use networking.k8s.io/v1 IngressClassList
ingressclass.networking.k8s.io/nginx created
root@controlplane:~/kubernetes-ingress/deployments# cd common/crds/
root@controlplane:~/kubernetes-ingress/deployments/common/crds# ls
appprotect.f5.com_aplogconfs.yaml k8s.nginx.org_globalconfigurations.yaml k8s.nginx.org_virtualserverroutes.yaml
appprotect.f5.com_appolicies.yaml k8s.nginx.org_policies.yaml k8s.nginx.org_virtualservers.yaml
appprotect.f5.com_apusersigs.yaml k8s.nginx.org_transportservers.yaml
root@controlplane:~/kubernetes-ingress/deployments/common/crds# k create -f k8s.nginx.org_virtualservers.yaml
bash: k: command not found
root@controlplane:~/kubernetes-ingress/deployments/common/crds# k create -f k8s.nginx.org_virtualservers.yamlcd …/…
bash: k: command not found
root@controlplane:~/kubernetes-ingress/deployments/common/crds# cd …/…
root@controlplane:~/kubernetes-ingress/deployments# kubectl apply -f common/crds/k8s.nginx.org_virtualservers.yaml
customresourcedefinition.apiextensions.k8s.io/virtualservers.k8s.nginx.org created
root@controlplane:~/kubernetes-ingress/deployments# kubectl apply -f common/crds/k8s.nginx.org_virtualserverroutes.yaml
customresourcedefinition.apiextensions.k8s.io/virtualserverroutes.k8s.nginx.org created
root@controlplane:~/kubernetes-ingress/deployments# kubectl apply -f common/crds/k8s.nginx.org_transportservers.yaml
customresourcedefinition.apiextensions.k8s.io/transportservers.k8s.nginx.org created
root@controlplane:~/kubernetes-ingress/deployments# kubectl apply -f common/crds/k8s.nginx.org_policies.yaml
customresourcedefinition.apiextensions.k8s.io/policies.k8s.nginx.org created
root@controlplane:~/kubernetes-ingress/deployments# kubectl apply -f common/crds/k8s.nginx.org_globalconfigurations.yaml
customresourcedefinition.apiextensions.k8s.io/globalconfigurations.k8s.nginx.org created
root@controlplane:~/kubernetes-ingress/deployments# kubectl apply -f common/crds/appprotect.f5.com_aplogconfs.yaml
customresourcedefinition.apiextensions.k8s.io/aplogconfs.appprotect.f5.com created
root@controlplane:~/kubernetes-ingress/deployments# kubectl apply -f common/crds/appprotect.f5.com_appolicies.yaml
customresourcedefinition.apiextensions.k8s.io/appolicies.appprotect.f5.com created
root@controlplane:~/kubernetes-ingress/deployments# kubectl apply -f common/crds/appprotect.f5.com_apusersigs.yaml
customresourcedefinition.apiextensions.k8s.io/apusersigs.appprotect.f5.com created
root@controlplane:~/kubernetes-ingress/deployments# kubectl apply -f deployment/nginx-ingress.yaml
deployment.apps/nginx-ingress created
root@controlplane:~/kubernetes-ingress/deployments# kubectl apply -f daemon-set/nginx-ingress.yaml
daemonset.apps/nginx-ingress created
root@controlplane:~/kubernetes-ingress/deployments# kubectl get pods --namespace=nginx-ingress
NAME READY STATUS RESTARTS AGE
nginx-ingress-77b5c64749-txjjf 1/1 Running 0 24s
nginx-ingress-qk5nz 0/1 Running 0 11s
root@controlplane:~/kubernetes-ingress/deployments# kubectl get pods --namespace=nginx-ingress
NAME READY STATUS RESTARTS AGE
nginx-ingress-77b5c64749-txjjf 1/1 Running 0 35s
nginx-ingress-qk5nz 1/1 Running 0 22s
root@controlplane:~/kubernetes-ingress/deployments# kubectl get IngressClass
NAME CONTROLLER PARAMETERS AGE
nginx nginx.org/ingress-controller 4m51s
root@controlplane:~/kubernetes-ingress/deployments#

Thanks @mohenraj_s . I asked in another channel and there is another person hit the same issue. Turns out it’s related to the cluster version 1.22.1.

The main difference is ingress-class.yaml has networking.k8s.io/v1beta1 in git branch v1.12.1 and networking.k8s.io/v1 in master branch

So, this nginx ingress controller seems not compatible with 1.22.1.

I guess your environment is in an older version and so does not have the problem that I have.