V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
dong706
V2EX  ›  Kubernetes

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

  •  
  •   dong706 · 2023-03-14 11:25:53 +08:00 · 2199 次点击
    这是一个创建于 607 天前的主题,其中的信息可能已经有所发展或是发生改变。

    部署 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 也无解。

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

    4 条回复    2023-03-14 17:13:51 +08:00
    dier
        1
    dier  
       2023-03-14 15:20:28 +08:00
    敏感信息替换一下,把完整的 yaml 发出来看看吧
    dong706
        2
    dong706  
    OP
       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
        3
    dier  
       2023-03-14 15:59:59 +08:00
    你用了一个 hostPort 的配置,这个配置会跟宿主机的端口绑定
    dong706
        4
    dong706  
    OP
       2023-03-14 17:13:51 +08:00
    @dier 大佬太牛逼了,这个细节都注意到了,我一直在想我没配置 nodePort 来着
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   972 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 22ms · UTC 19:21 · PVG 03:21 · LAX 11:21 · JFK 14:21
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.