kubectl apply does not allow more than 63 chars on metadata.labels values

Viewed 2864

I'm trying to create a LoadBalancer in my OKE cluster(Oracle Cloud Container Engine for Kubernetes). I'm doing a kubectl apply -f on the file, but it gives me this error.

The Service "servicename" is invalid: metadata.labels: Invalid value: "ocid1.vcn.oc1.iad.xx...xx": must be no more than 63 characters.

Here's the yaml file

apiVersion: v1
kind: Service
metadata:
  name: my-nginx-svc
  labels:
    app: nginx
  annotations:
    service.beta.kubernetes.io/oci-load-balancer-internal: "true"
    service.beta.kubernetes.io/oci-load-balancer-subnet1: "ocid1.subnet.oc1..aaaaaa...xxxxx"
spec:
  type: LoadBalancer
  ports:
  - port: 8100
  selector:
    app: nginx

I see the issue is because the value for service.beta.kubernetes.io/oci-load-balancer-subnet1: is more than 63 chars. But I can't change the value of the OCID. Is there a fix for this?

2 Answers

metadata.labels structure has that < 63 values length limit but metadata.annotations struct does not have it. Note that k8s uses metadata.annotation to store the full JSON with last applied configuration at key(kubectl.kubernetes.io/last-applied-configuration) and that almost always exceeds that limit of 63 bytes.

I had this issue when putting OCID values on label values, but NOT when using the annotation values, as you quote.

For example, this will NOT work:

apiVersion: v1
kind: Service
metadata:
  name: my-nginx-svc
  labels:
    app: nginx
    service.beta.kubernetes.io/oci-load-balancer-internal: "true"
    service.beta.kubernetes.io/oci-load-balancer-subnet1: "ocid1.subnet.oc1..aaaaaa...xxxxx"
spec:
   ...

But this is expected to work:

apiVersion: v1
kind: Service
metadata:
  name: my-nginx-svc
  labels:
    app: nginx
  annotations:
    service.beta.kubernetes.io/oci-load-balancer-internal: "true"
    service.beta.kubernetes.io/oci-load-balancer-subnet1: "ocid1.subnet.oc1..aaaaaa...xxxxx"
spec:
   ...

So, If you having this problem I do suggest to double check if you are really using the correct structure, as you quote.

https://docs.oracle.com/en-us/iaas/Content/ContEng/Tasks/contengcreatingloadbalancer.htm#Creating2

Related