【问题标题】:"CrashLoopBackOff" error disappeared, but new error "Connection Refuesd"“CrashLoopBackOff”错误消失,但新错误“Connection Refused”
【发布时间】:2020-02-26 09:32:33
【问题描述】:

使用命令:[ "/bin/bash", "-c", "--" ] args:[“虽然是真的;睡 30 分钟;完成;” ],我解决了“CrashLoopBackoff”错误

apiVersion: v1
kind: Pod
metadata:
  name: pod-apigw2
spec:
  selector:
      app: apigw2
  containers:
      - name: apigw2
        image: parkdongwoo/apigw_test:v1
        imagePullPolicy: Always
        ports:
                - name: port-apigw2
                  containerPort: 8080
  command: [ "/bin/bash", "-c", "--" ]
  args: [ "while true; do sleep 30; done;" ]

但是,链接服务时出现拒绝错误。

以下是我的服务 yaml。我将 NodePort 配置为接收来自外部的服务请求

apiVersion: v1
kind: Service
metadata:
  name: apigw-nodeport
spec:
  type: NodePort
  ports:
      - name: port-apigw
        port: 80      
        targetPort: 8001
  selector:
    app: apigw2 

pod的状态和svc的状态如下:

al8-1@al8-1:~/kuber_test/pod_nginx$ kubectl get pods -o wide
NAME         READY   STATUS    RESTARTS   AGE     IP             NODE    NOMINATED NODE   READINESS GATES
nginx        1/1     Running   0          6d3h    192.168.4.2    al8-2   <none>           <none>
pod-apigw2   1/1     Running   0          5m17s   192.168.4.56   al8-2   <none>           <none>

al8-1@al8-1:~/kuber_test/pod_nginx$ kubectl get svc -o wide
NAME             TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)          AGE     SELECTOR
apigw-nodeport   NodePort    10.108.177.5     <none>        80:31050/TCP     68m     app=apigw2

当我尝试curl nodePort查看是否正常打开时,出现如下错误:

al8-1@al8-1:~/kuber_test/pod_nginx$ curl 192.168.xx.xx:31050
curl: (7) Failed to connect to 192.168.xx.xx port 31050: connection refuesd

我现在不知道怎么解决。

如果有其他方法可以解决“CrashLoopBackOff”或如何解决“连接被拒绝”,请告诉我?

【问题讨论】:

  • connection refused 表示该端口上没有任何监听。您的服务未在该端口上运行,或者该端口未正确映射。运行netstat -ln | grep 31050查看服务是否真正启动并监听。
  • 搜索如下:--- tcp6 0 0 :::31050 :::* LISTEN

标签: kubernetes


【解决方案1】:

service 中的 targetPort 需要与 pod 中的 containerPort 相匹配。您将 8081 作为 targetPort,但将 8080 作为 containerPort。

如果即使在将目标端口与容器端口匹配后仍无法正常工作,则表示容器根本没有在该端口上侦听。

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-01-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-01-10
  • 2016-10-12
相关资源
最近更新 更多