如何设置service-node-port-range,然后能够使用新的端口范围部署服务?

时间:2019-02-18 17:51:35

标签: kubernetes service-node-port-range

我要求测试服务器使用端口范围20000-22767

我用命令编辑了kubeadm-config

kubectl edit cm kubeadm-config -n kube-system

当我查看结果时,我发现更改似乎已经存储:

$ kubeadm config view命令给了我

apiServer:
  extraArgs:
    authorization-mode: Node,RBAC
    service-node-port-range: 20000-22767
  timeoutForControlPlane: 4m0s
apiVersion: kubeadm.k8s.io/v1beta1
certificatesDir: /etc/kubernetes/pki
clusterName: kubernetes
controlPlaneEndpoint: ""
controllerManager: {}
dns:
  type: CoreDNS
etcd:
  local:
    dataDir: /var/lib/etcd
imageRepository: k8s.gcr.io
kind: ClusterConfiguration
kubernetesVersion: v1.13.3
networking:
  dnsDomain: cluster.local
  podSubnet: 10.244.0.0/16
  serviceSubnet: 10.96.0.0/12
scheduler: {}

但是当我以后尝试在新端口范围内安装某些东西时,会出现错误

helm upgrade --install --kubeconfig /external-storage/workspace/potapi-orchestration/clusters/at/admin.conf potapi-services charts/potapi-services -f charts/potapi-services/values.at.yaml
Error: UPGRADE FAILED: Service "potapi-services" is invalid: spec.ports[0].nodePort: Invalid value: 21011: provided port is not in the valid range. The range of valid ports is 30000-32767

我在这里摆弄了建议,但没有运气:https://github.com/kubernetes/kubeadm/issues/122

2 个答案:

答案 0 :(得分:1)

可以从默认值更新service-node-port-range

我用/etc/kubernetes/manifests/kube-apiserver.yaml更新了文件--service-node-port-range=20000-22767

apiserver已重新启动,并且端口范围已更新。

我为此写了blog post

答案 1 :(得分:0)

我也找不到关于kubeadm配置的任何文档。以下对我有用:

# your current k8s version
KUBE_VERSION=v1.14.1
KUBEADM_CONFIG=kubeadm-config.yaml

# save current kubeadm config
kubeadm config view > $KUBEADM_CONFIG

# add desired port range
vi kubeadm-config.yaml

  apiServer:
    extraArgs:
      authorization-mode: Node,RBAC
+       service-node-port-range: 20000-22767

# save kubeadm config into a configmap
kubeadm config upload from-file --config $KUBEADM_CONFIG

# check changes
sudo kubeadm upgrade diff --config $KUBEADM_CONFIG

# apply changes
sudo kubeadm upgrade apply $KUBE_VERSION --config $KUBEADM_CONFIG