<p>my deployment yaml:</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
  labels: 
    app: nginx
spec:
  selector:
    matchLabels:
      app: nginx
  replicas: 3
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.7.9
        ports:
        - containerPort: 80
</code></pre>
<p>my service yaml:</p>
<pre><code>apiVersion: v1
kind: Service
metadata:
  name: nginx-service
spec:
  selector:
    app: nginx
  ports:
  - protocol: TCP
    port: 80
    targetPort: 80
</code></pre>
<p><a href="https://i.stack.imgur.com/Hp4l8.png" rel="nofollow noreferrer">enter image description here</a></p>
<p><a href="https://i.stack.imgur.com/xXIUM.png" rel="nofollow noreferrer">enter image description here</a></p>
<p>and then I <code>curl 10.104.239.140</code>, but get an error <code>curl: (7) Failed connect to 10.104.239.140:80; Connection timed out</code></p>
<p>Who can tell me what's wrong?</p>

Meddie
<p>welcome to SO. That service you've deployed is of type <code>ClusterIP</code> which means it can only be accessed from within the cluster. In your case, it seems you're trying to access it from outside the cluster and thus the <code>connection timed out</code>.</p>
<p>What you can do is, deploy a service of type <code>NodePort</code> or <code>LoadBalancer</code> to access it from outside the cluster. You can read more about different service types <a href="https://kubernetes.io/docs/concepts/services-networking/service/#publishing-services-service-types" rel="nofollow noreferrer">here</a>.</p>
<p>You're service would end up something like this:</p>
<pre><code>apiVersion: v1
kind: Service
metadata:
  name: nginx-service
spec:
  type: NodePort      ## or LoadBalancer(supported by Cloud providers like AWS)    
  selector:
    app: nginx
  ports:
  - protocol: TCP
    port: 80
    targetPort: 80
    # Optional field
    # By default and for convenience, the Kubernetes control plane will allocate a port from a range (default: 30000-32767)
    nodePort: 30001
</code></pre>
