Kubernetes端口转发-拒绝连接

问题描述 投票:11回答:1

转发端口时出现以下错误。谁能帮忙?

mjafary$ sudo kubectl port-forward sa-frontend 88:82

Forwarding from 127.0.0.1:88 -> 82
Forwarding from [::1]:88 -> 82

错误日志:

Handling connection for 88
Handling connection for 88
E1214 01:25:48.704335   51463 portforward.go:331] an error occurred forwarding 88 -> 82: error forwarding port 82 to pod a017a46573bbc065902b600f0767d3b366c5dcfe6782c3c31d2652b4c2b76941, uid : exit status 1: 2018/12/14 08:25:48 socat[19382] E connect(5, AF=2 127.0.0.1:82, 16): Connection refused

这里是吊舱的描述。我的期望是,当我在浏览器中命中localhost:88时,请求应转发到jafary / sentiment-analysis-frontend容器,并且应加载应用程序页面

mjafary$ kubectl describe pods sa-frontend

Name:         sa-frontend
Namespace:    default
Node:         minikube/192.168.64.2
Start Time:   Fri, 14 Dec 2018 00:51:28 -0700
Labels:       app=sa-frontend
Annotations:  <none>
Status:       Running
IP:           172.17.0.23
Containers:
  sa-frontend:
    Container ID: docker://a87e614545e617be104061e88493b337d71d07109b0244b2b40002b2f5230967
    Image:          jafary/sentiment-analysis-frontend
    Image ID:       docker-pullable://jafary/sentiment-analysis-frontend@sha256:5ac784b51eb5507e88d8e2c11e5e064060871464e2c6d467c5b61692577aeeb1
    Port:           82/TCP
    Host Port:      0/TCP
    State:          Running
      Started:      Fri, 14 Dec 2018 00:51:30 -0700
    Ready:          True
    Restart Count:  0
    Environment:    <none>
    Mounts:
  /var/run/secrets/kubernetes.io/serviceaccount from default-token-mc5cn (ro)
Conditions:
  Type           Status
  Initialized    True 
  Ready          True 
  PodScheduled   True 
Volumes:
  default-token-mc5cn:
    Type:        Secret (a volume populated by a Secret)
    SecretName:  default-token-mc5cn
    Optional:    false
QoS Class:       BestEffort
Node-Selectors:  <none>
Tolerations:     node.kubernetes.io/not-ready:NoExecute for 300s
             node.kubernetes.io/unreachable:NoExecute for 300s
Events:          <none>
kubernetes portforwarding kubectl
1个回答
0
投票

拒绝连接的原因是,没有进程在端口82上进行监听。用于创建nginx映像的dockerfile公开了端口80,在您的pod规范中,您还公开了端口82。但是,nginx配置为监听在端口80上。

这意味着您的Pod有两个公开的端口:80和82。但是,nginx应用程序正在主动侦听端口80,因此仅对端口80的请求有效。

要使用端口82进行设置,您需要更改nginx配置文件,以便它监听端口82而不是端口80。您可以通过使用镜像中内置的更改创建自己的Docker镜像来执行此操作,或者您可以使用configMap将默认的配置文件替换为所需的设置]

© www.soinside.com 2019 - 2024. All rights reserved.