收到错误“无法连接到192.168.99.100端口31539:连接被拒绝”

时间:2019-09-28 10:58:26

标签: curl kubernetes kubectl minikube

我正在使用minkube(kubenetes单节点)。我公开了一项服务,并在以下情况下运行它:

curl $(minikube ip):$NODE_PORT 

我得到说的错误:

  

卷曲:(7)无法连接到192.168.99.100端口31539:连接被拒绝

我也尝试在Docker中运行容器,一切都很好。但是在Kubernetes中,我无法运行该应用程序。

我知道网站上存在类似的问题,但据我所知,没有一个问题可以解决我的问题。

有人知道怎么了吗?还是我想念什么?

(我还必须提到我是Kubernetes的新手)

执行“ kubectl get svc -n名称空间”命令的输出:

No resources found.

yaml文件:

apiVersion: v1
kind: Service
metadata:
 creationTimestamp: "2019-10-02T15:25:18Z"
 labels:
  app: urbackup-v11
 name: urbackup-v11
 namespace: default
 resourceVersion: "195336"
 selfLink: /api/v1/namespaces/default/services/urbackup-v11
 uid: a1c18360-a2bb-4de9-a25c-b0ffd45a20b2
spec:
 clusterIP: 10.111.173.217
 externalTrafficPolicy: Cluster
 ports:
 - nodePort: 31539
   port: 8080
   protocol: TCP
   targetPort: 8080
 selector:
  app: urbackup-v11
 sessionAffinity: None
 type: NodePort
status:
 loadBalancer: {}

execute iptables-save命令的输出:

# Generated by iptables-save v1.6.1 on Sat Sep 28 22:33:21 2019
*nat
:PREROUTING ACCEPT [21:3442]
:INPUT ACCEPT [16:3200]
:OUTPUT ACCEPT [1510:295823]
:POSTROUTING ACCEPT [1510:295823]
:DOCKER - [0:0]
-A PREROUTING -m addrtype --dst-type LOCAL -j DOCKER
-A OUTPUT ! -d 127.0.0.0/8 -m addrtype --dst-type LOCAL -j DOCKER
-A POSTROUTING -s 172.17.0.0/16 ! -o docker0 -j MASQUERADE
-A DOCKER -i docker0 -j RETURN
COMMIT
# Completed on Sat Sep 28 22:33:21 2019
# Generated by iptables-save v1.6.1 on Sat Sep 28 22:33:21 2019
*filter
:INPUT ACCEPT [64079:559675075]
:FORWARD DROP [0:0]
:OUTPUT ACCEPT [65202:547155125]
:DOCKER - [0:0]
:DOCKER-ISOLATION-STAGE-1 - [0:0]
:DOCKER-ISOLATION-STAGE-2 - [0:0]
:DOCKER-USER - [0:0]
-A FORWARD -j DOCKER-USER
-A FORWARD -j DOCKER-ISOLATION-STAGE-1
-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 DOCKER-ISOLATION-STAGE-1 -i docker0 ! -o docker0 -j DOCKER- 
ISOLATION-STAGE-2
-A DOCKER-ISOLATION-STAGE-1 -j RETURN
-A DOCKER-ISOLATION-STAGE-2 -o docker0 -j DROP
-A DOCKER-ISOLATION-STAGE-2 -j RETURN
-A DOCKER-USER -j RETURN
COMMIT
# Completed on Sat Sep 28 22:33:21 2019

在这里,kubectl -n default get pods -o yaml -l app=urbackup-v11命令的结果:

apiVersion: v1
items:
- apiVersion: v1
  kind: Pod
  metadata:
   creationTimestamp: "2019-10-02T15:22:34Z"
   generateName: urbackup-v11-774ff76465-
   labels:
    app: urbackup-v11
    pod-template-hash: 774ff76465
   name: urbackup-v11-774ff76465-ch42z
   namespace: default
   ownerReferences:
   - apiVersion: apps/v1
     blockOwnerDeletion: true
     controller: true
     kind: ReplicaSet
     name: urbackup-v11-774ff76465
     uid: 6d7ba6c6-5318-4dc1-bfd7-356f85598236
    resourceVersion: "212488"
    selfLink: /api/v1/namespaces/default/pods/urbackup-v11-774ff76465-ch42z
    uid: 22674f75-4507-4405-81d9-d1bb29b5a70b
  spec:
   containers:
   - image: uroni/urbackup-server
     imagePullPolicy: Always
     name: urbackup-server
     resources: {}
     terminationMessagePath: /dev/termination-log
     terminationMessagePolicy: File
     volumeMounts:
     - mountPath: /var/run/secrets/kubernetes.io/serviceaccount
       name: default-token-rggcc
       readOnly: true
    dnsPolicy: ClusterFirst
    enableServiceLinks: true
    nodeName: minikube
    priority: 0
    restartPolicy: Always
    schedulerName: default-scheduler
    securityContext: {}
    serviceAccount: default
    serviceAccountName: default
    terminationGracePeriodSeconds: 30
    tolerations:
    - effect: NoExecute
      key: node.kubernetes.io/not-ready
      operator: Exists
      tolerationSeconds: 300
    - effect: NoExecute
      key: node.kubernetes.io/unreachable
      operator: Exists
      tolerationSeconds: 300
    volumes:
    - name: default-token-rggcc
      secret:
       defaultMode: 420
        secretName: default-token-rggcc
   status:
    conditions:
    - lastProbeTime: null
      lastTransitionTime: "2019-10-02T15:22:34Z"
      status: "True"
      type: Initialized
    - lastProbeTime: null
      lastTransitionTime: "2019-10-05T09:44:00Z"
      message: 'containers with unready status: [urbackup-server]'
      reason: ContainersNotReady
      status: "False"
      type: Ready
    - lastProbeTime: null
      lastTransitionTime: "2019-10-05T09:44:00Z"
      message: 'containers with unready status: [urbackup-server]'
      reason: ContainersNotReady
      status: "False"
      type: ContainersReady
    - lastProbeTime: null
      lastTransitionTime: "2019-10-02T15:22:34Z"
      status: "True"
      type: PodScheduled
     containerStatuses:
     - containerID: docker://ba3170190d5315e9edaa5e2674d5cd38bff6c8fd5c8025537a7c0ece77a695c7
       image: uroni/urbackup-server:latest
       imageID: docker-pullable://uroni/urbackup-server@sha256:ed18b99ac85147e01dceb2dc45844c5689fb19bbe4c915d7e5b52b6a376db242
       lastState: {}
       name: urbackup-server
       ready: false
       restartCount: 1
       state:
       terminated:
        containerID: docker://ba3170190d5315e9edaa5e2674d5cd38bff6c8fd5c8025537a7c0ece77a695c7
        exitCode: 255
        finishedAt: "2019-10-05T09:43:09Z"
        reason: Error
        startedAt: "2019-10-04T12:11:01Z"
      hostIP: 10.0.2.15
      phase: Running
      qosClass: BestEffort
      startTime: "2019-10-02T15:22:34Z"
kind: List
metadata:
 resourceVersion: ""
 selfLink: ""

1 个答案:

答案 0 :(得分:0)

您的Pod spec.containers中缺少ports配置。

您需要添加它,并确保它与您的服务targetPort相匹配(请参阅:Exposing pods to the cluster)。

应该是这样的:

  spec:
   containers:
   - image: uroni/urbackup-server
     imagePullPolicy: Always
     ports:
     - containerPort: 8080
     name: urbackup-server
     resources: {}
     terminationMessagePath: /dev/termination-log
     terminationMessagePolicy: File
     volumeMounts:
     - mountPath: /var/run/secrets/kubernetes.io/serviceaccount
       name: default-token-rggcc
       readOnly: true