kubeval
kubeval copied to clipboard
invalid service/deployment name passes kubeval
I ran a yaml file through kubeval and didn't get any errors. Later when I tried to apply the config to Minikube I got the below
Error from server (Invalid): error when creating "kubernetes.yaml": Service "Foo" is invalid: metadata.name: Invalid value: "Foo": a DNS-1035 label must consist of lower case alphanumeric characters or '-', start with an alphabetic character, and end with an alphanumeric character (e.g. 'my-name', or 'abc-123', regex used for validation is '[a-z]([-a-z0-9]*[a-z0-9])?')
Error from server (Invalid): error when creating "kubernetes.yaml": Deployment.apps "Bar" is invalid: metadata.name: Invalid value: "Bar": a DNS-1123 subdomain must consist of lower case alphanumeric characters, '-' or '.', and must start and end with an alphanumeric character (e.g. 'example.com', regex used for validation is '[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*')
Changing the service/deployment 'metadata' > 'name'
per the errors allowed me to apply the yaml file to Minikube.
Kubeval should check service/deployment configurations against the regex listed in the above error.
Could you include a failing definition file? I'll take a look at where this is failing.
kubeval relies exclusively on the Kubernetes OpenAPI descriptions, which might mean this information is missing from those. Or it could be a different local bug.
Sure. Below is a failing definition file. "CapitalName" and "underscore_name" are the source of the errors in this example.
apiVersion: v1
kind: Service
metadata:
name: CapitalName
labels:
app: CapitalName
spec:
selector:
app: Invalid_App
type: LoadBalancer
---
apiVersion: v1
kind: Service
metadata:
name: underscore_name
labels:
app: underscore_name
spec:
selector:
app: underscore_name
type: LoadBalancer
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name:
labels:
app: Invalid_App
spec:
template:
metadata:
labels:
app: Invalid_App
spec:
containers:
- name: CapitalName
image: CapitalImage
imagePullPolicy: Always
- name: underscore_name
image: underscore_image
imagePullPolicy: Always