gpt4 book ai didi

kubernetes:无法从其他机器访问NodePort

转载 作者:行者123 更新时间:2023-12-03 13:18:29 28 4
gpt4 key购买 nike

我正在尝试安装kubernetes。
检查在kubernetes上执行的容器时出现问题。
我将服务类型设置为Nodeport,但是无法从运行容器的节点之外的其他节点访问。
想要从其他计算机访问它,请告诉我它的不同之处。
我尝试了externalIP和LoadBarancer,但这是不可能的。

环保环境

  • 操作系统:Ubuntu 16.04 LTS
  • Kubernetes:1.8
  • Docker:17.09.0-ce
  • etcd:3.2.8
  • 绒布:0.9.0

  • 网络
  • 物理:10.1.1.0/24
  • 法兰绒:172.16.0.0/16
  • docker :192.168.0.0/16

  • 机器
  • 主节点(2个节点):10.1.1.24,10.1.1.25
  • 工作节点(2nodes):10.1.1.26,10.1.1.27

  • kubectl描述svc nginx集群
    Name:              nginx-cluster
    Namespace: default
    Labels: app=nginx-demo
    Annotations: <none>
    Selector: app=nginx-demo
    Type: ClusterIP
    IP: 172.16.236.159
    Port: <unset> 8090/TCP
    TargetPort: 80/TCP
    Endpoints: 192.168.24.2:80
    Session Affinity: None
    Events: <none>

    kubectl描述svc nginx服务
    Name:                     nginx-service
    Namespace: default
    Labels: app=nginx-demo
    Annotations: <none>
    Selector: app=nginx-demo
    Type: NodePort
    IP: 172.16.199.69
    Port: <unset> 8090/TCP
    TargetPort: 80/TCP
    NodePort: <unset> 31659/TCP
    Endpoints: 192.168.24.2:80
    Session Affinity: None
    External Traffic Policy: Cluster
    Events: <none>

    运行容器工作程序节点(10.1.1.27)

    curl 10.1.1.27:31659
    <!DOCTYPE html>
    <html>
    <head>
    <title>Welcome to nginx!</title>
    ...

    工作节点(10.1.1.26)

    curl 10.1.1.27:31659
    curl: (7) Failed to connect to 10.1.1.27 port 31659:Connection timed out.

    其他机器(10.1.1.XX)

    curl 10.1.1.27:31659
    curl: (7) Failed to connect to 10.1.1.27 port 31659:Connection timed out.

    kubectl得到 pod -o宽
    NAME                          READY     STATUS    RESTARTS   AGE       IP             NODE
    echoserver-848b75d85-9fx7r 1/1 Running 3 6d 192.168.70.2 k8swrksv01
    nginx-demo-85cc49574c-wv2b9 1/1 Running 3 6d 192.168.2.2 k8swrksv02

    kubectl获取svc -o宽
    NAME            TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)          AGE       SELECTOR
    clusterip ClusterIP 172.16.39.77 <none> 80/TCP 6d run=echoserver
    kubernetes ClusterIP 172.16.0.1 <none> 443/TCP 10d <none>
    nginx-cluster ClusterIP 172.16.236.159 <none> 8090/TCP 6d app=nginx-demo
    nginx-service NodePort 172.16.199.69 <none> 8090:31659/TCP 6d app=nginx-demo
    nodeport NodePort 172.16.38.40 <none> 80:31317/TCP 6d run=echoserver

    netstat -ntlp
    tcp        0      0 127.0.0.1:10248         0.0.0.0:*               LISTEN      1963/kubelet
    tcp 0 0 127.0.0.1:10249 0.0.0.0:* LISTEN 2202/kube-proxy
    tcp 0 0 127.0.0.1:4243 0.0.0.0:* LISTEN 1758/dockerd
    tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 996/sshd
    tcp6 0 0 :::4194 :::* LISTEN 1963/kubelet
    tcp6 0 0 :::10250 :::* LISTEN 1963/kubelet
    tcp6 0 0 :::31659 :::* LISTEN 2202/kube-proxy
    tcp6 0 0 :::10255 :::* LISTEN 1963/kubelet
    tcp6 0 0 :::10256 :::* LISTEN 2202/kube-proxy
    tcp6 0 0 :::31317 :::* LISTEN 2202/kube-proxy
    tcp6 0 0 :::22 :::* LISTEN 996/sshd

    iptables保存
    *nat
    :PREROUTING ACCEPT [0:0]
    :INPUT ACCEPT [0:0]
    :OUTPUT ACCEPT [0:0]
    :POSTROUTING ACCEPT [0:0]
    :DOCKER - [0:0]
    :KUBE-MARK-DROP - [0:0]
    :KUBE-MARK-MASQ - [0:0]
    :KUBE-NODEPORTS - [0:0]
    :KUBE-POSTROUTING - [0:0]
    :KUBE-SEP-AZ4EGFEAU4RTSLJO - [0:0]
    :KUBE-SEP-C7HQKKO26GIFOZZM - [0:0]
    :KUBE-SEP-EWKNS2YCPXGJCXDC - [0:0]
    :KUBE-SEP-LQVPUPFGW6BWATIP - [0:0]
    :KUBE-SEP-OMMOFZ27GPKZ4OPA - [0:0]
    :KUBE-SEP-UD3HOGDD5NDLNY74 - [0:0]
    :KUBE-SERVICES - [0:0]
    :KUBE-SVC-CQNAS6RSUGJF2C2D - [0:0]
    :KUBE-SVC-GKN7Y2BSGW4NJTYL - [0:0]
    :KUBE-SVC-NPX46M4PTMTKRN6Y - [0:0]
    :KUBE-SVC-XP7QDA4CRQ2QA33W - [0:0]
    :KUBE-SVC-Z5P6OMNAEVLAQUTS - [0:0]
    -A PREROUTING -m comment --comment "kubernetes service portals" -j KUBE-SERVICES
    -A PREROUTING -m addrtype --dst-type LOCAL -j DOCKER
    -A OUTPUT -m comment --comment "kubernetes service portals" -j KUBE-SERVICES
    -A OUTPUT ! -d 127.0.0.0/8 -m addrtype --dst-type LOCAL -j DOCKER
    -A POSTROUTING -m comment --comment "kubernetes postrouting rules" -j KUBE-POSTROUTING
    -A POSTROUTING -s 192.168.2.0/24 ! -o docker0 -j MASQUERADE
    -A POSTROUTING -s 192.168.0.0/16 -d 192.168.0.0/16 -j RETURN
    -A POSTROUTING -s 192.168.0.0/16 ! -d 224.0.0.0/4 -j MASQUERADE
    -A POSTROUTING ! -s 192.168.0.0/16 -d 192.168.2.0/24 -j RETURN
    -A POSTROUTING ! -s 192.168.0.0/16 -d 192.168.0.0/16 -j MASQUERADE
    -A DOCKER -i docker0 -j RETURN
    -A KUBE-MARK-DROP -j MARK --set-xmark 0x8000/0x8000
    -A KUBE-MARK-MASQ -j MARK --set-xmark 0x4000/0x4000
    -A KUBE-NODEPORTS -p tcp -m comment --comment "default/nginx-service:" -m tcp --dport 31659 -j KUBE-MARK-MASQ
    -A KUBE-NODEPORTS -p tcp -m comment --comment "default/nginx-service:" -m tcp --dport 31659 -j KUBE-SVC-GKN7Y2BSGW4NJTYL
    -A KUBE-NODEPORTS -p tcp -m comment --comment "default/nodeport:" -m tcp --dport 31317 -j KUBE-MARK-MASQ
    -A KUBE-NODEPORTS -p tcp -m comment --comment "default/nodeport:" -m tcp --dport 31317 -j KUBE-SVC-XP7QDA4CRQ2QA33W
    -A KUBE-POSTROUTING -m comment --comment "kubernetes service traffic requiring SNAT" -m mark --mark 0x4000/0x4000 -j MASQUERADE
    -A KUBE-SEP-AZ4EGFEAU4RTSLJO -s 192.168.70.2/32 -m comment --comment "default/clusterip:" -j KUBE-MARK-MASQ
    -A KUBE-SEP-AZ4EGFEAU4RTSLJO -p tcp -m comment --comment "default/clusterip:" -m tcp -j DNAT --to-destination 192.168.70.2:8080
    -A KUBE-SEP-C7HQKKO26GIFOZZM -s 192.168.70.2/32 -m comment --comment "default/nodeport:" -j KUBE-MARK-MASQ
    -A KUBE-SEP-C7HQKKO26GIFOZZM -p tcp -m comment --comment "default/nodeport:" -m tcp -j DNAT --to-destination 192.168.70.2:8080
    -A KUBE-SEP-EWKNS2YCPXGJCXDC -s 10.1.1.25/32 -m comment --comment "default/kubernetes:https" -j KUBE-MARK-MASQ
    -A KUBE-SEP-EWKNS2YCPXGJCXDC -p tcp -m comment --comment "default/kubernetes:https" -m recent --set --name KUBE-SEP-EWKNS2YCPXGJCXDC --mask 255.255.255.255 --rsource -m tcp -j DNAT --to-destination 10.1.1.25:6443
    -A KUBE-SEP-LQVPUPFGW6BWATIP -s 192.168.2.2/32 -m comment --comment "default/nginx-service:" -j KUBE-MARK-MASQ
    -A KUBE-SEP-LQVPUPFGW6BWATIP -p tcp -m comment --comment "default/nginx-service:" -m tcp -j DNAT --to-destination 192.168.2.2:80
    -A KUBE-SEP-OMMOFZ27GPKZ4OPA -s 10.1.1.24/32 -m comment --comment "default/kubernetes:https" -j KUBE-MARK-MASQ
    -A KUBE-SEP-OMMOFZ27GPKZ4OPA -p tcp -m comment --comment "default/kubernetes:https" -m recent --set --name KUBE-SEP-OMMOFZ27GPKZ4OPA --mask 255.255.255.255 --rsource -m tcp -j DNAT --to-destination 10.1.1.24:6443
    -A KUBE-SEP-UD3HOGDD5NDLNY74 -s 192.168.2.2/32 -m comment --comment "default/nginx-cluster:" -j KUBE-MARK-MASQ
    -A KUBE-SEP-UD3HOGDD5NDLNY74 -p tcp -m comment --comment "default/nginx-cluster:" -m tcp -j DNAT --to-destination 192.168.2.2:80
    -A KUBE-SERVICES -d 172.16.236.159/32 -p tcp -m comment --comment "default/nginx-cluster: cluster IP" -m tcp --dport 8090 -j KUBE-SVC-Z5P6OMNAEVLAQUTS
    -A KUBE-SERVICES -d 172.16.199.69/32 -p tcp -m comment --comment "default/nginx-service: cluster IP" -m tcp --dport 8090 -j KUBE-SVC-GKN7Y2BSGW4NJTYL
    -A KUBE-SERVICES -d 172.16.38.40/32 -p tcp -m comment --comment "default/nodeport: cluster IP" -m tcp --dport 80 -j KUBE-SVC-XP7QDA4CRQ2QA33W
    -A KUBE-SERVICES -d 172.16.39.77/32 -p tcp -m comment --comment "default/clusterip: cluster IP" -m tcp --dport 80 -j KUBE-SVC-CQNAS6RSUGJF2C2D
    -A KUBE-SERVICES -d 172.16.0.1/32 -p tcp -m comment --comment "default/kubernetes:https cluster IP" -m tcp --dport 443 -j KUBE-SVC-NPX46M4PTMTKRN6Y
    -A KUBE-SERVICES -m comment --comment "kubernetes service nodeports; NOTE: this must be the last rule in this chain" -m addrtype --dst-type LOCAL -j KUBE-NODEPORTS
    -A KUBE-SVC-CQNAS6RSUGJF2C2D -m comment --comment "default/clusterip:" -j KUBE-SEP-AZ4EGFEAU4RTSLJO
    -A KUBE-SVC-GKN7Y2BSGW4NJTYL -m comment --comment "default/nginx-service:" -j KUBE-SEP-LQVPUPFGW6BWATIP
    -A KUBE-SVC-NPX46M4PTMTKRN6Y -m comment --comment "default/kubernetes:https" -m recent --rcheck --seconds 10800 --reap --name KUBE-SEP-OMMOFZ27GPKZ4OPA --mask 255.255.255.255 --rsource -j KUBE-SEP-OMMOFZ27GPKZ4OPA
    -A KUBE-SVC-NPX46M4PTMTKRN6Y -m comment --comment "default/kubernetes:https" -m recent --rcheck --seconds 10800 --reap --name KUBE-SEP-EWKNS2YCPXGJCXDC --mask 255.255.255.255 --rsource -j KUBE-SEP-EWKNS2YCPXGJCXDC
    -A KUBE-SVC-NPX46M4PTMTKRN6Y -m comment --comment "default/kubernetes:https" -m statistic --mode random --probability 0.50000000000 -j KUBE-SEP-OMMOFZ27GPKZ4OPA
    -A KUBE-SVC-NPX46M4PTMTKRN6Y -m comment --comment "default/kubernetes:https" -j KUBE-SEP-EWKNS2YCPXGJCXDC
    -A KUBE-SVC-XP7QDA4CRQ2QA33W -m comment --comment "default/nodeport:" -j KUBE-SEP-C7HQKKO26GIFOZZM
    -A KUBE-SVC-Z5P6OMNAEVLAQUTS -m comment --comment "default/nginx-cluster:" -j KUBE-SEP-UD3HOGDD5NDLNY74
    COMMIT
    *filter
    :INPUT ACCEPT [40:14606]
    :FORWARD DROP [0:0]
    :OUTPUT ACCEPT [42:6275]
    :DOCKER - [0:0]
    :DOCKER-ISOLATION - [0:0]
    :DOCKER-USER - [0:0]
    :KUBE-FIREWALL - [0:0]
    :KUBE-SERVICES - [0:0]
    -A INPUT -m comment --comment "kubernetes service portals" -j KUBE-SERVICES
    -A INPUT -j KUBE-FIREWALL
    -A FORWARD -j DOCKER-USER
    -A FORWARD -j DOCKER-ISOLATION
    -A FORWARD -o docker0 -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
    -A FORWARD -o docker0 -j DOCKER
    -A FORWARD -i docker0 ! -o docker0 -j ACCEPT
    -A FORWARD -i docker0 -o docker0 -j ACCEPT
    -A OUTPUT -m comment --comment "kubernetes service portals" -j KUBE-SERVICES
    -A OUTPUT -j KUBE-FIREWALL
    -A DOCKER-ISOLATION -j RETURN
    -A DOCKER-USER -j RETURN
    -A KUBE-FIREWALL -m comment --comment "kubernetes firewall for dropping marked packets" -m mark --mark 0x8000/0x8000 -j DROP
    COMMIT

    最佳答案

    它是由FORWARD链上的默认DROP引起的(这又是由docker引起的)。

    如果将iptables -A FORWARD -j ACCEPT规则添加到节点,则可以看到它再次正常工作。

    k8s的问题在这里:https://github.com/kubernetes/kubernetes/issues/39823,但实际的解决方法在这里https://github.com/kubernetes/kubernetes/pull/52569(预期在1.9中)。

    关于kubernetes:无法从其他机器访问NodePort,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46667659/

    28 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com