V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
root01

创建了 svc 无法访问

  •  
  •   root01 · May 4, 2021 · 2278 views
    This topic created in 1828 days ago, the information mentioned may be changed or developed.
    test-nginx.yaml
    ```
    apiVersion: apps/v1
    kind: Deployment
    metadata:
    name: test-nginx
    spec:
    replicas: 2
    selector:
    matchLabels:
    app: test-nginx
    template:
    metadata:
    labels:
    app: test-nginx
    spec:
    containers:
    - name: web
    image: nginx:1.8
    imagePullPolicy: IfNotPresent
    ports:
    - containerPort: 80
    ```
    test-nginx-svc.yaml
    ```
    apiVersion: v1
    kind: Service
    metadata:
    name: test-nginx
    labels:
    app: tets-nginx
    spec:
    selector:
    app: test-nginx
    type: NodePort
    ports:
    - port: 80
    protocol: TCP
    name: web
    targetPort: http
    nodePort: 31180


    ```
    netstat -ntlp |grep 31180
    tcp 0 0 0.0.0.0:31180 0.0.0.0:* LISTEN 4057/kube-proxy

    ### 显示已经成功了 ,pod 也是 running 状态
    ### 访问节点:192.168.145.146:31180 (wget/curl 都无法访问)
    ### 之前已经部署了 kubesphere,也是可以访问的,端口不冲突,请问该怎么排查?
    # kubectl get pod -l app=test-nginx
    NAME READY STATUS RESTARTS AGE
    test-nginx-55546c8c-42r5n 1/1 Running 0 13m
    test-nginx-55546c8c-5gqk5 1/1 Running 0 13m
    Supplement 1  ·  May 4, 2021
    kubectl get pod -l app=test-nginx
    NAME READY STATUS RESTARTS AGE
    test-nginx-9fdb9855d-5k264 1/1 Running 0 7m9s
    test-nginx-9fdb9855d-jz4pt 1/1 Running 0 7m11s

    kubectl get svc -l app=test-nginx
    NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
    test-nginx NodePort 10.99.78.120 <none> 80:31080/TCP 2m50s
    Supplement 2  ·  May 4, 2021
    解决了,targetPort 设置为 80 端口就可以了
    谢谢各位
    root01
        1
    root01  
    OP
       May 4, 2021
    已经修正两个 YAML 文件中的 labels=test-nginx
    root01
        2
    root01  
    OP
       May 4, 2021
    但是仍无法访问
    SignLeung
        3
    SignLeung  
       May 4, 2021
    可以 curl podIP:containerPort 看看能不能访问
    root01
        4
    root01  
    OP
       May 4, 2021
    @SignLeung
    # nslookup shun-nginx
    Server: 10.96.0.10
    Address 1: 10.96.0.10 kube-dns.kube-system.svc.cluster.local

    Name: shun-nginx
    Address 1: 10.104.210.29 shun-nginx.default.svc.cluster.local
    / # wget shun-nginx
    Connecting to shun-nginx (10.104.210.29:80)
    wget: can't connect to remote host (10.104.210.29): Connection refused
    root01
        5
    root01  
    OP
       May 4, 2021
    @SignLeung busybox 没 curl emmm
    freezex
        6
    freezex  
       May 4, 2021
    svc 里的这个: targetPort: http
    deploy 里没有
    root01
        7
    root01  
    OP
       May 4, 2021
    @freezex 解决了,targetPort 设置为 80 端口就可以了
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3817 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 34ms · UTC 05:05 · PVG 13:05 · LAX 22:05 · JFK 01:05
    ♥ Do have faith in what you're doing.