<p>I need to declare a long list of ports (in thousands) in both the pod template and the loadbalancer service. I believe there must be a way to do it without repeating the following a thousand times in the yaml. Can someone please shed some lights? Thanks.</p>

<pre><code>- name: containerPort10000
  containerPort: 10000
</code></pre>

<p>Update:
I'm afraid the problem is more complicated now. As I need to expose 10k ports (for connecting devices, using both TCP and UDP), I need to specify the followings in the yaml:</p>

<pre><code>  - targetPort: 10000
    port: 10000
    nodePort: 10000
    name: t10000
    protocol: TCP
  - targetPort: 10000
    port: 10000
    nodePort: 10000
    name: u10000
    protocol: UDP
...
  - targetPort: 20000
    port: 20000
    nodePort: 20000
    name: t20000
    protocol: TCP
  - targetPort: 20000
    port: 20000
    nodePort: 20000
    name: u20000
    protocol: UDP
</code></pre>

<p>and I've hit <code>The Service "svr" is invalid: metadata.annotations: Too long: must have at most 262144 characters</code> error. Please help.</p>

<p>I would go for bash script, but I would like to see other approaches.</p>

<p><code>bash svc.sh | kubectl apply -f -</code></p>

<pre><code>service/multiport created
multiport    LoadBalancer   10.100.63.192    &lt;pending&gt;     1000:32545/TCP,1001:32324/TCP,1002:32559/TCP,1003:31523/TCP,1004:31027/TCP,1005:31671/TCP,1006:31532/TCP,1007:30568/TCP,1008:30105/TCP,1009:32649/TCP   3s
</code></pre>

<p><code>$ cat svc.sh</code></p>

<pre><code>#!/bin/bash
#set -x
BODY=""
for p in `echo {1000..1009}`;do
  BODY=$BODY$(echo -e "\n  - port: $p\n    protocol: TCP\n    targetPort: $p\n    name: tcp$p\n")
done
cat &lt;&lt; TEMPLATE
apiVersion: v1
kind: Service
metadata:
  creationTimestamp: null
  labels:
    run: ubuntu
  name: multiport
spec:
  ports:
  ${BODY}
  selector:
    run: ubuntu
  type: LoadBalancer
status:
  loadBalancer: {}
TEMPLATE
</code></pre>

<p>or you can go for vim macro.</p>
