RMNull
RMNull

Reputation: 209

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

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?

Upvotes: 6

Views: 8338

Answers (3)

chirag sharma
chirag sharma

Reputation: 1

Try as below inside annotations:

   apiVersion: v1
   metadata:
     name: ingress-nginx
     namespace: ingress-nginx
     labels:
       app.kubernetes.io/name: ingress-nginx
       app.kubernetes.io/part-of: ingress-nginx
     annotations:
       service.beta.kubernetes.io/oci-load-balancer-internal: "true"
       service.beta.kubernetes.io/oci-load-balancer-subnet1: "ocid1.subnet.oc1.iad.xxxxxxxxxxxxxxxxx"
   spec:
     type: LoadBalancer
     selector:
       app.kubernetes.io/name: ingress-nginx
       app.kubernetes.io/part-of: ingress-nginx
     ports:
       - name: http
         port: 80
         targetPort: http
       - name: https
         port: 443
         targetPort: https

Upvotes: 0

ton
ton

Reputation: 4597

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

Upvotes: 0

webofmars
webofmars

Reputation: 1737

As far as i know there is no solution for that. The names of object in Kubernetes (and your annotation will create an object with the given name) should be DNS RFC complaint which is < 63 chars in the hostname part.

sources :

Upvotes: 1

Related Questions