启动副本报错 3 node(s) didn't have free ports for the requested pod ports

2023-03-14 11:25:53 +08:00
 dong706

部署 statefulset 时提示: 0/3 nodes are available: 3 node(s) didn't have free ports for the requested pod ports. preemption: 0/3 nodes are available: 3 No preemption victims found for incoming pod

Service.yaml 如下:

ports:
- name: redis-port
port: 7001
protocol: TCP
targetPort: 7001

背景:一共 3 个节点,master+node1+node2

现象:前三个副本都正常(分别在三个节点上),启动第四个节点时就报错“0/3 nodes are available: 3 node(s) didn't have free ports for the requested pod ports. preemption: 0/3 nodes are available: 3 No preemption victims found for incoming pod”。

分析:看了下 Service 的 yaml ,我并没有配置 nodePort,所以理论上一个节点上可以部署多个相同 pod 。但是现在直接提示闲置端口数量不足~~~百思不得其解,本来就是新部署的 k8s 集群,没几个 pod ,不至于端口数量不对。google 也无解。

求大佬们解惑,不胜感激~~~

1863 次点击
所在节点    Kubernetes
4 条回复
dier
2023-03-14 15:20:28 +08:00
敏感信息替换一下,把完整的 yaml 发出来看看吧
dong706
2023-03-14 15:48:37 +08:00
```
---
apiVersion: v1
kind: Namespace
metadata:
name: cssp-cloud-component
---
apiVersion: v1
kind: ConfigMap
metadata:
name: redis-config
namespace: cssp-cloud-component
data:
update-node.sh: |
#!/bin/sh
REDIS_NODES="/data/nodes.conf"
sed -i -e "/myself/ s/[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}/${MY_POD_IP}/" ${REDIS_NODES}
exec "$@"
redis.conf: |+
port 7001
protected-mode no
cluster-enabled yes
cluster-config-file nodes.conf
cluster-node-timeout 15000
#cluster-announce-ip ${MY_POD_IP}
#cluster-announce-port 7001
#cluster-announce-bus-port 17001
logfile "/data/redis.log"
---
```

```
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
labels:
app: redis-cluster
name: redis-cluster
namespace: default-component
spec:
replicas: 2
selector:
matchLabels:
app: redis-cluster
serviceName: redis-cluster
template:
metadata:
labels:
app: redis-cluster
spec:
containers:
- command:
["/bin/bash", "/usr/local/etc/redis/update-node.sh", "redis-server", "/usr/local/etc/redis/redis.conf"]
#args:
# - /usr/local/etc/redis/redis.conf
# - --cluster-announce-ip
# - "$(MY_POD_IP)"
env:
- name: MY_POD_IP
valueFrom:
fieldRef:
fieldPath: status.podIP
- name: TZ
value: Asia/Shanghai
image: 'redis:6.0.10'
imagePullPolicy: IfNotPresent
name: redis
ports:
- containerPort: 7001
hostPort: 7001
name: redis-port
protocol: TCP
volumeMounts:
- mountPath: /data
name: redis-cluster-data
subPath: data
readOnly: false
- mountPath: /usr/local/etc/redis
name: redis-config
readOnly: false
dnsPolicy: ClusterFirst
volumes:
- name: redis-config
configMap:
name: redis-config
volumeClaimTemplates:
- metadata:
name: redis-cluster-data
namespace: default-component
spec:
storageClassName: "default-storage-class"
accessModes: ["ReadWriteMany"]
resources:
requests:
storage: 1Gi
---
apiVersion: v1
kind: Service
metadata:
labels:
app: redis-cluster
name: redis-cluster
namespace: default-component
spec:
ports:
- name: redis-port
port: 7001
protocol: TCP
targetPort: 7001
selector:
app: redis-cluster
type: ClusterIP
clusterIP: None
```

@dier 其实没有敏感信息,就是部署 redis 集群时碰到的莫名其妙的错误...上面就是全部的脚本
dier
2023-03-14 15:59:59 +08:00
你用了一个 hostPort 的配置,这个配置会跟宿主机的端口绑定
dong706
2023-03-14 17:13:51 +08:00
@dier 大佬太牛逼了,这个细节都注意到了,我一直在想我没配置 nodePort 来着

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/923838

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX