-1

I'm used following kubernetes API. Configmap is not working with service and loadbalancer.

Here is code -

apiVersion: v1
kind: Service
metadata:
  annotations:
    service.beta.kubernetes.io/azure-load-balancer-resource-group: Resource_group
    valueFrom :
      configMapKeyRef :
        name : app-configmap
        key : Resource_group
  name: appliance-ui
spec:
  loadBalancerIP: Static_public_ip
  valueFrom :
    configMapKeyRef :
      name : app-configmap
      key : Static_public_ip
  type: LoadBalancer
  ports:
  - port: 80
  selector:
    app: appliance-ui

Here is error -

error: error validating "ab.yml": error validating data: [ValidationError(Service.metadata.annotations.valueFrom): invalid type for io.k8s.apimachinery.pkg.apis.meta.v1.ObjectMeta.annotations: got "map", expected "string", ValidationError(Service.spec): unknown field "valueFrom" in io.k8s.api.core.v1.ServiceSpec]; if you choose to ignore these errors, turn validation off with --validate=false

I have tried with --validate=false. It didn't work. Please let me know whether configmap will work for service and loadBalancerIP field or not.

Abhi S
  • 19
  • 4
  • What are you trying to do here? where is your kubernetes cluster being hosted? bare metal? config maps cant be used in services – paltaa Dec 02 '20 at 12:35
  • You might need a tool like Helm or Kustomize to fill in these values at deployment time. – David Maze Dec 02 '20 at 13:34

1 Answers1

1

Unfortunately, you cannot configure a certain value for Service manifest through configMapKeyRef. AFAIK ConfigMap should mount to a Pod(container) for referring the values, so it does not allow other resource except Pod. Refer Configure a Pod to Use a ConfigMap or ConfigMap and Pods for more details.

Daein Park
  • 4,393
  • 2
  • 12
  • 21