0

我使用 OS Centos 7。我的 Pod:

apiVersion: v1
kind: Pod
metadata:
  name: tomcat
spec:
  containers:
  - image: ec2-73-99-254-8.eu-central-1.compute.amazonaws.com:5000/tom
    name: tomcat
    command: ["sh","-c","/opt/tomcat/bin/deploy-and-run.sh"]
    volumeMounts:
    - mountPath: /maven
      name: app-volume
    ports:
    - containerPort: 8080
  volumes:
  - name: app-volume
    hostPath:
      path: /maven

我的服务:

apiVersion: v1
kind: Service
metadata:
  name: tomcat
spec:
  ports:
    - name: http
      port: 80
      targetPort: 8080
      protocol: TCP
  selector:
    name: tomcat

服务看起来像:

# kubectl get svc
NAME         CLUSTER_IP      EXTERNAL_IP   PORT(S)   SELECTOR      AGE
kubernetes   10.254.0.1      <none>        443/TCP   <none>        14h
tomcat       10.254.206.26   <none>        80/TCP    name=tomcat   13h

和豆荚:

# kubectl get pod
NAME      READY     STATUS    RESTARTS   AGE
tomcat    1/1       Running   0          13h

当我运行 Curl 时:

curl 10.254.206.26
curl: (56) Recv failure: Connection reset by peer

当时的 Kube-proxy 日志显示如下:

kube-proxy[22273]: Couldn't find an endpoint for default/tomcat:http: missing service entry
kube-proxy[22273]: Failed to connect to balancer: missing service entry

但是当我直接运行 curl 到 pod ip 地址和端口 8080 - 它工作正常。当我运行命令时 kubectl get endpoints

NAME         ENDPOINTS             AGE
kubernetes   195.234.109.11:6443   14h
tomcat       <none>                14h

此输出中带有“none”的字段 ENDPOINTS 看起来很奇怪。怎么了?

4

1 回答 1

0

服务通过匹配标签来工作。您正在尝试根据 pod 的名称进行匹配。尝试将您的 pod 的元数据更改为

metadata:
  name: tomcat
  labels:
    name: tomcat

看看是否有帮助。

于 2016-03-20T07:44:49.210 回答