Q:

Kubernetes - specify externalips in configmap

I have a Kubernetes cluster (external ips: 1.2.3.4, 2.3.4.5, 3.4.5.6)
I want to host a docker registry on this cluster on port 5000. Now to enable this I did a test with externalips, which works. This makes nginx available on port 85.
apiVersion: v1
kind: Service
metadata:
  name: nginx-extip
spec:
  type: ClusterIP
  ports:
  - name: http
    protocol: TCP
    port: 85
    targetPort: 80
  selector:
    app: nginx-extip
  externalIPs:
  - 1.2.3.4
  - 2.3.4.5
  - 3.4.5.6
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: nginx-extip
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: nginx-extip
    spec:
      containers:
      - name: nginx-extip-server
        image: nginx
        ports:
        - containerPort: 80

Now to reuse the externalip config I want to put this into a configmap. So all yamls can just reference the configmap and we don't have to manually update the externalips when they change. How can I put an array of ips into the configmap?
My current (not working) configmap:
apiVersion: v1
kind: ConfigMap
metadata:
  name: externalips
  namespace: default
data:
  externalips:
  - 1.2.3.4
  - 2.3.4.5
  - 3.4.5.6

The error I get:
error: error validating "static-ips-configmap.yml": error validating data: 
ValidationError(ConfigMap.data.externalips): invalid type for
io.k8s.api.core.v1.ConfigMap.data: got "array", expected "string";
if you choose to ignore these errors, turn validation off with --validate=false

How can I put these IP's into a configmap?

A:

There are two problems here:

There is a syntax error in the creation of the configmap itself. Config map expects you to list a bunch of files and their contents, so the correct syntax would look something like this:
apiVersion: v1
kind: ConfigMap
metadata:
  name: externalips
  namespace: default
data:
  external-ips.list: |
    externalips:
    - 1.2.3.4
    - 2.3.4.5
    - 3.4.5.6

I don't think it's possible to refer to a configmap that you created to template a service spec. So even if you managed to create the configmap correctly, you still wouldn't be able to reuse it as part of different service definitions.

You need an out-of-band templating system that you can use to add these external IPs to services. Alternatively, use an ingress control, that you have to configure with external IPs once and then use it to multiplex all your HTTP services inside the cluster. This way you manage IPs for only one service anyway.

A:

ffledgling's answer is correct, but I think "external-ips.list" confuses a little bit.
This is what should look like the configmap yaml file:
apiVersion: v1
kind: ConfigMap
metadata:
  name: externalips
  namespace: default
data:
  externalips: |
    ips:
    - 1.2.3.4
    - 2.3.4.5
    - 3.4.5.6

So, "externalips", "ips", "external-ips.list" can be anything as those are just keys.

