Kubernetes 如何声明一长串端口(以千为单位)?(超过262144个字符)
我需要在pod模板和loadbalancer服务中声明一长串端口(以千为单位)。我相信一定有办法做到这一点,而不必在yaml中重复下面的一千次。谁能帮我点灯吗?谢谢Kubernetes 如何声明一长串端口(以千为单位)?(超过262144个字符),kubernetes,Kubernetes,我需要在pod模板和loadbalancer服务中声明一长串端口(以千为单位)。我相信一定有办法做到这一点,而不必在yaml中重复下面的一千次。谁能帮我点灯吗?谢谢 - name: containerPort10000 containerPort: 10000 更新: 恐怕现在问题更复杂了。由于我需要公开10k端口(用于连接设备,使用TCP和UDP),我需要在yaml中指定以下内容: - targetPort: 10000 port: 10000 nodePort: 1
- name: containerPort10000
containerPort: 10000
更新:
恐怕现在问题更复杂了。由于我需要公开10k端口(用于连接设备,使用TCP和UDP),我需要在yaml中指定以下内容:
- 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
我点击了
服务“svr”无效:元数据。注释:太长:最多只能包含262144个字符错误。请帮助。我会选择bash脚本,但我希望看到其他方法
bash svc.sh|kubectl apply-f-
service/multiport created
multiport LoadBalancer 10.100.63.192 <pending> 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
或者你可以选择vim宏
#!/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 << TEMPLATE
apiVersion: v1
kind: Service
metadata:
creationTimestamp: null
labels:
run: ubuntu
name: multiport
spec:
ports:
${BODY}
selector:
run: ubuntu
type: LoadBalancer
status:
loadBalancer: {}
TEMPLATE