Get an error 'unknown field "data"' when try to deploy an Ingress object to a kube cluster

4/21/2021

Here is the config of the Ingress object:

apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: test-ingress
  labels:
    app: test-ingress
  annotations:
    nginx.ingress.kubernetes.io/proxy-body-size: 1024m
    nginx.ingress.kubernetes.io/proxy-read-timeout: 5000
    nginx.ingress.kubernetes.io/session-cookie-conditional-samesite-none: "true"
    nginx.ingress.kubernetes.io/rewrite-target: /
data:
  proxy-hide-headers: "Server"
  server-tokens: "False"
spec:
  rules:
      ...

When I do kubectl apply to create this Ingress I got the next error:

Error: unable to build kubernetes objects from release manifest: error validating "": error validating data: ValidationError(Ingress): unknown field "data" in io.k8s.api.networking.v1beta1.Ingress

The cluster version is 1.21.0.

After a long search in google didn't find any clue why this error can happen, didn't find any deprecation of this field. Please help.

-- Kirill Liubun
kubernetes
kubernetes-ingress

2 Answers

4/21/2021

So looking by error it says that apiversion (networking.k8s.io/v1beta1) you mentioned in yaml file is unable to identify the object data.

It looks like policies version has been changed from v1beta1 to v1. could you verify the version you have or change it to v1 and try. Ref: https://kubernetes.io/docs/concepts/services-networking/network-policies/

Thanks

-- Vinod
Source: StackOverflow

4/21/2021

data is an invalid object for the api-resource ingress.

data:
  proxy-hide-headers: "Server"
  server-tokens: "False"

remove the above fields and try to add them via a configmap for the ingress. configmap.yaml

apiVersion: v1
data:
  proxy-hide-headers: "Server"
  server-tokens: "False"
kind: ConfigMap
metadata:
  name: test-ingress-cm

And configure your pod to mount the nginx configmap. To know the allowed objects always run kubectl explain api-resource eg: kubectl explain ingress.

More details on custom configuration can be found in kubernetes.github.io site.

-- vijay
Source: StackOverflow